Exporting item state to mqtt

Hello there,

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.

I would be very grateful for any help.

Regards
Sven

Correct.

Two ways:

  1. 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.

  2. MQTT Event Bus [4.0.0.0;4.1.0.0)

This approach will be a lot less work than you think though.

First of all, you wouldn’t necessarily need extra Items and it would just be one rule.

  1. Add all the Items you care about to a Group
  2. Create a rule triggered by changes to the Group
  3. Use the MQTT binding publishMQTT Action to publish the state to a topic generated based on the name of the triggering Item.

It’d be like four lines of code. But 1 or 2 above would be even less work.

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.