Parsing Data from a Sonoff Bridge flashed with Tasmota

Platform: OpenHAB 3 running on RPI 4

I have a known working Mosquitto broker running on the Pi with about 12 lights working perfectly.

I am now trying to capture RF Switch events through a Tasmota flashed Sonoff Bridge. I have a Generic MQTT Thing called MQTTSwitchPressed

which is linked to an Item called MQTTSwitch

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.

2021-02-18 17:43:10.970 [INFO ] [openhab.event.ChannelTriggeredEvent ] - mqtt:broker:ba9d4bb639:MQTTSwitchPressed triggered {“Time”:“2021-02-18T17:43:10”,“RfReceived”:{“Sync”:11900,“Low”:430,“High”:1180,“Data”:“683102”,“RfKey”:“None”}}

Can anybody point me at the problem (or problems!), please?

Thanks as always for your help and support
Chris

Sorry, the Rule and Log didn’t come out in the correct format

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

2021-02-18 17:43:10.970 [INFO ] [openhab.event.ChannelTriggeredEvent ] - mqtt:broker:ba9d4bb639:MQTTSwitchPressed triggered {"Time":"2021-02-18T17:43:10","RfReceived":{"Sync":11900,"Low":430,"High":1180,"Data":"683102","RfKey":"None"}}

So, your Item never updates? (See your events.log)
You’ll need to fix that first. Maybe it’s your JSONPATH at fault.

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.

In this case I would expect the correct Topic to be:

occ/tasmota/RfReceived.Data

Although I have to guess (don’t have such device), especially unsure about the RfReceived.Data (replace . by /??).

I own a SONOFF Bridge flashed with tasmota/portisch and followed this guide(s) with success:
https://tasmota.github.io/docs/devices/Sonoff-RF-Bridge-433/
https://tasmota.github.io/docs/openHAB/
I’m using thing file configuration.

Sorry, I made a mistake. The name of the device should be in the stateTopic, not the JSONPath expression!

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.