Publish a set of parameter via JSON format

I customized my AC with an ESP8266 that communicates serial to the AC and via MQTT towards Openhab.
Now, to control the AC the following set of parameters needs to be sent (part of them or all, depends on what you want from the AC).


I’m not sure how i would do that, so that e.g. when using an “on” item to turn it on (which works thanks to @rossko57)…that it would take all other parameters from additional items (like mode, fan speed, setpoint temp) and create this JSON format above…what possibilities do I have, rule-based + mqtt-action binding?


This one, probably, though the action is part of the MQTT Binding already, not separate.

If it’s only a single variable you’re changing you can use formatBeforePublish. But if it’s more than one it’s best to use a rule.

What @hafniumzinc says; you can only access one command to one Item in a channel transformation.

So if you must assemble JSON based on several Item states, then you must do that in a rule.

OK thanks, but requires MQTT-Action Binding if done inside of Openhab ?

The MQTT binding includes an Action which you can access from rules.
It’s in the doc you already looked at

rule "Player State to MQTT"
  Item Tv received command

  val timestamp = new DateTimeType()
  val value = '{\"attribute\": \"player\", \"value\": \"' + receivedCommand + '\", \"timestamp\": \"' + timestamp + '\"}'  
  val actions = getActions("mqtt","mqtt:broker:myMQTTBroker") // myMQTTBroker is the name of my broker yours may be different
  logInfo("publishMQTT", value )

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.