Thanks a lot, this helped my out and is much more elegant!
I am just facing one more “issue”. I added the “Availability Topic”, but if my mqtt client (in my case an esp32) turns off without notification there is no change in the status of my thing in openhab. Is there a way to define a timeout when a thing is considered to be offline?
What is your device? What code or program are you running on it? Whatever it is needs to make sure that it correctly sets up the Last Will and Testament (LWT) topics and messages with the MQTT broker.
Currently I am programming an “ESP32 Dev Kit C V4 NodeMCU” by myself and I did not look into Last Will and Testament topic yet.
Would this still be send before power off?
Or is the last will stored in the MQTT Broker and the broker handles the timeout?
I am new to MQTT and this is my first project so not all things are fully clear to me yet.
Yep, this one. When your device connects it will setup the LWT topic, and also tell your broker what to publish when your broker can no longer see your device.