MQTT Switch And availability topic. What is its purpose?

Tags: #<Tag:0x00007f739efc8500> #<Tag:0x00007f739efc8348>

Hi there,

I am very noob with home assistant but I managed to flash a sonoff mini switch with Tasmota and connect it to HA through mqtt finally. It was a while experience but a very fun path! Besides that, I have a couple of architecture doubts.

What is the purpose of availability_topic in the switch configuration? I mean, I see using mqtt explorer how the device sends its status online through the LWT topic but, honestly, a don’t find the utility because how the device could send offline status when is being offline? Or how managed home assistant the availability status? Pinging the device or expecting updates each X seg? Or what is the purpose of this topic?

The second question is: how can I monitor the device availability status in HA? I’d like to have a card or something with all availability status of my switches (to see quickly if any is offline) and, also, notify me when any of them is offline (to replace batteries or whatever). Is it possible? Because I just have a switch entity which state is just on or off (based on the relay status) but without more properties.

I hope you can bring me some light here :slight_smile:

Thanks in advance and happy automation!

It’s the MQTT broker’s responsibility to manage Last Will and Testament (LWT).

  • When your Sonoff Mini Switch connects to the MQTT Broker, it supplies it with its LWT.
  • If the Sonoff Mini Switch fails and disconnects abruptly from the broker, its the broker’s responsibility to manage the Mini Switch’s LWT.
  • The broker will announce that the Mini Switch is now unavailable (“offline”).

Think of the broker as the “executor of the Mini Switch’s estate”. When the switch dies, the executor takes care of the switch’s “last wishes”.

1 Like

@123, thank you so much for the explanation!

I think I understand it correctly. In fact, I saw a unavailable disconnected device in my dashboard for first time after rebooting HA.
Now, my problem is that the mqtt broker updates the LWT status of the disconnected items correctly but the state is not being updated on HA correctly. I will investigate that, probably some misconfiguration or any retained messages.

Thanks for your help!

1 Like