[SOLVED] Sonoff POW openhab2 integration

Maybe an issue in M1 then… I still dont understand howcome the names doesnt have to be exact the same. It really makes no sense to me.
Maybe @David_Graeff knows. As far as I can tell he´s the developer of the binding.

Probably not. David doesn’t use nor does he promote the use of .things files.

If there is a bug here though, you will need to try it first on version 2.5 M3 (there were a number of PRs applied to the binding for that release) to see if it’s still a problem and if so, file an issue. I’m certain debug logs will be required as well.

I got everything up running. But I seem to have a problem with my Sonoff RF Bridge 433mhz and JSONPATH.
This is the openhab log when the RF Bride receives at key (RfReceived):

2019-09-12 11:09:04.071 [WARN ] [l.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.RfKey1' in '{"RfReceived":{"Sync":8320,"Low":290,"High":820,"Data":"AB7BC2","RfKey":1}}'
2019-09-12 11:09:04.076 [WARN ] [eneric.internal.generic.ChannelState] - Command '{"RfReceived":{"Sync":8320,"Low":290,"High":820,"Data":"AB7BC2","RfKey":1}}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"RfReceived":{"Sync":8320,"Low":290,"High":820,"Data":"AB7BC2","RfKey":1}}
2019-09-12 11:09:04.107 [WARN ] [l.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.RfKey1' in '{"RfReceived":{"Sync":8320,"Low":290,"High":820,"Data":"AB7BC2","RfKey":1}}'
2019-09-12 11:09:04.110 [WARN ] [eneric.internal.generic.ChannelState] - Command '{"RfReceived":{"Sync":8320,"Low":290,"High":820,"Data":"AB7BC2","RfKey":1}}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"RfReceived":{"Sync":8320,"Low":290,"High":820,"Data":"AB7BC2","RfKey":1}}
2019-09-12 11:09:04.117 [WARN ] [l.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.RfKey1' in '{"RfReceived":{"Sync":8320,"Low":290,"High":820,"Data":"AB7BC2","RfKey":1}}'
2019-09-12 11:09:04.123 [WARN ] [eneric.internal.generic.ChannelState] - Command '{"RfReceived":{"Sync":8320,"Low":290,"High":820,"Data":"AB7BC2","RfKey":1}}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"RfReceived":{"Sync":8320,"Low":290,"High":820,"Data":"AB7BC2","RfKey":1}}
2019-09-12 11:09:04.144 [WARN ] [l.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.RfKey1' in '{"RfReceived":{"Sync":8320,"Low":290,"High":820,"Data":"AB7BC2","RfKey":1}}'
2019-09-12 11:09:04.152 [WARN ] [eneric.internal.generic.ChannelState] - Command '{"RfReceived":{"Sync":8320,"Low":290,"High":820,"Data":"AB7BC2","RfKey":1}}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"RfReceived":{"Sync":8320,"Low":290,"High":820,"Data":"AB7BC2","RfKey":1}}

My thing file looks like the above:

Bridge mqtt:broker:mosquitto "mosquitto" [ host="10.4.28.200", port=1883, secure=false, username="openhabian", password="openhab" ]
{   
    Thing topic sonoffpow1 "Sonoff Pow1 " @ "A Room" {
    Channels:
        Type string : reachable    "Reachable"                [ stateTopic="tele/sonoffPOW1/LWT" ]
        Type switch : power        "Power"                    [ stateTopic="stat/sonoffPOW1/POWER", commandTopic="cmnd/sonoffPOW1/POWER" ]
        Type number : powerload    "Power load"               [ stateTopic="tele/sonoffPOW1/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Power"]
        Type number : voltage      "Line voltage"             [ stateTopic="tele/sonoffPOW1/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Voltage"]
        Type number : current      "Line current"             [ stateTopic="tele/sonoffPOW1/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Current"]
        Type number : total        "Total energy today"       [ stateTopic="tele/sonoffPOW1/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Today"]
        Type number : totalyest    "Total energy yesterday"   [ stateTopic="tele/sonoffPOW1/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Yesterday"]
        Type number : totalall     "Total energy alltime"     [ stateTopic="tele/sonoffPOW1/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Total"]
        Type number : rssi         "WiFi Signal Strength"     [ stateTopic="tele/sonoffPOW1/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
    } 

   Thing topic sonoffbm "RF Bridge" @ "second Room"    {
    Channels: 
        Type string : reachable     "Reachable"            [ stateTopic="tele/sonoffbm/LWT" ]
        Type string : recieveddata  "Received Data"        [ stateTopic="tele/sonoffbm/RESULT", transformationPattern="JSONPATH:$.RfReceived.Data"]
        Type string : recievedsync  "Received Sync"        [ stateTopic="tele/sonoffbm/RESULT", transformationPattern="JSONPATH:$.RfReceived.Sync"]
        Type string : recievedlow   "Received Low"         [ stateTopic="tele/sonoffbm/RESULT", transformationPattern="JSONPATH:$.RfReceived.Low"]
        Type string : recievedhigh  "Received High"        [ stateTopic="tele/sonoffbm/RESULT", transformationPattern="JSONPATH:$.RfReceived.High"]
        Type string : recievedrfkey "Received RfKey"       [ stateTopic="tele/sonoffbm/RESULT", transformationPattern="JSONPATH:$.RfReceived.RfKey"]
        Type switch : button1       "Button 1"             [ stateTopic="tele/sonoffbm/RESULT", commandTopic="cmnd/sonoffbm/RFKEY1", transformationPattern="JSONPATH:$.RfKey1" ]
        Type switch : button2       "Button 2"             [ stateTopic="tele/sonoffbm/RESULT", commandTopic="cmnd/sonoffbm/RFKEY2", transformationPattern="JSONPATH:$.RfKey1" ]
        Type switch : button3       "Button 3"             [ stateTopic="tele/sonoffbm/RESULT", commandTopic="cmnd/sonoffbm/RFKEY3", transformationPattern="JSONPATH:$.RfKey1" ]
        Type switch : button4       "Button 4"             [ stateTopic="tele/sonoffbm/RESULT", commandTopic="cmnd/sonoffbm/RFKEY4", transformationPattern="JSONPATH:$.RfKey1" ]
        Type number : rssi          "WiFi Signal Strength" [ stateTopic="tele/sonoffbm/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
    }
}

It´s ONLY the RF Bridge which returns this error.

One of these JSONPATH is not like the other

but maybe more important
JSONPATH:$.RfKey1
isn’t going to match anything in
'{"RfReceived":{"Sync":8320,"Low":290,"High":820,"Data":"AB7BC2","RfKey":1}}'

But why?
For now, untill I figured this out, I have deleted the four buttons channels. They seem to make a mess (Spamming my openhab log file whenever the bridge receive any message).

The JSONPATH looks for “RfKey1”
There isn’t one.
“RfKey” without the “1” isn’t close enough.

I guess what you really want to do is activate this channel if RfKey value 1 is present, and that channel if RfKey value 2 is present?
There is an advanced technique involving chaining REGEX

Maybe " $.RfReceived.RfKey " could help !?

Hmm I dont get it…
I have a device spamming my RF Bridge, and I have yet to find this device…
Message from RF Bridge consol looks like this aprox every 10 seconds (and sometimes it stops for hours).:

12:15:32 MQT: tele/sonoffbm/RESULT = {"RfReceived":{"Sync":6980,"Low":240,"High":690,"Data":"EEEEEE","RfKey":"None"}}

This trigger the JSONPATH warning as well. And I have no idea how to correct it.

It´s already defined as a channel.

        Type string : recievedrfkey "Received RfKey"       [ stateTopic="tele/sonoffbm/RESULT", transformationPattern="JSONPATH:$.RfReceived.RfKey"]

Sorry, didn’t saw this

Type switch : button1       "Button 1"             [ stateTopic="tele/sonoffbm/RESULT", commandTopic="cmnd/sonoffbm/RFKEY1", transformationPattern="JSONPATH:$.RfKey1" ]

What does your WebUI (of Sonoff) shows, when using the Topic ?

Have you an understanding that an incoming message works it way through your list of incoming channels until it finds a match, and then stops?

It doesn’t. It tries to match every channel. The channels looking for RfKey1 fails because there isn’t an RfKey1

I do not have aRF-Bridge, but I found this snippet (and saved it, maybe I will get a Bridge in the future)

        Type switch : button1       "Button 1"             [ stateTopic="stat/sonoff-rf/RESULT", commandTopic="cmnd/sonoff-rf/RFKEY1", transformationPattern="JSONPATH:$.RfKey1" ]

As you can see it’s a “little” bit different :wink:

Partly :frowning:
I know there has to be a match. And there is a match with the RfKey (without 1) when the RF Bridde receive the EEEEEE message.
It also returns the “None” allright.

But I fail to understand, why JSONPATH returns a warning… It seems like it (JSONPATH) continues to the four buttonchannels, and somehow mix up the RfKey with the RfKey1 (or any simular number).
I have 4 keys learned in the Bridge from my Key fob. They´re learned on RfKey1 - Rfkey4.
So JSONPATH should dicover the match fine then…

The JSONPATH warning is gone, when I remove the four Switch (buttons) channels from my thing file.

There is… I made a small typo… But Rfkey1 is still the same. And after correcting the typo, I still got the JSONPATH warning :slight_smile:
This is how it looks right now, (though I have disabled the button channels).

   Thing topic sonoffbm "RF Bridge" @ "second Room"    {
    Channels: 
        Type string : reachable     "Reachable"            [ stateTopic="tele/sonoffbm/LWT" ]
        Type string : recieveddata  "Received Data"        [ stateTopic="tele/sonoffbm/RESULT", transformationPattern="JSONPATH:$.RfReceived.Data"]
        Type string : recievedsync  "Received Sync"        [ stateTopic="tele/sonoffbm/RESULT", transformationPattern="JSONPATH:$.RfReceived.Sync"]
        Type string : recievedlow   "Received Low"         [ stateTopic="tele/sonoffbm/RESULT", transformationPattern="JSONPATH:$.RfReceived.Low"]
        Type string : recievedhigh  "Received High"        [ stateTopic="tele/sonoffbm/RESULT", transformationPattern="JSONPATH:$.RfReceived.High"]
        Type string : recievedrfkey "Received RfKey"       [ stateTopic="tele/sonoffbm/RESULT", transformationPattern="JSONPATH:$.RfReceived.RfKey"]
//        Type switch : button1       "Button 1"             [ stateTopic="tele/sonoffbm/RESULT", commandTopic="cmnd/sonoffbm/RFKEY1", transformationPattern="JSONPATH:$.RfKey1" ]
//        Type switch : button2       "Button 2"             [ stateTopic="tele/sonoffbm/RESULT", commandTopic="cmnd/sonoffbm/RFKEY2", transformationPattern="JSONPATH:$.RfKey2" ]
//        Type switch : button3       "Button 3"             [ stateTopic="tele/sonoffbm/RESULT", commandTopic="cmnd/sonoffbm/RFKEY3", transformationPattern="JSONPATH:$.RfKey3" ]
//        Type switch : button4       "Button 4"             [ stateTopic="tele/sonoffbm/RESULT", commandTopic="cmnd/sonoffbm/RFKEY4", transformationPattern="JSONPATH:$.RfKey4" ]
        Type number : rssi          "WiFi Signal Strength" [ stateTopic="tele/sonoffbm/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
    }

It also dont explain howcome JSONPATH gives a warning when the Brigde sends the EEEEEEE message. (RfKey)

12:59:58 MQT: tele/sonoffbm/RESULT = {"RfReceived":{"Sync":7050,"Low":250,"High":690,"Data":"EEEEEE","RfKey":"None"}}

Yep. The binding gets a bunch of data (it happens to be JSON). The binding works through every channel for that topic Thing looking for things to do. (EDIT - where the stateTopic matches of course)
In your case, each channel has its own JSONPATH to run. So, every different JSONPATH for every channel is run on the incoming data.

If the JSONPATH looks for “banana” and it is not present in the data packet, it will fail.

Thats what I thought as well… But how come I get the JSON warning when receiving the “RfKey” then? It is there, its defined in the String channel (above the buttons).

Here is the full example:

    Thing topic sonoffrf "RF Bridge" @ "Yet Another Room" {
        Type string : reachable     "Reachable"            [ stateTopic="tele/sonoff-rf/LWT" ]
        Type string : recieveddata  "Received Data"        [ stateTopic="tele/sonoff-rf/RESULT", transformationPattern="JSONPATH:$.RfReceived.Data"]
        Type string : recievedsync  "Received Sync"        [ stateTopic="tele/sonoff-rf/RESULT", transformationPattern="JSONPATH:$.RfReceived.Sync"]
        Type string : recievedlow   "Received Low"         [ stateTopic="tele/sonoff-rf/RESULT", transformationPattern="JSONPATH:$.RfReceived.Low"]
        Type string : recievedhigh  "Received High"        [ stateTopic="tele/sonoff-rf/RESULT", transformationPattern="JSONPATH:$.RfReceived.High"]
        Type string : recievedrfkey "Received RfKey"       [ stateTopic="tele/sonoff-rf/RESULT", transformationPattern="JSONPATH:$.RfReceived.RfKey"]
        Type switch : button1       "Button 1"             [ stateTopic="stat/sonoff-rf/RESULT", commandTopic="cmnd/sonoff-rf/RFKEY1", transformationPattern="JSONPATH:$.RfKey1" ]
        Type switch : button16      "Button 16"            [ stateTopic="stat/sonoff-rf/RESULT", commandTopic="cmnd/sonoff-rf/RFKEY16", transformationPattern="JSONPATH:$.RfKey16" ]
        Type number : rssi          "WiFi Signal Strength" [ stateTopic="tele/sonoff-rf/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
    }

The little difference is the keyword “stat” in the topic instead of “tele” could this make the difference ?

1 Like

“RfKey” in the data is not equal to “RfKey1” being sought.

Arrgh, damit… Didnt see that one… Nice catch!
I´ll give it a try…

You missed my second mqtt message:

13:03:09 MQT: tele/sonoffbm/RESULT = {"RfReceived":{"Sync":7080,"Low":240,"High":700,"Data":"EEEEEE","RfKey":"None"}}

Notic the “RfKey” (without any number).
This channel is defined like this:

        Type string : recievedrfkey "Received RfKey"       [ stateTopic="tele/sonoffbm/RESULT", transformationPattern="JSONPATH:$.RfReceived.RfKey"]

This should not return a JSON warning, but it does… Otherweise I simply dont get it.

But I believe Fibu found the reason… Ofcouse the buttons would need to be stats, otherweise the bindings thinks it´s receiving the same RfKey again. (at least this is my guess).

EDIT - Fibu-freak seems to be right… Changing the buttons channels to stat solved the problem… Sorry I totally missed that stupid cut&paste error… :frowning:

POW2 MQTT integration