Using Sonoff Power Switches with Tasmota firmware and openHAB2 MQTT2 binding

Tags: #<Tag:0x00007f1e669310a8> #<Tag:0x00007f1e66930e28> #<Tag:0x00007f1e66930ba8>
(David Graeff) #72

Not yet. At the moment Paper UI and text files are basically fighting each other and it makes sense to choose one and stay there.


(WJ) #73

No real question, some experience shared

Completely agree I had recent a OH mess-up because I followed the manual of the network binding to the letter and created an <openHAB-conf>/services/network.cfg file (not sure if I also installed the binding itself in paper UI).

Later, for another reason I thought it was wise to do the combination of cleaning the cache and deleting file /var/lib/openhab2/config/org/openhab/addons.config in one go with results all bindings were ‘gone’ and things not working. Oeps. Notice in addons.config that only the Network binding was there. Manage to restore this and OH is now running again but some errors on startup remain.


(SiHui) #74

addons.config is created automatically based on the settings in your addons.cfg and should not be edited.
If you define a binding in addons.cfg it takes precedence over the installed bindings in PaperUI, meaning you either have to define ALL your bindings in addons.cfg OR ALL bindings in PaperUI.

1 Like

(WJ) #75

Did not change recently anything in addons.cfg; only package and ui is activated here, which explains I lost in the past habpanel because ui info was ‘ui = basic,paper’ I changed this to ‘ui = basic,habpanel,paper’ but based on your answer the better option is to set ui on comment with #ui?

Yesterday I had good experience to re-add the astro.binding to the addons.config file because adding it to the paper ui again gave problems with adding the Astro things with old names (confession: did a forced remove of these things). The Astro binding is working like a charm now again.


(SiHui) #76

Again: don’t edit the config files! If you do not want to use PaperUI, do your complete setup via addons.cfg, stop openHAB, delete the addons.config, then restart openHAB. Based on your settings in the addons.cfg openHAB will recreate the correct addons.config automatically.


(J Wee) #77

I have a DS18B20 sensor on my sonoff RF that reads fine on the sonoff but has this error in OH under MQTT 2.4

Type string : temperature “Temperature” [ stateTopic=“tele/sonoff/powerstrip3/SENSOR”, transformationPattern=“JSONPATH:$.DS18B20.Temperature”]

Number Sonoffps3_Temperature “Powerstrip3 Temperature [%d °C]” (Sonoffps3) { channel=“mqtt:topic:sonoffps3:DS18B20.temperature”}

This is the error:

2019-01-31 15:55:22.544 [ERROR] [el.item.internal.GenericItemProvider] - Binding configuration of type 'channel' of item 'Sonoffps3_Temperature' could not be parsed correctly.

org.eclipse.smarthome.model.item.BindingConfigParseException: UID segment 'DS18B20.temperature' contains invalid characters. The last segment of the channel UID must match the pattern '[\w-]*|[\w-]*#[\w-]*'.

	at org.eclipse.smarthome.model.thing.internal.GenericItemChannelLinkProvider.createItemChannelLink( ~[?:?]

	at org.eclipse.smarthome.model.thing.internal.GenericItemChannelLinkProvider.processBindingConfiguration( ~[?:?]

	at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings( ~[?:?]

	at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings( ~[?:?]

	at org.eclipse.smarthome.model.item.internal.GenericItemProvider.processBindingConfigsFromModel( ~[?:?]

	at org.eclipse.smarthome.model.item.internal.GenericItemProvider.modelChanged( ~[?:?]

	at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners( ~[?:?]

	at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel( ~[?:?]

	at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile( ~[?:?]

	at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.processWatchEvent( ~[?:?]

	at org.eclipse.smarthome.core.service.WatchQueueReader.lambda$3( ~[?:?]

	at java.util.concurrent.Executors$ [?:?]

	at [?:?]

	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201( [?:?]

	at java.util.concurrent.ScheduledThreadPoolExecutor$ [?:?]

	at java.util.concurrent.ThreadPoolExecutor.runWorker( [?:?]

	at java.util.concurrent.ThreadPoolExecutor$ [?:?]

	at [?:?]

What am I doing wrong?


Configuration of openHAB
(David Graeff) #78

Sigh. It’s not the MQTT bindings fault. You need to read up on the .thing file syntax. I know it is complex and long and tedious, but you decided not use Paper UI.


(Jürgen Baginski) #79

Take a look into PaperUI, under Configuration- Things you will find your thing, click on it and all channels will be shown, under the bold name of the channel the correct syntax for that channel to be used in the items file is shown.
My guess , you omitted the brokername.


(J Wee) #80

Hi David, I am not blaming the binding. I am assuming I mess up somewhere in my configuration of the thing /item file. Which is why I am requesting for insights

Hi Jurgen, you were right on. Somehow I link a wrong item to the temperature channel for that thing.
Thank you very much

1 Like

(Hans Neesen) #81

Had the same problem. Fixed it by deleting the cache and temp removing and afterwards adding the things file with the broker. probably had some mixed paperui old mqtt v1 stuff


(J Wee) #82

Has there been changes to the MQTT 2.4 binding recently?
The “Sonoff Maintenance” rule earlier in this thread no longer works. I get an error

2019-02-25 17:38:51.504 [INFO ] [.smarthome.model.script.sonoff.rules] - Sonoff Maintenance on all devices:queryFW

2019-02-25 17:38:51.505 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Sonoff Maintenance': Instance is not an MQTTActions class.

It was working fine earlier. Currently on the latest 2.5 snapshot


(David Graeff) #83

There are a lot of build related changes and it could just be that the actions part did not compile / not got included / some dependencies are not resolving. It is at the moment not the best idea to use the snapshots and if you do, you need to check your logs intensively.

Cheers, David


(J Wee) #84

Thanks David. So should I just go with the M1 build instead?
Unfortunately I also need the latest Z wave snaphots for my z wave devices


(SiHui) #85

Just download the latest zwave snapshot binding and put it in your addons folder. Uninstall the PaperUI zwave binding first.


(J Wee) #86

Thank you . What is the safest way to move from 2.40/2.50 snapshot to 2.5 M1 , and not have to reconfigure all the Z wave and MQTT items again? Docker installation for OH


(SiHui) #87

Sorry, no idea about Docker :sunglasses:


(Marc) #88

I am using the 2.5 snapshot atm and got strange behaviour…

when is use that thing file entry :

Bridge mqtt:broker:myAuthentificatedBroker "MyBroker" @ "MyHome" [ host="", secure=false, username="openhabian", password="xxxx", qos=1] {
        Type string : reachable "Reachable"            [ stateTopic="tasmota/tele/sonoff-basic-1-00/LWT" ]
        Type switch : power     "Power"                [ stateTopic="tasmota/stat/sonoff-basic-1-00/POWER", commandTopic="tasmota/cmnd/sonoff-basic-1-00/POWER", on="ON", off="OFF" ]
        Type number : rssi      "WiFi Signal Strength" [ stateTopic="tasmota/tele/sonoff-basic-1-00/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
        Type publishTrigger : myTriggerChannel "Receive everything" [ stateTopic="tasmota/#", separator="#" ]

without the Thing line, i get channels shown in Visual studio in the Thing list.

if i go like this, which should be correct according to the documentation from what i can see, it doesnt show any channels :

Bridge mqtt:broker:myAuthentificatedBroker "MyBroker" @ "MyHome" [ host="", secure=false, username="openhabian", password="xxxxxx", qos=1] {
Thing mqtt:topic:SonoffBasic01 "Sonoff Power Switch 01" @ "MQTT"  {
        Type string : reachable "Reachable"            [ stateTopic="tasmota/tele/sonoff-basic-1-00/LWT" ]
        Type switch : power     "Power"                [ stateTopic="tasmota/stat/sonoff-basic-1-00/POWER", commandTopic="tasmota/cmnd/sonoff-basic-1-00/POWER", on="ON", off="OFF" ]
        Type number : rssi      "WiFi Signal Strength" [ stateTopic="tasmota/tele/sonoff-basic-1-00/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
        Type publishTrigger : myTriggerChannel "Receive everything" [ stateTopic="tasmota/#", separator="#" ]

now the channels need to be correct, since a thing config like this :

Type publishTrigger : myTriggerChannel "Receive everything" [ stateTopic="tasmota/tele/sonoff-basic-1-00/POWER", separator="#" ]

results in that loggin

2019-03-30 15:37:37.621 [vent.ChannelTriggeredEvent] - mqtt:broker:myAuthentificatedBroker:reachable triggered Online

2019-03-30 15:37:43.861 [vent.ChannelTriggeredEvent] - mqtt:broker:myAuthentificatedBroker:power triggered ON

2019-03-30 15:37:56.665 [vent.ChannelTriggeredEvent] - mqtt:broker:myAuthentificatedBroker:power triggered OFF

2019-03-30 15:37:59.593 [vent.ChannelTriggeredEvent] - mqtt:broker:myAuthentificatedBroker:rssi triggered {"Time":"2019-03-30T15:38:00","Uptime":"0T00:05:20","Vcc":3.170,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":20,"POWER":"OFF","Wifi":{"AP":1,"SSId":"Elias W-LAN","BSSId":"A0:04:60:86:32:62","Channel":6,"RSSI":32,"LinkCount":1,"Downtime":"0T00:00:06"}}

the item file is like follows, but either way, does not really work

String Reachable "Reachable" {channel="mqtt:broker:myAuthentificatedBroker:reachable"}
Number Rssi "WiFi Signal Strength" {channel="mqtt:broker:myAuthentificatedBroker:rssi"}
Switch 		OnOff_Bath_Mirror_OG	"An/Aus (Bad Spiegel) OG"		<light_led>		/*(G_Lights_Bath,G_OnOff)*/		{channel="mqtt:broker:myAuthentificatedBroker:power"}

i have no clue what the problem is… does anyone see the mistake or know the reason why i cant have the thing line in the thing config file ?
Also i am not sure why the JASONPATH transformation is not working … i have the transformation jsonpath installed…


(WJ) #89

@schelli Marc, maybe I am not the best person to answer your question I’ve got it working with all the examples I found on this forum. for starters I use MQTT bridge in a separate thing file. This file contains no “{”; so think you can remove that in your bridge line. Not sure but the differences in your StateTopic might be problem.
Please note my solution works but might be not the most perfect solotion.

PS Still not found the SonOff icons, anyone?


Bridge mqtt:broker:MyMosquitto "MQTT Broker Mosquitto" @ "MQTT" 


Thing mqtt:topic:Sonoff1 "Sonoff 1" (mqtt:broker:MyMosquitto) @ "MQTT"  {
    Type switch : power          [ stateTopic="stat/Sonoff1/POWER",  commandTopic="cmnd/Sonoff1/Power"]
    Type string : fw             [ stateTopic="tele/Sonoff1/INFO1",  transformationPattern="JSONPATH:$.Version"]
    Type string : hostname       [ stateTopic="tele/Sonoff1/INFO2",  transformationPattern="JSONPATH:$.Hostname"]
    Type string : ip             [ stateTopic="tele/Sonoff1/INFO2",  transformationPattern="JSONPATH:$.IPAddress"]
    Type string : wifi-rssi      [ stateTopic="tele/Sonoff1/STATE",  transformationPattern="JSONPATH:$.Wifi.RSSI" ]
    Type switch : devicestate    [ stateTopic="tele/Sonoff1/LWT",    transformationPattern="" ]
} // end of thing


Switch Sonoff1_Switch          "Voordeur"            <selflight>    (Sonoffs) { channel="mqtt:topic:Sonoff1:power" }
String Sonoff1_hostname        "Sonoff1 hostname"                   (Sonoffs) { channel="mqtt:topic:Sonoff1:hostname" }
String Sonoff1_IP              "Sonoff1 IP"          <ip>           (Sonoffs) { channel="mqtt:topic:Sonoff1:ip" }
String Sonoff1_FW              "Sonoff1 FW"          <selfinfo>     (Sonoffs) { channel="mqtt:topic:Sonoff1:fw" }
String Sonoff1_WifiRssi        "Sonoff1 Wifi RSSI"   <network>      (Sonoffs) { channel="mqtt:topic:Sonoff1:wifi-rssi" }
Switch Sonoff1_DeviceState     "Sonoff1 Device State" <selfshield> (gReachable,Sonoffs) { channel="mqtt:topic:Sonoff1:devicestate" }

(Jürgen Baginski) #90

IMHO it is possible to add channels to the broker-thing ( which is a bridge), but those channels are of no use!
Did you copy the channel definition from your PaperUI? The channel definition show on PaperUI can be used in both cases, either if things are defined on PaperUI as well as in files.


(Marc) #91

Hmm, the problem was as so many times between my own ears :roll_eyes:

I was looking in the thing list under the MQTT Broker name for channels to appear. but ofc i had to look under the name of my MQTT topic thing in the thing list … incredibly stupid, but well, cost me 2 or 3 hours fiddling around, just a simple thinking mistake … thx for your help though.

@opus actually your note about being able to create those channels without effect, made me think about where the channels should be / appear…