One item changes another, best way?

I have a MQTT fed item from a thermostat (room temp). it has incoming mapping to map the json message to get the value out. All good to here.

I now wish to send another MQTT message out in a different json format with that value in the json somewhere.

I know I would write a rule that is triggered on change of what and do a sendCommand in that.

But I am going to need to do this for a number of items and that might be a lot of rules. Is there some slicker way to do this?

Basically, I have an item called cabin_temp. When it changes I need an MQTT send like;

{"sync" :{ "pid": 5, "temp": 27}}

I could do a member of rule to partly do this, the issue would be the pid. I need to store that on the item somehow

You could, if not already done, write your rule in a way that it not used direct item names but event.item and circles through the triggering events automatically.
This might potentially reduce your lines of code to only a few, but requires good planning of item names.
I did something similar here.

You are using MQTT to communicate with your things, in that case I use MQTT messages directly instead of a sendCommand.
Something like:


val mqttActions = getActions("mqtt", "mqtt:broker:xxxxx")
mqttActions.publishMQTT("/lampa-pod-tv/switch/cmd", "get")

In the rule you can use that .publishMQTT multiple times with different topics and payloads.