I installed the Mosquitto broker (6.0.1) add-on on my Home Assistant (2022.3.3, OS 5.10.92-v8). Publish and subscribe of messages is working perfectly.
However, when configuring the Last Will & Testament (LWT) of an external MQTT client, the message is not published, when the MQTT client disconnects. This is how I test the LWT:
“Listening instance” (running on the Raspberry where HA is installed):
mosquitto_sub -h 192.168.1.123 -p 8883 --cafile CA.pem --cert client1.pem --key client1.key -t "test/#"
“Instance to test LWT” (running on the Raspberry where HA is installed):
mosquitto_sub -h 192.168.1.123 -p 8883 --cafile CA.pem --cert client2.pem --key client2.key -t "test/#" --will-topic "test/lwt" --will-payload "disconnected"
Using netstat -lna
I cann see both clients connected:
tcp 0 0 172.30.33.1:54618 192.168.1.123:8883 ESTABLISHED
tcp 0 0 172.30.33.1:54868 192.168.1.123:8883 ESTABLISHED
Now, when I terminate the “Instance to test LWT” I would expect seeing the LWT message on the “Listening client”. But no message appears. The client is really disconnected when looking at netstat
again.
What am I missing in the MQTT configuration?