openHAB2 + Sonoff switch with Tasmota problem

Hi!

I install Mosquitto MQTT Server, openHAB2 on my Raspberry PI3. I use Homebridge, and it works well, but openHAB I have some issues.

I follow this openHAB2 install tutorial from 3. point.

echo 'deb http://dl.bintray.com/openhab/apt-repo2 testing main' | sudo tee /etc/apt/sources.list.d/openhab2.list
wget -qO - 'https://bintray.com/user/downloadSubjectPublicKey?username=openhab' | sudo apt-key add –
sudo apt-get update
sudo apt-get install openhab2-offline
sudo systemctl start openhab2.service
sudo systemctl status openhab2.service
sudo systemctl daemon-reload
sudo systemctl enable openhab2.service

Problems:

  • The switch works but not always, sometimes not doing anything (MQTT massage not send by openHAB) after a several switching it works again, and than not again…
  • Not showing the Wifi signal strength. (light1_wifi)
  • Not showing the Online or Offline state. (light1_on)

I used andrest wiki to my setup.

mqtt.cfg:

raspberrypi.url=tcp://localhost:1883
raspberrypi.clientId=DVES_%06X
raspberrypi.user=DVES_USER
raspberrypi.pwd=DVES_PASS

sonoff.items

Switch light1 "Nappali" <light> (LR,gLight)
    { mqtt=">[broker:cmnd/sonoff_1/power:command:*:default],
            <[broker:stat/sonoff_1/POWER:state:default]" }

// A switch being 'ON' as long as the device is reachable
Switch light1_on "Nappali elerheto" (gReachable)
    { mqtt="<[broker:tele/sonoff_1/LWT:state:MAP(reachable.map)]" }

// Wifi Signal Strength in Percent
Number light1_wifi "Nappali wifi [%d %%]" (gRSSI)
    { mqtt="<[broker:tele/sonoff_1/STATE:state:JSONPATH($.Wifi.RSSI)]" }

//A collection of return messages by the Sonoff module
String light1_mqtt "Nappali: [%s]"
    { mqtt="<[broker:tele/sonoff_1/INFO1:state:default],
            <[broker:stat/sonoff_1/STATUS2:state:default],
            <[broker:stat/sonoff_1/RESULT:state:default]" }

reachable.map

Online=ON
Offline=OFF

_default.sitemap

sitemap home label="Otthon"
{
Frame label="Lámpák2"
 {
   Switch item=light1
   Text item=light1_on
   Text item=light1_wifi
   Text item=light1_mqtt
 }

replace the “broker:” in sonoff.items with mqtt broker name, which is “raspberrypi:” in your case. Also ensure that mqtt topic matches with your client_id of your sonoff switch (sonoff_1 is the client id in sonoff configuration)

Hi manu74!

I did it, but nothing happen.

my events.log

2017-03-31 11:31:02.500 [ItemCommandEvent          ] - Item 'light2' received command ON
2017-03-31 11:31:02.512 [ItemStateChangedEvent     ] - light2 changed from OFF to ON
2017-03-31 11:31:14.712 [ItemCommandEvent          ] - Item 'light2' received command OFF
2017-03-31 11:31:14.725 [ItemStateChangedEvent     ] - light2 changed from ON to OFF
2017-03-31 11:31:52.546 [ItemCommandEvent          ] - Item 'light1' received command ON
2017-03-31 11:31:52.559 [ItemStateChangedEvent     ] - light1 changed from OFF to ON
2017-03-31 11:31:55.452 [ItemCommandEvent          ] - Item 'light2' received command ON
2017-03-31 11:31:55.464 [ItemStateChangedEvent     ] - light2 changed from OFF to ON
2017-03-31 11:32:00.727 [ItemCommandEvent          ] - Item 'light2' received command OFF
2017-03-31 11:32:00.739 [ItemStateChangedEvent     ] - light2 changed from ON to OFF
2017-03-31 11:32:02.376 [ItemCommandEvent          ] - Item 'light1' received command OFF
2017-03-31 11:32:02.392 [ItemStateChangedEvent     ] - light1 changed from ON to OFF
2017-03-31 11:33:15.843 [ItemCommandEvent          ] - Item 'light2' received command ON
2017-03-31 11:33:15.869 [ItemStateChangedEvent     ] - light2 changed from OFF to ON
2017-03-31 11:33:19.484 [ItemCommandEvent          ] - Item 'light1' received command ON
2017-03-31 11:33:19.497 [ItemStateChangedEvent     ] - light1 changed from OFF to ON

my openhab.log

2017-03-31 11:31:00.148 [WARN ] [sitemap.internal.SitemapProviderImpl] - Filename `_default.sitemap` does not match the name `home` of the sitemap - please fix this as you might see unexpected behavior otherwise.
2017-03-31 11:31:00.747 [WARN ] [sitemap.internal.SitemapProviderImpl] - Filename `_default.sitemap` does not match the name `home` of the sitemap - please fix this as you might see unexpected behavior otherwise.
2017-03-31 11:31:46.443 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'sonoff.items'
2017-03-31 11:31:46.479 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH
2017-03-31 11:31:46.481 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH
2017-03-31 11:31:46.484 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH
2017-03-31 11:31:46.487 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type MAP
2017-03-31 11:31:46.490 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH
2017-03-31 11:31:46.504 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'sonoff.items'
2017-03-31 11:31:46.533 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH
2017-03-31 11:31:46.535 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH
2017-03-31 11:31:46.537 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH
2017-03-31 11:31:46.539 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type MAP
2017-03-31 11:31:46.541 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH
2017-03-31 11:31:49.936 [WARN ] [sitemap.internal.SitemapProviderImpl] - Filename `_default.sitemap` does not match the name `home` of the sitemap - please fix this as you might see unexpected behavior otherwise.
2017-03-31 11:31:50.471 [WARN ] [sitemap.internal.SitemapProviderImpl] - Filename `_default.sitemap` does not match the name `home` of the sitemap - please fix this as you might see unexpected behavior otherwise.
2017-03-31 11:33:10.848 [WARN ] [sitemap.internal.SitemapProviderImpl] - Filename `_default.sitemap` does not match the name `home` of the sitemap - please fix this as you might see unexpected behavior otherwise.
2017-03-31 11:33:11.327 [WARN ] [sitemap.internal.SitemapProviderImpl] - Filename `_default.sitemap` does not match the name `home` of the sitemap - please fix this as you might see unexpected behavior otherwise.
2017-03-31 11:33:13.122 [WARN ] [sitemap.internal.SitemapProviderImpl] - Filename `_default.sitemap` does not match the name `home` of the sitemap - please fix this as you might see unexpected behavior otherwise.
2017-03-31 11:33:13.601 [WARN ] [sitemap.internal.SitemapProviderImpl] - Filename `_default.sitemap` does not match the name `home` of the sitemap - please fix this as you might see unexpected behavior otherwise.

my mosquitto.log

1490944273: New connection from 192.168.0.50 on port 1883.
1490944273: New client connected from 192.168.0.50 as DVES_96F37E (c1, k15, u'DVES_USER').
1490945033: Client DVES_96F37E has exceeded timeout, disconnecting.
1490945033: Socket error on client DVES_96F37E, disconnecting.
1490945034: New connection from 192.168.0.50 on port 1883.
1490945034: New client connected from 192.168.0.50 as DVES_96F37E (c1, k15, u'DVES_USER').
1490945106: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1490945904: Client DVES_96F37E has exceeded timeout, disconnecting.
1490945904: Socket error on client DVES_96F37E, disconnecting.
1490945906: New connection from 192.168.0.50 on port 1883.
1490945921: New client connected from 192.168.0.50 as DVES_96F37E (c1, k15, u'DVES_USER').
1490945949: Client DVES_96F37E has exceeded timeout, disconnecting.
1490945949: Socket error on client DVES_96F37E, disconnecting.
1490945961: New connection from 192.168.0.50 on port 1883.
1490945961: New client connected from 192.168.0.50 as DVES_96F37E (c1, k15, u'DVES_USER').

my sonoff swich (sonoff_1) log:

11:25:01 MQTT: tele/sonoff_1/STATE = {"Time":"2017-03-31T11:25:01", "Uptime":3, "Vcc":3.152, "POWER":"OFF", "Wifi":{"AP":1, "SSID":"Sziszi WIFI", "RSSI":68}}
11:30:03 MQTT: tele/sonoff_1/STATE = {"Time":"2017-03-31T11:30:03", "Uptime":3, "Vcc":3.153, "POWER":"OFF", "Wifi":{"AP":1, "SSID":"Sziszi WIFI", "RSSI":68}}
11:35:03 MQTT: tele/sonoff_1/STATE = {"Time":"2017-03-31T11:35:03", "Uptime":3, "Vcc":3.154, "POWER":"OFF", "Wifi":{"AP":1, "SSID":"Sziszi WIFI", "RSSI":68}}
11:40:03 MQTT: tele/sonoff_1/STATE = {"Time":"2017-03-31T11:40:03", "Uptime":3, "Vcc":3.153, "POWER":"OFF", "Wifi":{"AP":1, "SSID":"Sziszi WIFI", "RSSI":68}}

Hi!

I completly reinstall the whole Pi.
Modified the code:

mqtt.cfg:

raspberrypi.url=tcp://localhost:1883`

sonoff.items

Switch light1 "Nappali" <light> (LR,gLight)
    { mqtt=">[raspberrypi:cmnd/sonoff_1/power:command:*:default],
            <[raspberrypi:stat/sonoff_1/POWER:state:default]" }

// A switch being 'ON' as long as the device is reachable
Switch alive "Nappali elerheto" (gReachable)
{ mqtt="<[raspberrypi:tele/sonoff_1/LWT:state:MAP(reachable.map)]" }

// Wifi Signal Strength in Percent
Number wifi "Nappali wifi [%d %%]" (gRSSI)
{ mqtt="<[raspberrypi:tele/sonoff_1/STATE:state:JSONPATH($.Wifi.RSSI)]" }

//A collection of return messages by the Sonoff module
String mqtt "Nappali: [%s]"
{ mqtt="<[raspberrypi:tele/sonoff_1/INFO1:state:default],
        <[raspberrypi:stat/sonoff_1/STATUS2:state:default],
        <[raspberrypi:stat/sonoff_1/RESULT:state:default]" }

defeult.sitemap

sitemap home label="Otthon"
{
Frame label="Lámpák"
 {
   Switch item=light1
   Switch item=alive
   Text item=wifi
   Text item=mqtt
 }

Result:

  • Switch works fine!
  • Alive not working, not showing anything
  • Wifi signal not working, not showing anything
  • MQTT return messeges works fine!
1 Like

Everyithing works perfectly!

Missing addons: paperUI> Add-on> Transormations , install JSONPath Transformation and Map Transformation

2 Likes

good to hear that it worked.

Hi! Sonoff Tasmota 5.9.1, Openhab 2.1
my p16.items

Switch WorkSwitch (WorkRoom, Lights) {mqtt=">[dsBroker:cmnd/sonoff-07ABD4/POWER:command:*:default],<dsBroker:stat/sonoff-07ABD4/POWER:state:default]"}

It works wery well, but when I press the button on the sonoff device I have no actions on the openhab ui screen. Is it normal?

Hi,
is there any news on this topic?
I have the same issue. The switch works fine, but as my previous members says, there is now update in Basic UI when I press the button on sonoff device also no update on RSSI.

with MQTT FX I can verify that the states are sending:
{“Time”:“2018.04.30 20:21:57”,“Uptime”:“0 00:18:06”,“Vcc”:3.477,“POWER”:“ON”,“Wifi”:{“AP”:1,“SSId”:“FB-7590”,“RSSI”:70,“APMac”:“CC:CE:1E:AD:E7:71”}}

Items:

Switch Light1 "Light1" <light> (LR,gLight)
    { mqtt=">[mqtthome:cmnd/sonoff/POWER:command:*:default],
            <[matthome:stat/sonoff/POWER:state:default]" }
     
Number Light1_RSSI "Light1: RSSI [%d %%]" (gRSSI)
    { mqtt="<[mqtthome:tele/sonoff/STATE:state:JSONPATH($.Wifi.RSSI)]" }                               

Sitemap:

sitemap home label="Sitemap Label" {
    Frame label="Status"{
        Switch      item=Light1                   icon="light"
        Text        item=Light1_RSSI              icon="network"
    }
}

JSONPath Transformation, Map Transformation, MQTT Binding is installed.
Using:
openHAB 2.2.0 Release Build
RPI3 with Jessie

Two possibilities for the first one:
The broker name for input was wrong matthome instead of mqtthome
And add autoupdate="false" to the bindings

The JSONPATH in the Tasmota OpenHAB wiki is wrong:

Switch Light1 "Light1" <light> (LR,gLight) { mqtt=">[mqtthome:cmnd/sonoff/POWER:command:*:default], <[mqtthome:stat/sonoff/POWER:state:default]", autoupdate="false" }
Number Light1_RSSI "Light1: RSSI [%d %%]" (gRSSI)
    { mqtt="<[mqtthome:tele/sonoff/STATE:state:JSONPATH($.StatusSTS.Wifi.RSSI)]" } 

Also, is you browser autorefresh correctly set-up?

sorry for the typo in matt -> mqtt.
I have implemented the following code in Items:

Switch Light1 "Light1" <light> (LR,gLight) 
    { mqtt=">[mqtthome:cmnd/sonoff/POWER:command:*:default], 
            <[mqtthome:stat/sonoff/POWER:state:default]", autoupdate="false" }
            
Number Light1_RSSI "Light1: RSSI [%d %%]" (gRSSI)
    { mqtt="<[mqtthome:tele/sonoff/STATE:state:JSONPATH($.StatusSTS.Wifi.RSSI)]" } 

The switch works now and is updating. Thanks!

No changes on The RSSI is already “-” but I get an Error message:

2018-05-01 00:25:10.832 [ERROR] [.mqtt.internal.MqttMessageSubscriber] - Error processing MQTT message.
org.openhab.core.transform.TransformationException: Invalid path '$.StatusSTS.Wifi.RSSI' in '{"Time":"2018.04.30 23:25:10","Uptime":"0 00:06:35","Vcc":3.476,"POWER":"OFF","Wifi":{"AP":1,"SSId":"FB-7590","RSSI":72,"APMac":"CC:CE:1E:AD:E7:71"}}'

The browser autorefresh is not setupt jet. I use at the moment edge and crome and press the reload button. I expect that this is usually the same result?

Change the Light1_RSSI back to, Sorry I was ready some advanced docs and thought that might do the trick. I have checked the json payload that you get and the JSONPATH $.Wifi.RSSI should work… (You can check yourself in jsonpath.com, great little tool)

Number Light1_RSSI "Light1: RSSI [%d %%]" (gRSSI)
    { mqtt="<[mqtthome:tele/sonoff/STATE:state:JSONPATH($.Wifi.RSSI)]" } 

Thanks a lot! With above code the Sonoff works.

I highly recommend that you name your sonoff (Or at least change the topic in the sonoff configuration) so as not to get confused with the different devices (They get addictive) For example I have 7 for radiator valves and they are named: MasterBedroom_RadiatorValve, LargeBedroom_RadiatorValve, SmallBedroom_RadiatorValve, Kitchen_RadiatorValve… Closely matching my openhab naming
It makes things easier in the long run