[SOLVED] Sonoff POW openhab2 integration

Yes, openHABian will install Mosquitto. I don’t think it get’s installed by default so you will want to go through openhabian-config to get it installed. Mosquitto is what most of us use I believe.

If you want a simpler to set up and use broker, OH now comes with Moquette which is an embedded broker you can install from the MISC tab in PaperUI. But this is a very simple broker lacking many of the features and capabilities of Mosquitto.

image

Docs MQTT - Bindings | openHAB

Yes, I just tried the embedded one… I have no idea what I´m doing or how to configure the manual things file when using this one… I guess I´ll have to try the mosquitto one and follow the examples above.

If you look at the docs (addons) and write mqtt in the search button, there are several (addons) which is named mqtt.
From paperUI there only seem to be one though.

You should do yourself a favor and go read the HiveMQ MQTT Tutorial to give yourself a grounding in how it works. It will save you a lot of effort in the long run. Then a lot of the settings and ways the OH presents MQTT to you will make more sense.

That’s a quirk that I think has an issue set up but hasn’t found a solution. The MQTT docs are split into many pages and each page shows up as a separate entry when you search.

I get the basic idea of MQTT… What I seem to be missing is how to set it up regarding openhab, (using manual things files).

have a look onto this documentation page (it is for the 2.4 version! not the latest!) it cotains an example for trhe file setup at the end!

I cant get it to work with the embedded mqtt broker.
Insted I tried to install mosquitto from openhabian-config. But the installation fails with this, and I have no idea why or where to find a solution:

2019-09-10_15:47:09_CEST [openHABian] Setting up the MQTT broker Eclipse Mosquitto...
$ apt-get update
Get:1 http://archive.raspberrypi.org/debian stretch InRelease [25.4 kB]
Hit:2 http://raspbian.raspberrypi.org/raspbian stretch InRelease
Ign:3 https://dl.bintray.com/openhab/apt-repo2 testing InRelease
Get:4 https://dl.bintray.com/openhab/apt-repo2 testing Release [6,053 B]
Hit:5 https://repos.influxdata.com/debian stretch InRelease
Ign:6 https://dl.bintray.com/openhab/apt-repo2 testing Release.gpg
Hit:7 https://packages.grafana.com/oss/deb stable InRelease
Reading package lists... Done
E: The repository 'https://dl.bintray.com/openhab/apt-repo2 testing Release' is no longer signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
FAILED
[15:47:31] openhabian@openHABianPi:~$

I got it installed using:

sudo apt-get -f install mosquitto

EDIT - Still got problems though… Broker is online, but Thing doesn´t respond…

Please post how you have setup the thing and how your sonoff MQTT settings are (topic and full topic).

I just got it to work… I believe there is a error in the binding, (or at least a issue/cause I wasn´t aware of).

This is my previous .things file which fail to get the thing online:

Bridge mqtt:broker:mosquitto "mosquitto" [ host="10.4.28.200", port=1883, secure=false, username="openhabian", password="openhab" ]
{   
    Thing topic sonoffPOW1  {
    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 : rssi         "WiFi Signal Strength"     [ stateTopic="tele/sonoffPOW1/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
    } 
}

Notice the capital letters in the third line, (sonoffPOW1).

When I changed this to lower letters (sonoffpow1) things got online, and now everything is working allright… Like this:

Bridge mqtt:broker:mosquitto "mosquitto" [ host="10.4.28.200", port=1883, secure=false, username="openhabian", password="openhab" ]
{   
    Thing topic sonoffpow1  {
    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 : rssi         "WiFi Signal Strength"     [ stateTopic="tele/sonoffPOW1/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
    } 
}

Again, notice the third line, now using lower letters.

The topic of my Sonoff Pow is named: sonoffPOW1. So I assumed it should be the same. Unfortunalty this is not true. It seems like capital letters isn´t allowed in the thing name. But in the topic state, it´s has to be exact the same as the device topic named.

Its either a bug or its highly confusing.

Btw I´m using openhabian 2.5 M1. I have no idea if this may have been fixed in the recently released M3 or M2.

I am still on the 2.4 stable release and I am using Thing names with capitals but names that are different then the mqtt topic.

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