Update the MQTT Last Will and Testament?

Hello there Community,


An algorithm calculates a TTL (time to live), I need to make sure the message gets delivered to the client (MQTT QoS 2) and I need to make sure that the calculated TTL is the Last Will and Testament (LWT).

Something like this, algorithm calculates 6 Minutes, get written to the LWT.
Does it work like this? Is the LWT just like a topic where I could subscribe or publish to?
I read up on this on hivemq, some forums and some discussions but could not find a satisfying final answer.
Maybe you guys can help me :slight_smile:

note: the algorithm is written in python3.7 and I used the paho-mqtt package.

Thanks ahead for any creative input :heart:

The LWT topic is just a topic like any other.

When a client connects to a broker, the client can (this is optional) configure a LWT topic and message. If the client fails to respond to a heart beat message from the broker for too long of a time the broker will publish the configed message to the LWT topic.

Given this is how the LWT is supposed to be used, I don’t understand why you would publish this TTL to the LWT topic. Why not a TTL topic? The LWT topic is intended to represent whether or not a client is connected to the broker or not. From what little is describe for what you are trying to do, it really seems like you are trying to use the LWT message in a way it is not intended to be used. But to answer your specific question, yes, the LWT topic is just a topic and you can publish anything you want to it.

I think ESPEasy has the best implementation of LWT I’ve encountered thus far. When a client starts up it publishes as a retained message “online” to the LWT topic. If it disconnects, the broker will publish a retained message “offline” to the LWT topic. I think Homie works like this too. Thus, at any time one can subscribe to the client’s LWT topic and immediately know whether it is actively connected to the broker or not.

This is the sort of thing the LWT message is intended to do.

I’m going to move this to the Add-ons Binding category as it really isn’t about development of the OH software.