I’m stuck in solving a problem.
What do I want to do?
I’m getting values from different sensors (e.g. Homematic, Zigbee/Deconz, …) and want them to be published to some MQTT topics.
For example I have an item which is linked to the temperature of an aqara zigbee sensor and this temperature should be published to “openhab/some/queue/topic”.
The MQTT Broker is working with other mqtt stuff and I’m subscribing to mqtt topics with openhab successfully.
I tried to link the item (for example the zigbee thing/channel) additionally to an mqtt thing/channel and configured a command topic for publishing.
My expectation was, that if the item value is changing (as the temperature reading changes) a mqtt message should be published. But surprisingly nothing happened. No message was published.
Maybe this is, because the item is only “updated” without a command?
But how could I easily achieve what I want to do without a lot of work? Of course I could create a second item, which is linked to the mqtt thing/channel and send changes as commands via rules, but this would tripple the work as I would have to maintain additional items and rules.
Configure the Follow Profile on the link. Updates from the Channel get forwarded as commands to the second Channel Configure the MQTT Channel as the second.
Thank you for you quick reply.
I tried the first way using the Follow Profile and it seems to work.
Maybe I also try the second way once I migrated to OH 4.
I have approximately the same problem.
I have a String type item that receives the average home temperature.
I linked it to the channel, which is the topic openhab/temperature/avgTemp/command
I have enabled the follow option, but I don’t see anything publish when the item string is updated
Please post the complete channel definition, otherwise we can only guess what’s wrong.
At first sight, your topic says command, but a temp sensor does not receive commands, it has a state only.
with OH2 I had created an item string that sent the temperature value to the thermostat and displayed it on the display and a rule that updated the item string with the average of the values taken from the sensors. In OH3 I managed to do almost everything, except that I can’t publish the value of the item string to the thermostat.
The follow profile causes one Channel to follow the state updates from another Channel. Simply changing the state of the Item will not activate the follow profile. You don’t have another Channel linked to the Item here so the follow profile does nothing for you.
Where is this average temperature coming from? A rule?
But it’s a String Item. You can’t link a number Channel to a String Item and expect everything to work. In particular, %1f only works with Numbers but because it’s a String Item you don’t have a number to format here, you’ve a String. In truth, I’m astonished [%.1f °C] wasn’t throwing errors in OH 2.5 too. %.1f only works with Numbers, not Strings.
Use a Number:Temperature Item, not a String Item; set the unit metadata to °C. Or just use a plain Number Item but change your MQTT config to remove the unit: °C. Either you need to use units or you don’t.
Link this Number:Temperature Item to the MQTT Channel without any profiles. There’s nothing to “follow” here.
Whatever rule is calculating the average temperature needs to sendCommand the new value to the Item. Only Item commands get sent on to the binding and here out as a message over MQTT. Updates never leave openHAB.
That’s it. In short, just configure this Item to be what it is.