…in data/configuration.yaml for zigbee2mqtt. That will make sure all data pushed to MQTT from Zigbee2mqtt is retained. So when HA / Z2mAssistant / whatever restarts, all messages are still there.
Hi All. I’m running docker with HA Core and Mosquitto on an isolated server with a remote system (Pi) running Zigbee2MQTT and continue to have this problem only after I restart the HA core/ Mosquitto server, full Linux reboot. After HA Core and Mosquitto containers start, all zigbee devices continue to report “Unavailable”.
Happens every time I do this, what is the fix for this?
Rebooting Z2M server helps “waking up” the devices in HA, but all devices are losing their state.
For example, all my buttons or switches have to be pressed once to become active and on the following presses, they are actualy doing what they are supposed to do.
Looks like :
1/ Restarting Z2M makes them “visible” to HA, but without any exploitable state (from “unavailable” > “unknown”)
2/ Pressing or manualy changing their state in Z2M updates their state in HA (from “unknown” > “WhateverTheirState”)
3/ And only then everything’s working properly.
I am the only one ?
Rebooting Z2M only help in step 1… do you have a solution to avoid step 2 ?
It’s strange. Although HA sets all entities to unavailable after restart, it should re-read current zigbee devices states from mqtt (mqtt is the data source for HA in this case).
Those mqtt topics must be howeverh set to retained. Otherwise the refresh of an entity happens with the first upcoming data change
I’m a new user of Zigbee2MQTT, and had an interest in this topic. I too expected zigbee2mqtt’s device topic/state to be retained at the MQTT broker. I currently only have one lightbulb (named “My Light”) as a device so I did a few experiments.
First I can confirm, as others have mentioned, that the MQTT topic for the device’s state is Not retained.
Next, I restarted HA and checked the logs of Zigbee2MQTT to see what was going on.
debug 2023-02-27 16:48:26: Received MQTT message on 'homeassistant/status' with data 'offline'
debug 2023-02-27 16:49:03: Received MQTT message on 'homeassistant/status' with data 'online'
info 2023-02-27 16:49:33: MQTT publish: topic 'zigbee2mqtt/My Light', payload '{"last_seen":"2023-02-24T18:22:43-05:00","linkquality":255,"power_on_behavior":null,"state":"OFF", "update":{"installed_version":16786688,"latest_version":16786688,"state":"idle"},"update_available":null}'
HA’s MQTT Birth/Last-Will-Testament uses the topic homeassistant/status and when HA goes down, the Broker will send this topic with a status of “off-line” and when HA starts back up the status changes to online.
So from the logs, Zigbee2MQTT sees HA’s status go “on-line”, and 30 seconds later it sends an update of the device’s state using the device’s topic (zigbee2mqtt/My Light) and message containing its current state ("state":"OFF").