MQTT Autodiscovery and last will for multiple topics

Hi,

I have a device with multiple entities using MQTT autodiscovery

image

The topics are:

BELL_VOLUME_PREFIX = f"homeassistant/number/bell-client-1/volume"
BELL_SWITCH_PREFIX = f"homeassistant/switch/bell-client-1"
BELL_SOUND_PREFIX = f"homeassistant/number/bell-client-1/sound"

These topics are configured for a single MQTT client. However, I can only set one last will per client,
where actually I wan’t to set the availability for each entity to ‘offline’. Thus, if I do this:

self.client_inst.will_set(topic=f"{BELL_VOLUME_PREFIX}/status", payload="offline", qos=0, retain=False)
self.client_inst.will_set(topic=f"{BELL_SWITCH_PREFIX}/status", payload="offline", qos=0, retain=False)
self.client_inst.will_set(topic=f"{BELL_SOUND_PREFIX}/status", payload="offline", qos=0, retain=False)

it will only set the ‘bell sound’ status to offline after unexpected disconnection. Does anybody maybe know a nice way to achieve what I want?

I’d use just one availability topic per device, e.g. bell-client-1/availability. You can specify it as availability_topic for all of its entities.
Only MQTT discovery messages should go to topics under homeassistant/, the actual state and availability topics should be somewhere else.

1 Like

Thanks, that seems to make sense. I will give it try.
With respect to the second part, I followed the documentation. Example:

image

It’s from the URL you included. Is this not considered good practice anymore?

Oh, sorry for that. I subscribed to my own homeassistant/# with mosquitto_sub and saw that programs like mqtt-io and zigbee2mqtt do it as I described. However, now that I read the docs more carefully, I see that both ways are possible.