Zigbee2Mqtt device unavailable after HA restart

I had this problem and my solution is to re-force publish the MQTT birth message after which Z2M re-populate device statuses -

Adjust the delay as necessary depending on the time it takes your system to properly load :slight_smile:

EDIT - just re-read your comments and you tried this :frowning:

automation:
# Force Publish HA Birth Message
  - id: zigbee_publish_birth_message
    alias: Zigbee Publish MQTT Birth Message
    trigger:
      platform: homeassistant
      event: start
    action:
      - delay: '10'
      - service: mqtt.publish
        data:
          topic: 'hass/status'
          payload: 'online'
1 Like

Issue with zigbee2mqtt after Mqtt-server restart:

Try publish “online” to zigbee2mqtt/bridge/state

Fix incoming:

Le me describe my case.

After a power outage 80% of Z2M devices were unavailable in HA.
I checked zigbee2mqtt/bridge/state and it was online.

I run koenkk/zigbee2mqtt:1.14.1 in Docker using docker-compose. After restarting the service all devices just back online fine.

Set:

device_options:
  retain: true

…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.

1 Like

Upgrade to Zigbee2Mqtt version 1.16.2 fixed this.

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?

1 Like

Anyone find the final fix for this?

My only way to fix it was to restart zigbee2mqtt when HA restart. Never had an issue since then:

5 Likes

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 ?

1 Like

Is the broker IP the same as the HA IP?

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").

1 Like

Hey guys.

I have the same issue, but just with some entities (all 7x Ikea fyrturs). All other devices come online.

Is there a retain flag in Z2M which I missed maybe on the Ikea’s?

Thx

@jimbojd72 after a year. Did you ever faced the issue again with the restart automation. Or is it gone?
Thinking of also add this automation.

thx