[SOLVED] [MQTT2] Send knx item value to mqtt broker with the new mqtt2 binding?

Hello all,

Today I’ve upgraded my system from openhab 2.3 to 2.4. After that I installed the embedded mqtt broker and the new mqtt2 binding.

I have a few knx items (with knx binding 2.4) that represent a temperature or light intensity.

From knx.items:

Number Lichtsterkte_Buiten "Lichtsterkte Buiten [%.1f Lux]" <temperature> (INFO) { channel="knx:device:knxd:generic:lichtsterkte_buiten" }
Number Temperatuur_Buiten "Temperatuur Buiten [%.1f °C]" <temperature> (INFO) { channel="knx:device:knxd:generic:temperatuur_buiten" }
Number Temperatuur_Binnen "Temperatuur Binnen [%.1f °C]" <temperature> (INFO) { channel="knx:device:knxd:generic:temperatuur_binnen" }

With openhab 2.3 and mqtt binding 1.0, I used to send these values to a mqtt broker using the following in mqtt.items:

Number Lichtsterkte_Buiten "Lichtsterkte Buiten [%.1f Lux]" <temperature> { mqtt=">[openhab:lichtsterkte_buiten:state:*:default]" }
Number Temperatuur_Buiten "Temperatuur Buiten [%.1f °C]" <temperature> { mqtt=">[openhab:temperatuur_buiten:state:*:default]" }
Number Temperatuur_Binnen "Temperatuur Binnen [%.1f °C]" <temperature> { mqtt=">[openhab:temperatuur_binnen:state:*:default]" }

That seemed to work OK. Now I’m trying to do the same with the mqtt2 binding, but that doesn’t seem to work for me.

Whenever I add the knx item (e.g. ‘temperatuur_buiten’) to the generic mqtt thing channel it seems to override the knx item value. And so in the end nothing gets published to the mqtt broker because nothing is feeding the item anymore…


What am I doing ‘wrong’? Any ideas?

(I haven’t try working around this issue with rules yet)

Eddy

Did you comment out ( // ) or remove the old mqtt item from the files?

If so you may need to clean the cache and reboot so the new binding picks up the item.

Oh I didn’t mention that. I indeed deleted the old mqtt.item file. (and I also deleted the mqtt.cfg file since I’m using the embedded broker now).

The new MQTT binding cannot send payloads on state change only as far as I know, unfortunately.

@H102 Restarting and cleaning the cache didn’t help.

Anyone more ideas?

Really? What is the commandTopic option for then?

For sending a command…
In a rule as in item.sendCommand()

In the old binding it was possible to do this:

Switch mySwitch { mqtt=">[broker:topic:state:*:default]" }

Which would send an MQTT payload on every state update on the item
Unfortunately this is not possible with the new binding as far as I know

@David_Graeff is this intentional or are you planning to implement this? I might be able to make a PR if you can point me in the right direction.

Edit: I mean not sending status updates over MQTT.

Guys please read the detailed binding documentation. stateTopic and commandTopic are well described.

And yes the MQTT binding assumes it is the only source for an Item state and will override any existing state with the mqtt topic payload. If no payload is received yet the item is initialised with UNDEF.

All new bindings are doing it this way. If someone wants to synchronise two items (KNX and MQTT for example) he/she would use a follow profile.

I admit I’m a little confused about where to find the canonical documentation for the MQTT binding. I would expect it to be here: https://www.openhab.org/addons/bindings/mqtt/
However, that page doesn’t contain any of the information you are referring to.

It’s in there:

Thx David, this confirms the behaviour I saw. Is there any documentation about this behaviour somewhere? Also which bindings do it like that and which don’t? Doesn’t seem completely consistent to me.

I had worked around it using rules. I’ll take a look to the follow profile.

Hello all,

The follow profile solves it indeed. Thx to @David_Graeff.

So to summarize for one of the items:

I have a knx item called ‘temperatuur_binnen’. This one is linked to the corresponding knx channel in a knx.items file.

I have also setup a MQTT Generic Thing with PaperUI and added a ‘temperatuur_binnen’ channel with just a MQTT command topic:

After that I linked the temperatuur_binnen item to the mqtt channel and selected the system:follow profile:

This way whenever the knx temperature sensor sends a new measurement, the measurement also gets forwarded to the mqtt broker :smiley:

Hopefully this helps someone else too.