zigbee2mqtt/bridge/state 'offline' after Mosquitto MQTT broker restart

Created on 2 Nov 2020  路  14Comments  路  Source: Koenkk/zigbee2mqtt

What happened

I recently noticed _all_ of my zigbee2mqtt devices became unavailable in Home Assistant, and traced the trigger back to a Mosquitto MQTT broker restart.

Restarting HA did not fix the problem, but restarting zigbee2mqtt _did_ resolve the issue. On further investigation, I found that after restarting the broker zigbee2mqtt/bridge/state remains offline.

Looking through the logs I can see that zigbee2mqtt reconnects, as you would expect, but state is not updated on reconnect:

Zigbee2MQTT:error 2020-11-02 18:28:30: Not connected to MQTT server!
Zigbee2MQTT:info  2020-11-02 18:28:35: Connected to MQTT server

zigbee2mqtt itself is working, I can control devices via the zigbee2mqtt web GUI/ MQTT commands, just Home Assistant thinks all of the zigbee2mqtt devices are offline due to zigbee2mqtt/bridge/state being offline

What did you expect to happen

zigbee2mqtt should (imo!) reconnect when the MQTT broker is available and publish an zigbee2mqtt/bridge/state online message.

On startup/ initial connect I can see that zigbee2mqtt does publish to zigbee2mqtt/bridge/state:

Zigbee2MQTT:info  2020-11-02 20:02:42: Connecting to MQTT server at mqtt://hostname:1883
Zigbee2MQTT:debug 2020-11-02 20:02:42: Using MQTT keepalive: 30
Zigbee2MQTT:info  2020-11-02 20:02:42: Connected to MQTT server
Zigbee2MQTT:info  2020-11-02 20:02:42: MQTT publish: topic 'zigbee2mqtt/bridge/state', payload 'online'

However there is no such message publishing on a reconnect.

How to reproduce it (minimal and precise)

Restart Mosquitto MQTT broker _without_ restarting zigbee2mqtt.

Cleaned config (removed device-specific/ network key) - note that MQTT version 5 in use for device-specific retention - hopefully I haven't missed anything obvious in my configuration, apologies if I have 馃

mqtt:
  base_topic: zigbee2mqtt
  server: 'mqtt://hostname:1883'
  user: <username>
  password: <password>
  keepalive: 30
  version: 5
serial:
  port: /dev/ttyUSB0
frontend:
  port: 8081
experimental:
  new_api: true
advanced:
  log_level: debug
  homeassistant_discovery_topic: 'homeassistant'
  homeassistant_status_topic: 'homeassistant/status'
  rtscts: false
  report: true
  last_seen: ISO_8601

Debug info

Zigbee2MQTT version: 1.16.0 (I have also tested/ replicated this issue with 1.15.0, both containerised)
Adapter hardware: zzh! / CC26X2R1
Adapter firmware version: CC26X2R1_20201017.hex (from dev branch)
Mosquitto MQTT broker version: 1.6.12

problem

Most helpful comment

Should be fixed now.

Changes will be available in the latest dev branch in a few hours (https://www.zigbee2mqtt.io/how_tos/how-to-switch-to-dev-branch.html)

All 14 comments

It's the same for me. Can't connect to MQTT anymore. Reverted back to 1.15

I'm able to connect to my MQTT broker with zigbee2mqtt 1.16, this issue just relates to zigbee2mqtt/bridge/state not being updated to 'online' after a reconnect event (which also affects 1.15 from my testing).

Full snapshot recovery in my case

I had the same problem, but it was fixed after I set username/password in configuration.yaml

Experiencing the same issue when having the new_api: true in place
When removing that the zigbee2mqtt service is starting up fine without any issues

Experiencing the same issue when having the new_api: true in place
When removing that the zigbee2mqtt service is starting up fine without any issues

Want to be sure we're talking about the same issue here.

Since upgrade to 1.16 (and with version 1.15) I have _always_ been able to start zigbee2mqtt / connect to MQTT broker, with username and password. My issue is that if I restart the MQTT broker the zigbee2mqtt bridge status remains 'offline' in the retained messages on the broker despite zigbee2mqtt reconnecting to the broker, this is 'resolved' by restarting zigbee2mqtt.

I also had the issue of not being able to connect to MQTT after updating to 1.16. I added my MQTT user's password to the config (username was already set) which fixed it. Thanks @zfrank2601 !

Experiencing the same issue when having the new_api: true in place
When removing that the zigbee2mqtt service is starting up fine without any issues

Want to be sure we're talking about the same issue here.

Since upgrade to 1.16 (and with version 1.15) I have _always_ been able to start zigbee2mqtt / connect to MQTT broker, with username and password. My issue is that if I restart the MQTT broker the zigbee2mqtt bridge status remains 'offline' in the retained messages on the broker despite zigbee2mqtt reconnecting to the broker, this is 'resolved' by restarting zigbee2mqtt.

Alright, then we got different issues. Please ignore my comment

More or less same issue for me. If zigbee2mqtt lose its connection to MQTT server zigbee2mqtt/bridge/state becomes "offline" (probably the "will message"). When zigbe2mqtt reconnects the will message is not updated.

It's possible to set zigbee2mqtt/bridge/state to "online" manually (I use MQTT.fx to do this), and all devices becomes available in HA again.

I have the same problems as he described by @coldfire84 in this issue.

Have the same issue, happens by itself:

Zigbee2MQTT:info  2020-11-07 05:12:32: MQTT publish: topic 'zigbee2mqtt/computer_damiano', payload '{"linkquality":102,"power":9,"state":"ON"}'
Zigbee2MQTT:error 2020-11-07 05:12:38: Not connected to MQTT server!
Zigbee2MQTT:error 2020-11-07 05:12:38: Cannot send message: topic: 'zigbee2mqtt/computer_damiano', payload: '{"linkquality":102,"power":7,"state":"ON"}
Zigbee2MQTT:error 2020-11-07 05:12:42: Not connected to MQTT server!
Zigbee2MQTT:info  2020-11-07 05:12:43: Connected to MQTT server
Zigbee2MQTT:info  2020-11-07 05:12:44: MQTT publish: topic 'zigbee2mqtt/Wattmetro_Casa', payload '{"linkquality":87,"power":92,"power_alarm_active":false,"power_alarm_active_value":0,"power_alarm_enabled":0,"power_alarm_wh_threshold":0}'

At the same time, the Mosquitto HA addon shows this:

1604722245: Client mqttjs_67a4784b has exceeded timeout, disconnecting.
1604722353: New connection from 172.30.33.2 on port 1883.
[INFO] found mosqui on Home Assistant
1604722363: New client connected from 172.30.33.2 as mqttjs_67a4784b (p2, c1, k60, u'mosqui').
1604722418: Saving in-memory database to /data/mosquitto.db.

1604722245 converts to 05:10:45 CET. At 5:10:47, "sensor.bridge_state" turned to "offline" in the HA logbook

Connecting to the MQTT server showed zigbee2mqtt/bridge/state as offline, but the topics for the various devices were still being updated. I manually changed the topic to online and everything started working again.

Same problem here.
zigbee2mqtt bridge state goes offline and never comes back even when zigbee2mqtt and the broker (mosquitto) are working fine.
I've had user/pass in my config since the beginning of the setup so this is not a solution for me...

Should be fixed now.

Changes will be available in the latest dev branch in a few hours (https://www.zigbee2mqtt.io/how_tos/how-to-switch-to-dev-branch.html)

Dear @Koenkk

They are on the updated dev branch last Sunday after their fix goes live. However, today the problem has reappeared. When I restart the Home Assistant, the entities are unavailable, to resolve, I need to stop zigbee2mqtt and start again. I'm using the Bare-Metal installation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pepp86 picture pepp86  路  4Comments

andreasbrett picture andreasbrett  路  3Comments

jeroenterheerdt picture jeroenterheerdt  路  3Comments

z4rn0x picture z4rn0x  路  3Comments

sylarevan picture sylarevan  路  5Comments