Using Sonoff Power Switches with Tasmota firmware and openHAB2 MQTT2 binding

mqtt
mqtt-binding
mqttsonoff
Tags: #<Tag:0x00007f51efcea660> #<Tag:0x00007f51efcea408> #<Tag:0x00007f51efcea188>

(Scott Karns) #68

Look in your docker host’s directory that is provided as your openHAB container’s userdata volume:

[openhab@casabot oh]$ find openhab_userdata/config/ -name 'addons*'
openhab_userdata/config/org/openhab/addons.config

On my test system, that directory is /home/openhab/oh/openhab_userdata:

[openhab@casabot oh]$ cat start-oh                                                                                                                                                                                                                                                                                                                                                           
#!/bin/bash
                                                                                                                                                                                                                                                                                                                                                                                             
docker run \
    --name openhab \
    --tty=true \
    --net=host \
    --device=/dev/ttyACM0 \
    -v /etc/localtime:/etc/localtime:ro \
    -v /home/openhab/oh/timezone:/etc/timezone:ro \
    -v /home/openhab/oh/openhab_addons:/openhab/addons \
    -v /home/openhab/oh/openhab_conf:/openhab/conf \
    -v /home/openhab/oh/openhab_userdata:/openhab/userdata \
    --env="EXTRA_JAVA_OPTS=-Duser.timezone=America/Denver\ -Dgnu.io.rxtx.SerialPorts=/dev/ttyACM0\ -Xbootclasspath/a:/openhab/conf/automation/jython/jython-standalone-2.7.0.jar -Dpython.home=/openhab/conf/automation/jython -Dpython.path=/openhab/conf/automation/lib/python" \
    --env="OPENHAB_HTTP_PORT=8080" \
    --env="OPENHAB_HTTPS_PORT=8443" \
    --env="USER_ID=1000" \
    --env="GROUP_ID=1000" \
    -d \
    --restart=always \
    openhab/openhab:2.5.0-snapshot-amd64-debian

(J Wee) #69

I dont have a addons.config, but I do see a profile.config. Are this/these the offending lines? The one that has ‘mqtt’?

feature.esh-io-transport-coap/0.11.0.SNAPSHOT=“esh-io-transport-coap/0.11.0.SNAPSHOT”
feature.esh-io-transport-dbus/0.11.0.SNAPSHOT=“esh-io-transport-dbus/0.11.0.SNAPSHOT”
feature.esh-io-transport-http/0.11.0.SNAPSHOT=“esh-io-transport-http/0.11.0.SNAPSHOT”
feature.esh-io-transport-mdns/0.11.0.SNAPSHOT=“esh-io-transport-mdns/0.11.0.SNAPSHOT”
feature.esh-io-transport-mqtt/0.11.0.SNAPSHOT=“esh-io-transport-mqtt/0.11.0.SNAPSHOT”

Because I also see this line, which I assume is the needful 2.5 snapshot mqtt binding

feature.openhab-transport-mqtt/2.5.0.SNAPSHOT=“openhab-transport-mqtt/2.5.0.SNAPSHOT”

So do I just remove all of the .11.0.SNAPSHOT lines?

Update. I found the addons.config file.

:org.apache.felix.configadmin.revision:=L"1"
action=",mqtt,nma"
binding=",mqtt1,network,http1,tplinksmarthome,ntp,mqtt"
legacy=B"false"
misc="restdocs,openhabcloud"
package="standard"
persistence="mapdb"
remote=B"true"
service.pid="org.openhab.addons"
transformation="jsonpath,map,javascript,exec"
ui="basic,paper,habpanel,homebuilder,classic,habmin"
voice="picotts"

Which part should I amend? or do I just delete the whole file?


(J Wee) #70

I removed the line - action
and also the mqtt1 binding. (still dunno how it got there)

This error is gone “[error] [core.karaf.internal.FeatureInstaller] - Failed installing 'openhab-action-nma, openhab-action-mqtt,openhab-binding-mqtt1”

but this error remains on startup

2019-01-21 19:20:33.641 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule ‘Update Sonoff Status’: Instance is not an MQTTActions class.


(WJ) #71

Dear guys, @epicurean,

I am following this this topic and I am was also struggling with the same sort of problems, My MQTT connection (server=Mosquitto) is working perfectly from OH2 to my MQTT devices and back. Costed me some (read this as an understatement) effort due to the new set-up and my i.e. sloppy case-sensitive use.

I was also able to remove the recurring error of mqtt1 by deleting the file “/var/lib/openhab2/config/org/openhab/addons.config” (thanks to all/@opus for solving this part). However I still notice on startup the warning “[WARN ] [.MqttBrokerConnectionServiceInstance] - MqttBroker connection configuration faulty: host : You need to provide a hostname/IP!”. Though I do not want to use this broker I think I can solve this problem by configuring in the Paper UI - Configruaration - Services - MQTT MQTT system broker connection(org.eclipse.smarthome.mqttbroker)?

Getting the interaction (this topic) with my Sonoff’s was still on my to do list.

I found this article from @David_Graeff by accident and very helpfull. To get it working I used the “On system start” rule-example monitoring it with MQTTbox. It worked and realised what the problem was in the syntax to restart Sonoff devices. The syntac of @epicurean :

actionsBroker.publishMQTT("mosB", "cmnd/" + device_id + "/STATUS", "2")

is incorrect; the duplicity of the MQTT-broker needs to be removed.

actionsBroker.publishMQTT("cmnd/" + device_id + "/STATUS", "2")

Long story but it also indicates that moving to 2.4/2.5 was a bit of a burden for me in respect of the major MQTT changes. And yes RTFM can be helpful.

A last question i setup the MQTT-broker with a .thing file for both bridge as various things. Reason I find this more handy than the paper UI itself. Not, for sure, in respect of the proper syntax but easier to share/duplicate. The question: is there a way to extract the properties from a paper UI to a text file?
(if it is already there I did not find it yet in the rtFM.


(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.


(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

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

Item
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(GenericItemChannelLinkProvider.java:83) ~[?:?]

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

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

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

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

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

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

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

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

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

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

	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]

	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]

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

	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:?]

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

	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]

	at java.lang.Thread.run(Thread.java:748) [?:?]

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


(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: