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:
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.
Iâm happy of any kind of support.
Regards Martin
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
Note, given that the command isnât being transformed, you probably donât need the Rule. Use the âOutgoing Value Formatâ in the Thing definition.