Hello everyone,
I’ve been using MQTT v2.5.5 for a while now to get data/values INTO openhab, which works perfectly. So the MQTT configuration itself (mosquitto as broker, binding, thing, channels) should not be the issue. I now want to get the state of an item OUT OF openhab, for which I want to publish the value to the broker (running on localhost) and have other clients subscribe to that topic.
For testing purposes I defined the channel as “read”, meaning in PaperUI I put the topic in the channel’s MQTT State Topic. Submitting a publish to that channel from the external client using mosquitto_pub shows up in openhab and the item gets updated. This is the item definition:
Number item1 {channel="mqtt:topic:344c69dc:item1"}
So far, so good. Now I tried entering the topic in the channel’s MQTT Command Topic, checking the “Is Command” box, and update the item’s state from within openhab with a rule. My expectation is that this should then push the value out to the MQTT channel, but it doesn’t.
My (rather simple rule) is:
when
Item item2 received update
then
item1.sendCommand(item2.state)
Item2 is an openhab item that gets updated from within openhab, and item1 is linked to the MQTT channel as above. Now when item2 receives an update, the state of item1 changes accordingly, but nothing else happens.
I found actions from (presumably) the older v1 MQTT binding:
val mqttActions = getActions("mqtt","mqtt:broker:87c4e9b7")
mqttActions.publishMQTT("/broker/topic", "message")
but that only works with “message” verbatim, if I try to replace that with item2.state, I get a javascript error, so that is probably not the way to go. BTW, 87c4e9b7 is the MQTT bridge, and 344c69dc is the generic MQTT thing that contains the channels.
Any insights?
Thanks!