Hello,
I have OH2.4 running with MQTT and a Mosquito Broker (separate instance, not on OH instance).
Today I tried to add INNR Plugs to my setup.
I have included the plugs to my MQTT network and using MQTT.fx I can switch them. As the plugs needs to get the command as JSON string, I tried different ways to set this up but all failed.
Important to mention is that I do not use a Things file, instead I have my configuration running using Paper UI.
I have created a new Switch item and set the Command Topic to “zigbee2mqtt/WZ/PLUG/CAMERA/set”.
Then i created a JS file with the following content and add this to Outgoing value format JS:onoff.js.
(function(x) { var result = new Object();
if (x==ON) {result.state = “state:ON”}
else if (x==OFF) {result.state = “state.OFF”}
return JSON.stringify(result);
})(input).
That didn’t work, so I tried to add the information directly in Paper UI:
ON={“state”:“ON”}, OFF={“state”:“OFF”}.
Finally I tried using a rule to run the command:
val mqttAction = getActions(“mqtt”,“mqtt:systemBroker:MQTTBroker”)
mqttAction.publishMQTT(“zigbee2mqtt/WZ/PLUG/CAMERA/set”,“{"state":"ON"}”)
This returns an error:
Rule ‘testbutton’: Instance is not an MQTTActions class.
So I have no further idea how to proceed. Different aspects seems just to work using things files instead of working through the UI.
It’d be helpful to see what you send, what you’re trying to acheive.
You’ve got mqtt.fx to monitor what happened here. May we know what happened too?
You would normally get actions associated with a broker, not with a systembroker. You don’t need any systembroker Thing unless you are using the embedded broker.
rule "Test Item"
when
Item TEST222a received command
then
val value = '{\"state\":\"' + receivedCommand + '\"}'
val actions = getActions("mqtt","mqtt:broker:myMQTTBroker") // myMQTTBroker is the name of my broker yours may be different
actions.publishMQTT("zigbee2mqtt/WZ/PLUG/CAMERA/set",value)
end