I created rules to publish data in json format, I’m not really sure about the format of the rule… So my rules has errors, any help on what am I doing wrong…?
rule "mqtt update"
when
Item mylight received update
then
mylight.SendCommand("{\"fport\":\"10\",\"object"\"control1\":\"mylight\"}")
logInfo("Test2","running")
end
oh… Never thought about transforms . Yeah I need to send the status of mylight to mqtt broker.
I did like you said but it is not working… I’m sorry but what exactly do you mean by escape double quotes
I read through the link you gave, but I really did not get it.
I am able send it to mqtt lens, but that’s only 1 and 0. I need to send it with json payload… I tried doing so by writing rules, but like I said my rules have errors but I’m not sure what errors…
It errors because you try to send a string to a switch item. A switch item only accepts ON and OFF as commands. If you want to send something else to the actual device you need to specify that in the item definition, with a transform, like @vzorglub suggested. An alternative is to use the mqtt action to publish directly from the rule instead.
@mmj6
It should work as I set it up
What does the openhab.log show when you change the switch on the UI?
Is the MAP transform installed?
Is the mylight.map located in the /etc/openhab2/conf/transform folder?
Can you publish you code? rules, items and map file as they are, please?
Thanks
You have two items named the same. That won’t work.
Rename the second one and
And add a space after the { abd before the } it helps the parser sometimes
2018-08-28 16:53:11.934 [ome.event.ItemCommandEvent] - Item 'mylight' received command ON
2018-08-28 16:53:11.936 [vent.ItemStateChangedEvent] - mylight changed from OFF to ON
2018-08-28 16:53:12.094 [ome.event.ItemCommandEvent] - Item 'mylight' received command OFF
2018-08-28 16:53:12.097 [vent.ItemStateChangedEvent] - mylight changed from ON to OFF