Discovered MQTT entities not available after restart HA

I use MQTT to integrate some devices with HA:

All devices and entities are correctly discovered by HA.
However, whenever HA is restarted, all MQTT entities are unavailable and I have to trigger sending of the HA Discovery config on all devices to get it working again. As I’m integrating more devices with HA via MQTT, this because more and more a burden.

Is this expected behaviour of HA?
Does HA not cache the configuration of those MQTT entities?
Why is HA not able to reconnect those entities? The device keep sending data so that should not be the problem.

Before I was also loosing the the data whenever HA thought the entity was not available, so now I have a Telegram instance running forwarding MQTT data to an Influx instance.
But since I experiment a lot, and therefore restart often, I really would like this issue to be solved.

Does HA announce itself as ‘offline’ before restarting, and ‘online’ when back online?
Otherwise I could add some logic to the devices to monitor HA and re-announce the config when HA is back online.
But I consider this a workaround since HA should in my opinion properly continue the MQTT entities after restart.

Cheers,
Joost

That is exactly what will happen when the payload, published to the Discovery topic, is not published as a retained message.

It’s the normal behavior of MQTT. When you publish a payload to a topic, all the clients connected to the broker and subscribed to that topic will receive the payload. The payload is not normally stored on the broker so any client that connects afterwards, and subscribes to the topic, receives nothing.

Home Assistant is an MQTT client and that’s why, after a restart, it receives nothing from topics that begin with “homeassistant” because their payloads (the device configurations you published previously) are no longer on the broker.

In contrast, if you publish the payload as a retained message, it instructs the broker to store it. Any client that connects and subscribes afterwards will receive the stored payload (i.e “retained message”).

All devices that claim to support Home Assistant’s MQTT Discovery, should publish their discovery payloads as retained messages. If they don’t then you get the behavior you have observed.

Thanks. I thought they publish everything as retained message, but I will check to be sure.