and a rule which is intended to use a Switch function to react to each of the 6 possible button presses.
rule "RfBridge send message"
when
Item MQTTSwitch received update
then
logInfo("Switch Pressed Msg Received ", "Update")
var mqttMsg = MQTTSwitch.state.toString
val mqttActions = getActions("mqtt","mqtt:broker:ba9d4bb639")
logInfo("SwitchPressed", mqttMsg)
var dataElement = transform("JSONPATH", "$.RfReceived.Data", mqttMsg) //MQTTSwitchPressed.state.toString)
logInfo("SwitchPressed", dataElement)
switch(dataElement) {
case "455101": { mqttActions.publishMQTT("occ/testrgbred/dps/22/command", "1000") }
case "455102": { mqttActions.publishMQTT("occ/testrgbgreen/dps/22/command", "1000") }
case "455104": { mqttActions.publishMQTT("occ/testrgbblue/dps/22/command", "1000") }
case "683101": { mqttActions.publishMQTT("occ/testrgbred/dps/22/command", "0") }
case "683102": { mqttActions.publishMQTT("occ/testrgbgreen/dps/22/command", "0") }
case "683104": { mqttActions.publishMQTT("occ/testrgbblue/dps/22/command", "0") }
default: { mqttActions.publishMQTT("occ/testrgbblue/dps/22/command", "500") }
}
end
There are no errors reported by VSC and the .rules file loads without problem, however, the Rule is never called, although the logs show that the event has triggered containing the data I’m looking for.
I’d expect to see something in the logs as a result of the logInfo statements before we get to the JSONPATH transform, so I think the first problem is - why isn’t the Rule being triggered?
Looking at your JSONPath expression I think you are missing a part of the topic. If not customized Tasmota does use a device-specific name in the topic. If you are not familiar post what the Tasmota device shows when requesting: http://IP-of-Device/mq? in a browser.
I deleted the MQTTSwitchPressed Thing, recreated it and it is now working. The Rule all worked first time. After 2 days of going around in circles, it feels great when it all works!
Thanks once again, Community, for your responses. Even if no one gave me the exact solution, you encouraged me to go back through everything logically one more time.