Using MQTT Persistence

I’m returning to Openhab after a 2-year hiatus - I didn’t use another platform in the interim, I simply went without while renovating my new property. It’s now time to set up Openhab and my z-wave environment once more, and I’m having a bit of trouble with MQTT.

In my old system I used MQTT persistence. Every single item was get/set on the broker. I had no items that came into openhab via the broker (i.e. Wifi items), and I don’t remember that I had any 3rd party software feed off the broker; it was just regular z-wave items and the like. I can’t currently remember what use I actually made of the traffic on the broker, so my first question is: what use is MQTT persistence to an Openhab system that already knows all items directly?

My second question is, if there’s some kind of positive answer to the first, how the hell do I set this up under Openhab 2.5.0? I have the MQTT binding up and running successfully, but the instructions for the MQTT persistence are from 1.x, and reference the 1.x MQTT binding configuration - documentation unavailable on the main Openhab site. The MQTT broker Thing is set up via the PaperUI and I’ve been defining my (non-MQTT) items via .items files, so how do I configure the persistence, and how do I ensure that all of my z-wave items, for example, are get/set from the broker? Does this need the “mqtt=” string manually entered into every single item record, or is there a passive way that every item on the bus is copied to the broker?

It may be that MQTT persistence has no benefit for me and I abandon the idea, though I will use MQTT for the likes of Owntracks. It’s interesting that there’s currently a hole in the documentation (that for 1.x MQTT-persistence does not align with that of the 2.x MQTT binding), though perhaps the hole is in my understanding only.

Is this a discussion worth having, or am I barking up the wrong tree here?

  • Platform information:
    • Hardware: Raspberry Pi 4, 4Gb RAM
    • OS: Buster latest
    • Java Runtime Environment: openjdk version “1.8.0_222”
    • openHAB version: 2.5.0~S1674-1

We cannot answer why you did that. Perhaps you didn’t want to use a more conventional persistence service; that would be more usual if you wanted to save and restore values.

Perhaps if you describe what you are trying to achieve, we can suggest the most elegant mechanism to do it.

1 Like

In fact, you can still use the mqtt persistence, but as it’s legacy, you have to switch on legacy bindings first.

Same for documentation:

But as rossko57 already stated, this is an uncommon way to persist data, for restoreOnStartup simply use mapdb.

1 Like

Both, thanks for the replies. I actually had MySQL and InfluxDB set up also, so it wasn’t an aversion to traditional persistence.

I actually just found the following snippet in my post history:

mqtt-eventbus.cfg:
broker=m2m-eclipse
statePublishTopic=/openHAB/out/${item}/state
commandPublishTopic=/openHAB/out/${item}/command
stateSubscribeTopic=/openHAB/in/${item}/state
commandSubscribeTopic=/openHAB/in/${item}/command

This shows that there was an eventbus method of achieving this - and that I not going mad. Udo, the documentation that you linked is the one that I’ve been looking at and concluded that there’s a missing piece. For example, the eventbus is no longer mentioned.

I truly don’t remember my original use case, but I’ve noticed that the answer most often offered to similar questions is “there’s probably a more appropriate persistance solution to your needs”. Probably true, but it begs the question: what is the use case for mqtt-persistence?

You want to dump all your Item changes to some external service that has an MQTT listener capability. Maybe another openHAB instance, maybe some exotic database, maybe an elaborate logger.

It’s no longer some special service of a special binding. Exploit the capabilities of MQTT v2 binding to achieve the same ends.

1 Like

Rossko, thank you. I don’t have a use case it seems. Thanks for linking the article on the MQTT 2.5 event bus - very informative and it has convinced me not to pursue the option.