MQTT device availability | not getting "unavailable” when offline
I want to know when my extern OpenWrt Router (connected over VPN) is not available anymore:
I thought the easiest method would be an MQTT device with LWT (last will testament):
[this good topic] (How do I set MQTT device to "unavailable state" when it has gone offline? - #2 by tom_l)
I have tested it with an Ubuntu LXC container (instead with OpenWrt) with mosquitoo:
mosquitto_pub -r -h 10.xxx -i "Workshop" -u "…" -P "…" -p 1883 -t 'homeassistant/sensor/workshop/config' -m '{"name":"WorkshopAlive","unique_id":"workshop_alive","ent_cat":"diagnostic","stat_t":"workshop/alive","avty_t":"workshop/state","device":{"identifiers":["workshop"….}}
So I can change the availability state by sending the second command “online” / “offline” and everything works fine
mosquitto_pub -h 10.xxx -i "Workshop" -u "…" -P "…" -p 1883 -m 'online' -t 'workshop/state' -q 2 -k 20 --will-payload 'offline' --will-qos 2 --will-retain --will-topic 'workshop/state'
But usually when the broker does not receive an answer after 20 sec (I have set in HA mosquitto broker settings or at least 60 sec) it should send the LWT to the will-topic and HA should set “unavailable”.
→ Unfortunately this does not work, even when I shutdown the lxc container completely and not running for couple of hours!
(By the way, that works with my esp32 flashed with my own coding not ESPHOME.)