Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT availability messages sent before MQTT connection at startup are lost #3625

Closed
crowbarz opened this issue May 28, 2020 · 2 comments
Closed

Comments

@crowbarz
Copy link
Contributor

Bug Report

What happened

After restarting zigbee2mqtt, some of my devices occasionally show as unavailable on Home Assistant. However, they are still sending Zigbee reports which are then also sent via MQTT, and they can still be controlled via zigbee2mqtt by sending commands via MQTT. It is a different set of devices every restart.

What did you expect to happen

These devices seem to be online to zigbee2mqtt, but is not considered online by Home Assistant due to the zigbee2mqtt/DEVICE/availability MQTT message being lost. This has been confirmed by sniffing MQTT traffic with MQTT Explorer.

How to reproduce it (minimal and precise)

Analysis of the logs identified that the MQTT availability messages for the affected devices were attempted to be sent before MQTT was connected. (see lines in the abridged log below marked >>, in this instance the online MQTT message is dropped Kitchen Floor Right and not resent after MQTT is connected, but the online message is sent for Kitchen Floor Left and all other devices).

2020-05-28 00:11:46: Starting zigbee2mqtt versio
n 1.13.1 (commit #3046680)
...
2020-05-28 00:11:48: Setup reporting for '0x0017880100dbd6aa' - 11 - genOnOff
2020-05-28 00:11:48: Setup reporting for '0x0017880100dfff5a' - 11 - genOnOff
>>2020-05-28 00:11:56: Received Zigbee message from 'Kitchen Floor Right', type 'attributeReport', cluster 'genLevelCtrl', data '{"currentLevel":32}' from endpoint 1 with groupID 0
>>2020-05-28 00:11:56: Not connected to MQTT server!
>>2020-05-28 00:11:56: Cannot send message: topic: 'zigbee/Kitchen Floor Right/availability', payload: 'online
...
2020-05-28 00:12:11: Connecting to MQTT server at mqtts://mqtt.xxx:8883
2020-05-28 00:12:11: Connected to MQTT server
...
2020-05-28 00:12:12: MQTT publish: topic 'zigbee/Hallway Ground/availability', payload 'online'
2020-05-28 00:12:12: MQTT publish: topic 'zigbee/Kitchen Floor Left/availability', payload 'online'

The availability messages (as well as resulting reporting messages) appear to be triggered by a Zigbee message being received by the controller before MQTT is connected. The logs show that availability messages for all devices are normally sent after MQTT is connected. When that happens, any devices for which availability messages have already been sent (but dropped because MQTT is not connected) are skipped, so they remain offline.

Suggested possible solutions to this issue:

  1. cache the MQTT messages that are sent prior to MQTT connection (and whilst MQTT is otherwise disconnected), and resend them after (re-)connection, and/or:
  2. resend availability for the device along with all other devices after MQTT is connected. The code seems to me to try to do this already, but the logs don't show that they are being sent.

Debug Info

Zigbee2mqtt version: 1.13.1
Adapter hardware: CC2531
Adapter firmware version: 20190619

@Koenkk
Copy link
Owner

Koenkk commented May 28, 2020

Should be fixed in latest dev branch (edge for hassio). Could you confirm this?

@crowbarz
Copy link
Contributor Author

Looks good now - thanks for fixing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants