MQTT devices unavailable after MQTT integration restart

As described in the title. If I restart / reload the MQTT integration or restart the whole Home Assistant, all devices / entities that are integrated via MQTT are not available in HA.

I come from a HA Docker container version back to HAOS. If I have observed it correctly, the problem only occurs since switching to HAOS.

I use Mosquitto as MQTT broker in a docker container.

The solutions in this older post marked as solved are no longer valid or do not work.

https://community.home-assistant.io/t/zigbee2mqtt-device-unavailable-after-ha-restart/166413

mqtt:
  discovery: true
  broker: 192.168.x.x
  birth_message:
    topic: 'hass/status'
    payload: 'online'
  will_message:
    topic: 'hass/status'
    payload: 'offline'

bitrh_meaasge is no longer allowed in configuration.yaml

Sending

action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - service: mqtt.publish
    data:
      topic: hass/status
      payload: online

do not solve the issue.

Can someone point me to the actual solution of this problem?

Settings → Devices & Services → MQTT → Configure → Reconfigure MQTT → second page

afbeelding

@francisp Thanks for showing me this options in the integration.

It seems that this solves a part of the problem.

All entities of the HUE bulbs and contact sensors (except all update.domain entities) are now back after HA reboot.

But the curtain motors and the vaccum robot with valetudo stays unavailable.

Any additional idea?

I have tested around a bit these days and installed the MQTT explorer add-on to understand a bit more of MQTT.

I also moved from my Docker MQTT-Broker to the HA add-on Broker.

After the last HA restarts all the Z2M and frigate devices/entities are coming back. Only the Valetudo robot not or with some delay. I will make some more research to this.

Any solution to this? After rebooting HA, MQTT devices are unavailable, and the only way to bring them back seems to be rebooting the devices reporting to my mqtt broker, which is mosquitto in my case. Then when they do come back, everything is listed as “unknown” until their state changes, which means I have to re-trigger everything again for things to go back to knowing what state they’re in.

It really sucks.

That is normal behavior
The devices needing to be reboot to reconnect, not
I assume you are using the add-on?

Some devices reporting to mqtt have ability to republish their state on demand. for example Shelly devices can be triggered by announce message.

you can publish such request on ha start or on demand or other events

Other option is to setup these devices to publish retained messages. Not all have this option. For example Shelly gen1 have, while newer ones don’t

It turns out, the DB for mosquitto wasn’t being written, despite being in the config. I don’t know what change I made but it started writing the DB and things will preserve state between mosquitto server reboots now.

I also can’t seem to get it in the state where I need to reboot the endpoint device anymore, so perhaps it was that config issue, whatever it was, that was causing the mosquitto db not to be created that caused it all?