MQTT and retain flag, current status?

TL;DR: What’s the status of MQTT and retain, particularly in the case of publishMQTT? I see lots of old messages, but no apparent resolutions.

Here’s the deal. I have a Z-wave controller that OH4 owns. That is, the controller knows how to transmit and receive, but has no intelligence. OH4 tells the controller what to transmit, and listens to it for status updates from Z-wave devices.

OH4 publishes the status of the Z-wave devices to my Mosquitto MQTT broker, so other systems in my network can access that information when they need to know. OH4 does this via a rule that calls publishMQTT, and this works well. Or would, except that without the MQTT retain flag, the status data disappears after a while. So some external system X wondering about the state of light switch Y can’t reliably find out its condition.

The MQTT RFC has a retain flag because some messages are transient, while others need to stick around until revised. And whether something should be retained is often determined on a message by message basis, not on a connection-to-the-broker basis. In most use cases, status information (e.g. “light switch Y is on”) is considered permanent data - it stays around until it’s updated. Command instructions are typically transient.

So, I need to mark my status updates as to be retained, while commands I send elsewhere are transient. People have been asking about this for several years. Are we there yet? If not, is this an active issue? I think a simple way to go would be to allow an optional third parameter on the call to publishMQTT to set the retain flag. It’s fine to have an option in channels and such if we want, but sometimes that won’t be selective enough. My rule doesn’t have a channel, nor need one, so channel-level options aren’t useful.

If this isn’t being worked on anywhere, can I open a bug report on MQTT data being lost for lack of a retain flag? If no one else wants to work on this, I probably can, but I don’t even know what language I’d be programming in, and I probably don’t know it anyway (not that that’s ever stopped me before), so an experienced OH developer would be better.

In fact, publishMQTT has a third parameter for retain…

Really! Well now I feel foolish. Is there any documentation about that somewhere? I haven’t seen that in any examples I’ve found on-line, which are few and far between.

I actually tried a third parameter before I posted, and got a page full of JavaScript errors in my log as a result. Maybe just a wrong data type, since I was straight-up guessing that it would want a 1 for retain.

Yes, if you can tell me what that parameter is, or better, tell me how I could have found that out for myself, that would fantastic.

Strike that.

I followed your link (that I didn’t initially recognize as a link). For others, the third parm is “true” (no quotes) to retain.

The link points exactly to the official documentation :slight_smile:

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.