Exec persistence and MQTT variables


i’m trying to find out how to setup a line in exec.persist so I can run a mqtt publish client at intervals.

I’ve got it working but I have to use the FQDN for the MQTT server.

Is there a way that I could have access to the mqtt URL in the openhab.cfg file ?

The reason is, I would need to change the URL in the openhab.cfg and the exec.persist if I ever changed the MQTT server.

Thanks for any input on this.

Jeff C.

I don’t think there is a way to access the URL other than parsing the openhab.cfg file yourself.

But since you want to persist to MQTT, another option is to simply add the MQTT binding to your item. For example:

Number Temperature "my temp [%.1f °C]" { ecobee="<[123456#runtime.actualTemperature]", mqtt=">[mybroker:/mytopic/temp:state:default]" }

This would publish to MQTT every time the item was updated. If that’s too often, you could instead use a rule and the MQTT action bundle. For example:

rule PubToMQTT
  Item Temperature changed

Thank, I think i’ll change the exec persistence to a simple rule…

and thanks for the publishing tip… that exactly what i need. :slight_smile:

1 Like

Lastly, there’s even an MQTT Persistence bundle you could use! All the bases are covered! :smiley: