What is birth_message and will_message in MQTT and what are they use for?

I notice the introduction of birth_message and will_message in MQTT for HA version 0.33. May I know what are they and how are they use for?

Birth = service started
Will = last message before service ends

1 Like

The Last Will and Testament feature is used in MQTT to notify other clients about an ungracefully disconnected client.
Birth feature is the opposite and is used to notify when a client connects.

1 Like

thanks guys. so how you actually make use of these messages in HA? or is it only use by external service to monitor the status of HA?

My impression from reading he PR was that this was to internally support predefined publishers to detect an abnormal condition like a disconnect, though I could be wrong on this.

so it can be used for make a notification when a client disconnect from the mqtt service?

Sorry for reviving the dead post, but I think it’s much related to my current issue :
I have an existing MQTT sensor that has retain:true on its status message, birth/will message are turned off
Now, I’ve just configured the birth/will support as per the documentation on this subject

If I use ESPHomeLib for this sensor, should I configure the same on the sensor itself ?
How does HASS know to distinguish between different sensors’ birth/will messages if they’re being sent on the same topic ?

Thanks in advance

Each MQTT client has its own topics for birth and last will.

The documentation shows the birth and last will topics belonging to Home Assistant. In other words, some other MQTT device can subscribe to hass/status. If Home Assistant ungracefully disconnects from the MQTT broker, the broker (on behalf of the departed Home Assistant) informs all subscribers to hass/status with the message offline. Now that they have been apprised of Home Assistance’s status, they can proceed to adjust to the new conditions.

So I’m at the same spot, what do I need to to avoid the wrong state reporting in HASS then ?

My reply was in response to this question:

The following is a different question:

Can you provide more information about what you mean by “wrong state”?

I have a mqtt sensor which is not connected.
Even though it’s offline, hass reports its state as available.
I’ve connected to the MQTT broker to check whether there are retained status messages and found out there are

Now my question would be what’s the best way to go around this issue and make the MQTT sensor status reliable

Publish an empty-string to the topic, with retain=true, and the MQTT broker will delete the topic and its message.

@gpbenton showed an easy way to do that in this post:

1 Like

Thank you, I ended up removing persistence in mosquitto which seems to have a good effect on the system, I’ll update in a couple of days