LWT speed? Currently taking 10+ seconds...would prefer a higher poll rate on some groups

Is it possible to configure the rate at which LWT messages are received by mosquitto?

The LWT speed matters a little because I use a rule to switch off Sonoff A (powering a lamp) when Sonoff B (powered by a PIR) loses power.

I’m running the latest OH2 version on a RPi.

From: https://www.hivemq.com/blog/mqtt-essentials-part-9-last-will-and-testament

If the client disconnect abruptly, the broker sends the message to all subscribed clients on the topic, which was specified in the last will message.

The LWT messages are sent by the broker, there is no polling involved.

You do can specify time-to-LWT as a (global) timeout in Mosquitto, but that would mean to choose the wrong path.
If your setup relies on regularly receiving LWTs in time, it is bad system design.
LWTs are to handle exceptions such as loss of power or connectivity to do state recovery, cleanup etc., that shouldn’t happen often, so 10+ seconds is fine in those cases.

I understand that, thanks. My question is about the broker, so really an MQTT question, not an OH one, but I thought maybe I’d get lucky :wink:

Maybe I should not have used the word polling, but I can’t think of another that describes what happens. When the Sonoff device gets disconnected abruptly, i.e. powered off, it can not send a message about it. The broker - at some point - notices that the Sonoff is not functioning any more and publishes a LWT on the Sonoff’s behalf. My question is can one speed up how fast the broker notices abruptly disconnected devices?

The answer is:

Thanks both. I’ll check out if there can be a Tasmota per-client (or per-group) Keepalive client request or server config. I would prefer that to a server side config forcing that for all clients.

Not strictly correct. One of the criteria for when the LWT gets sent is

The client fails to communicate within the Keep Alive time.

And while it is true that there is no polling involved, there is a time period that could expire when the client just stops sending anything where the LWT will get sent. I suspect this is the case that Kiat is encountering.

This article has a good description of what is actually going on under the covers for the keepalive:


It appears that this polling period is set by the client.

@gr1nch, there is a keepAlive parameter you can add to your mqtt.cfg file under conf/services.

But this will only apply to openHAB’s connection. Each of your MQTT clients have to set their own keepAlive value if you do not want to use the default, which is defined in the client library, not the server.

One of the things that is hard for users of MQTT to understand is that parameters like this are not set by the broker, they are set by the client. The client is what tells the broker how much time can pass without network traffic before calling the connection dead. This lets each client define their own keepalive time that suits that specific client’s needs.

Similarly, you will not find a QOS or retain parameter in your broker’s config. This is because the client sets these parameters on a message by message basis. Counter to what one expects, they are not broker wide parameters.

Unfortunately, that just isn’t how MQTT works. The clients have to tell the broker what the keepAlive period is when they connect.

Thanks for explaining that @rlkoshak. Actually, MQTT client side configuration is perfect for my use case. I just didn’t want server side, as it was previously explained to me, to be global and forced on all clients. So, it can’t be and that’s that. Having read the rticle you linked to and the mqtt.conf man page the server-side KeepAlive setting is for bridges to other brokers as I understand it.

Back to the point at hand, I couldn’t see where the Tasmota client can be configured to set its own Keepalive parameter request to the broker.

Any ideas?

Today I’ve discovered the Tasmota/Sonoff user group on Google group which looks a great resource for OpenHAB users like me who utilise Sonoffs.

Yes. In that case the Mosquitto broker is behaving as a client to another broker so all the usual client connection parameters are present in that section.

I’m running a several months old version of Tasmota on a Sonoff. The option may not be there.

But just to reiterate Markus’ warning. LWT should only be occurring in an error case. If 10 seconds is too long of a wait then you probably should be relying on some other mechanism to detect this problem. Decreasing the keepAlive does not come for free. The shorter the period the more essentially pointless traffic that will flood your wifi.