[SOLVED] How do I setup an Item to interpret MQTT payload

I have a Sonoff RF Button paired to a Sonoff RF Bridge.
The RF Bridge has been flashed with Tasmota firmware
OH and the RF Bridge have been configured as MQTT clients

When the Button is pressed, the RF Bridge publishes a MQTT message with the payload

{"RfReceived":{"Sync":9600,"Low":320,"High":920,"Data":"4045E2","RfKey":"None"}}

I’m gessing that Transformation can parse the JSON payload and tell me

  • RfRecived
  • Sync value
  • Low value
  • High value
  • Data value
  • RfKey value

The “Data” element seems to be the button identifier
This is the only MQTT message sent

I’d like the have all of the values available when writing rules for a button press event.
How would I define an Item that can parse the payload?
How would I make each of the payload elements available in the rule handling the button press event?

In addition, the following would be helpful

Any links to docs on just what each element means?
Any experience with Portish firmware for the RF Bridge? https://github.com/Portisch/RF-Bridge-EFM8BB1

Both are clients?

I haven’t used RF with sonoff but I do have several sonoff devices that comm. with MQTT

Here is what item looks like in my OH for the RSSI strength.

Number Your_Items_Name "A description of Item: RSSI [%d %%]" 
//	{ mqtt="<[pibroker:tele/sonoff/STATE:state:JSONPATH($.Wifi.RSSI)]" }

From sonoff UI console

 MQT: tele/sonoff/STATE = {"Time":"2018-08-30T13:30:04","Uptime":"22T01:11:15","Vcc":3.206,"POWER":"OFF","Wifi":{"AP":1,"SSId":"Your SSID","RSSI":100,"APMac"

Maybe this will help with what your OH item should look like when receiving a message from sonoff via MQTT.

You have two choices.

You can create one Item for each piece of data and configure them all to subscribe to the same topic. The difference will be you will use a different JSONPATH to extract different data for each Item. This is a good approach when you don’t necessarily need to do anything beyond putting this data into an Item.

The other option is to use a String Item that subscribes to the MQTT topic and this Item gets updated to the full JSON message. Trigger a Rule when this String Item is updated then use the transform Action to extract each piece of data for use in that Rule. This is a good approach when you need to be sure you have all the fields from that message available at the same time (in the previous approach each Item gets updated in parallel) or you don’t necessarily need to store the data in an Item.

Thank you

The I’m having some issue with the JSONPATH

My Item

String SonoffRF "RF Bridge: MQTT return message [%s]" { mqtt="<[broker:tasmota/tele/rf-bridge/RESULT:state:default]" }

Here is my rule

rule "RfBridge send message"
when 
    Item SonoffRF changed 
then
    var mqttMsg = SonoffRF.state.toString 
    logInfo("SonoffRFMsg", mqttMsg)
    var dataElement = transform("JSONPATH", ".$.RfReceived.Data", SonoffRF.state.toString)
    logInfo("SonoffRFData", dataElement)

end

Here is my Log

18:43:42.419 [INFO ] [del.core.internal.ModelRepositoryImpl] - Refreshing model 'rfBridge.rules'
18:43:57.248 [INFO ] [smarthome.event.ItemStateChangedEvent] - SonoffRF changed from {"RfReceived":{"Sync":9620,"Low":310,"High":930,"Data":"4045E2","RfKey":"None"}} to {"RfReceived":{"Sync":9600,"Low":310,"High":920,"Data":"4045E2","RfKey":"None"}}
18:43:57.280 [INFO ] [se.smarthome.model.script.SonoffRFMsg] - {"RfReceived":{"Sync":9600,"Low":310,"High":920,"Data":"4045E2","RfKey":"None"}}
18:43:57.282 [INFO ] [e.smarthome.model.script.SonoffRFData] - {"RfReceived":{"Sync":9600,"Low":310,"High":920,"Data":"4045E2","RfKey":"None"}}

I’m not getting the Data element

I also notice that if the bridge sends the exact same message as the previous message, the rule does not fire. Is there a nifty way to fire the rule 100% of the time?

No . in front of the $

rule "RfBridge send message"
when 
    Item SonoffRF changed 
then
    var mqttMsg = SonoffRF.state.toString 
    logInfo("SonoffRFMsg", mqttMsg)
    var dataElement = transform("JSONPATH", "$.RfReceived.Data", mqttMsg)
    logInfo("SonoffRFData", dataElement)
end

Vincent got to the JSONPATH first.

For the latter problem, use received update instead of changed as the rule trigger.

Well, that did not seem to do anything, any other pointers?

rule "RfBridge send message"
when 
    Item SonoffRF received update 
then
    var mqttMsg = SonoffRF.state.toString 
    logInfo("SonoffRFMsg", mqttMsg)
    var dataElement = transform("JSONPATH", ".$.RfReceived.Data", mqttMsg)
    logInfo("SonoffRFData", dataElement)

end

No change

20:15:28.330 [INFO ] [se.smarthome.model.script.SonoffRFMsg] - {"RfReceived":{"Sync":9610,"Low":310,"High":920,"Data":"4045E2","RfKey":"None"}}
20:15:28.334 [INFO ] [e.smarthome.model.script.SonoffRFData] - {"RfReceived":{"Sync":9610,"Low":310,"High":920,"Data":"4045E2","RfKey":"None"}}

Sonoff console

02:15:28 MQT: tasmota/tele/rf-bridge/RESULT = {"RfReceived":{"Sync":9610,"Low":310,"High":920,"Data":"4045E2","RfKey":"None"}}

Thank you, received update exactly fits “nifty”

You still have a . in front of your $ in the transform:
It should be:
"$.RfReceived.Data"

Still no luv
Rule

rule "RfBridge send message"
when 
    Item SonoffRF received update 
then
    var mqttMsg = SonoffRF.state.toString 
    logInfo("SonoffRFMsg", mqttMsg)
    var dataElement = transform("JSONPATH", "$.RfReceived.Data", mqttMsg)
    logInfo("SonoffRFData", dataElement)

end

Result

20:25:49.163 [INFO ] [del.core.internal.ModelRepositoryImpl] - Refreshing model 'rfBridge.rules'
20:26:03.648 [INFO ] [smarthome.event.ItemStateChangedEvent] - SonoffRF changed from {"RfReceived":{"Sync":9610,"Low":310,"High":920,"Data":"4045E2","RfKey":"None"}} to {"RfReceived":{"Sync":9520,"Low":330,"High":910,"Data":"4045E2","RfKey":"None"}}
20:26:03.660 [INFO ] [se.smarthome.model.script.SonoffRFMsg] - {"RfReceived":{"Sync":9520,"Low":330,"High":910,"Data":"4045E2","RfKey":"None"}}
20:26:03.662 [INFO ] [e.smarthome.model.script.SonoffRFData] - {"RfReceived":{"Sync":9520,"Low":330,"High":910,"Data":"4045E2","RfKey":"None"}}

Silly question but is the JSONPATH transform installed?

DOH…
Thank you

Sometimes it’s the simplest things…
Good night