MQTT Thing/Item with multiple JSON items OpenMQTTGateway

Hello,

I’m running OH3 and try to find clean way to control my RF sockets over MQTT with the OpenMQTTGateway.

Actually I use a rule that sends a constant JSON formatted string to a EXEC thing that I achieve a output like this:
Full:
mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoRF2 -m “{“groupBit”:0,“period”:273,“address”:54668270,“unit”:1,“switchType”:0}”
Reduced
mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoRF2 -m “{“address”:54668270,“unit”:1,“switchType”:0}”

The Rule

rule "Alex Desk Lamp"

when Item Alex_LED_Desk changed 
then
	if(Alex_LED_Desk.state == ON)
		rfExec.sendCommand("\"{\"groupBit\":0,\"period\":273,\"address\":54668270,\"unit\":1,\"switchType\":1}\"")
	else
		rfExec.sendCommand("\"{\"groupBit\":0,\"period\":273,\"address\":54668270,\"unit\":1,\"switchType\":0}\"")
end

As you can see there are 3 parameters I have to cover.
The switchType Bit is eq. to ON/OFF.

Is it possible to create things/items, that have the adress and unit JSON item in a static way,
so that I only have to pass the ON/OFF value?

Thanks!

yes you can create a thing and use incoming transformation and format before publishing.

1 Like

If you must publish from a rule (for example, you want to publish JSON based on the state of two different Items), then use the MQTT Action instead of exec.

1 Like

Thanks for your fast help!

I forgot about the format before publish swiss army knife :D.
In this way it works fine now.

Thing mqtt:topic:alex_rf_desk_lamp "Alex RF Lampe" (mqtt:broker:db6728e1c1) @ "Alex" 
{
    Channels:
        Type switch : state "State" [ commandTopic ="home/OpenMQTTGateway/commands/MQTTtoRF2", formatBeforePublish="{\"address\":54668270,\"unit\":1,\"switchType\":%s}",on="1",off="0"]
}
1 Like