Using Sonoff Power Switches with Tasmota firmware and openHAB2 MQTT2 binding

Tags: #<Tag:0x00007f2fb585ce60> #<Tag:0x00007f2fb585ccd0> #<Tag:0x00007f2fb585cb90>

These are just warnings, associated with those of your Items that have been linked to two channels. You can ignore these warnings, they are removed in later openHAB versions.

That looks like a real problem. Simplify to just one sonoff, don’t add any more until you have one working. Be careful of the type of quotemarks " you use in this file.

  1. Yes i can

  2. Yes

  3. The files are readable. The paste did this.

  4. i try it today.

  5. if i ignores error, i didnt wrote here :smiley:

  6. i will check after test today.

by the way. i copied the things and items of the first thread here.

@rossko57
ok i will check the quotemarks today.

Thanks

If you want to stick to the one file version remove the “:” in the channel definition! Here is the syntax of my working file:

Bridge mqtt:broker:opusMQTT [ host="192.168.178.50", secure=false, username="UserName", password="IWillNotTellYou" , clientID="opusMQTTClient" ]
{
  Thing topic sonoff_1_Thing "Light_1" @ "Sonoff" {  
    Channels:
        Type switch : PowerSwitch  [ stateTopic="stat/sonoff_1/POWER" , commandTopic="cmnd/sonoff_1/POWER", on="ON", off="OFF" ]
        Type string : Version [stateTopic="stat/sonoff_1/STATUS2", transformationPattern="JSONPATH:$.StatusFWR.Version"]
      }   
}

The mqtt state of the above Sonoff is “sonoff_1” with the FullTopic left with the default “%prefix%/%topic%/”!

For readability, please format the posted content as “Preformatted Text” (the “</>” Icon!).

In best Case i want more files.

  • mqtt.things
  • sonoff-buero.things
  • sonoff-livingroom.things

but if i cut them in own files, they dont visible in paper ui. i dont know why.
in the future i have more than 1-2 items per room. with one file it is very unusable for me.

check your log when saving file, it will show you an error for sure, thats why they are not shown in basicUI

I do have several files with things,items etc and all is working just fine, you have to be carefull on double definitions and syntax

The syntax I showed and use is for using a single file, if the broker is in a separated file, the syntax is different. See some posts above.
In any case, using the correct syntax the so created things do show in PaperUI, but they are not changeable by PaperUI!
@kriznik: Things are never shown on BasicUI!

i haven’t say they do…

For now i get infos in log of the first device.

mqtt.things and other things are cutted. I cant switch, cause i dont know, how to write the switch. at the moment iam a little bit confused. i tried to use the switch, but it dont work.

mqtt.things

Bridge mqtt:broker:MqttBroker “MQTT Broker” @ “MQTT” [
host="",
secure=false,
port=1883,
qos=0,
retain=false,
clientid=“Oh2Mqtt2Thing”,
keep_alive_time=30000,
reconnect_time=60000,
username="",
password=""
]

buero.things

//=================================================================================================================================================
Thing mqtt:topic:sonoffcorin1 “Strom Corin 1” (mqtt:broker:MqttBroker) @ “Büro” {
Channels:
Type switch : power [ stateTopic=“buero/sonoffcorin1/POWER”, commandTopic=“buero/sonoffcorin1/Power”]
Type string : fw [ stateTopic=“buero/sonoffcorin1/INFO1”, transformationPattern=“JSONPATH:$.Version”]
Type string : hostname [ stateTopic=“buero/sonoffcorin1/INFO2”, transformationPattern=“JSONPATH:$.Hostname”]
Type string : ip [ stateTopic=“buero/sonoffcorin1/INFO2”, transformationPattern=“JSONPATH:$.IPAddress”]
Type string : wifi-rssi [ stateTopic=“buero/sonoffcorin1/STATE”, transformationPattern=“JSONPATH:$.Wifi.RSSI” ]
Type switch : devicestate [ stateTopic=“buero/sonoffcorin1/LWT”, transformationPattern=“MAP:reachable.map” ]
} // end of thing
//=================================================================================================================================================

buero.items

//=================================================================================================================================================
Switch sonoffcorin1_Switch “sonoffcorin1 Power” (Sonoffs) { channel=“mqtt:topic:sonoffcorin1:power” }
String sonoffcorin1_hostname “sonoffcorin1 hostname” (Sonoffs) { channel=“mqtt:topic:sonoffcorin1:hostname” }
String sonoffcorin1_IP “sonoffcorin1 IP” (Sonoffs) { channel=“mqtt:topic:sonoffcorin1:ip” }
String sonoffcorin1_FW “sonoffcorin1 FW” (Sonoffs) { channel=“mqtt:topic:sonoffcorin1:fw” }
String sonoffcorin1_WifiRssi “sonoffcorin1 Wifi RSSI” (Sonoffs) { channel=“mqtt:topic:sonoffcorin1:wifi-rssi” }
Switch sonoffcorin1_DeviceState “sonoffcorin1 Device State” (gReachable,Sonoffs) { channel=“mqtt:topic:sonoffcorin1:devicestate” }
//=================================================================================================================================================

To switch this item click on power of your last picture (so located at “paper UI - control - etc”)
resulting in log entries like:

2019-07-14 21:40:50.731 [ome.event.ItemCommandEvent] - Item 'Sonoff2_Switch' received command ON
2019-07-14 21:40:50.748 [nt.ItemStatePredictedEvent] - Sonoff2_Switch predicted to become ON
2019-07-14 21:40:50.762 [vent.ItemStateChangedEvent] - Sonoff2_Switch changed from OFF to ON

Because your details shows firmware and RSSI you will see the light. But…
If not working please check the syntac of thing channel “power”.
This line might be incorrect using Tasmota.

I click, and it do nothing.

Would you show us your event.log please. You might also look in openhab.log for any messages at this time.

I note that your command topic looks wrong

Event.log if i click in paper ui

2019-07-15 19:24:16.555 [ome.event.ItemCommandEvent] - Item ‘sonoffcorin1_Switch’ received command OFF
2019-07-15 19:24:16.556 [nt.ItemStatePredictedEvent] - sonoffcorin1_Switch predicted to become OFF
2019-07-15 19:24:16.557 [vent.ItemStateChangedEvent] - sonoffcorin1_Switch changed from ON to OFF
2019-07-15 19:24:16.936 [ome.event.ItemCommandEvent] - Item ‘sonoffcorin1_Switch’ received command ON
2019-07-15 19:24:16.937 [nt.ItemStatePredictedEvent] - sonoffcorin1_Switch predicted to become ON
2019-07-15 19:24:16.937 [vent.ItemStateChangedEvent] - sonoffcorin1_Switch changed from OFF to ON
2019-07-15 19:24:17.336 [ome.event.ItemCommandEvent] - Item ‘sonoffcorin1_Switch’ received command OFF
2019-07-15 19:24:17.337 [nt.ItemStatePredictedEvent] - sonoffcorin1_Switch predicted to become OFF
2019-07-15 19:24:17.338 [vent.ItemStateChangedEvent] - sonoffcorin1_Switch changed from ON to OFF
2019-07-15 19:24:17.705 [ome.event.ItemCommandEvent] - Item ‘sonoffcorin1_Switch’ received command ON
2019-07-15 19:24:17.706 [nt.ItemStatePredictedEvent] - sonoffcorin1_Switch predicted to become ON
2019-07-15 19:24:17.706 [vent.ItemStateChangedEvent] - sonoffcorin1_Switch changed from OFF to ON

meanwhile the switch
“nothing”

if i click on the webgui of the switch directly

18:27:17 MQT: buero/sonoffcorin1/RESULT = {“POWER”:“OFF”}
18:27:17 MQT: buero/sonoffcorin1/POWER = OFF
18:27:19 MQT: buero/sonoffcorin1/RESULT = {“POWER”:“ON”}
18:27:19 MQT: buero/sonoffcorin1/POWER = ON

So, did you have a close look at your command topic? These are case sensitive.

i try something… nothing works…

now i tried the template of tasmota wiki, all pastes of this thread. nothing work.

no errors in openhab.log

2019-07-15 20:32:13.881 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘buero.things’
2019-07-15 20:32:14.887 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘buero.things’
2019-07-15 20:33:12.440 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘buero.things’
2019-07-15 20:34:13.523 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘buero.things’
2019-07-15 20:34:38.517 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘buero.things’
2019-07-15 20:36:42.519 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘buero.items’
2019-07-15 20:37:56.015 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘buero.items’
2019-07-15 20:39:11.024 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘buero.things’
2019-07-15 20:41:17.014 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘buero.things’
2019-07-15 20:42:14.516 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘buero.things’
2019-07-15 20:44:41.011 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘buero.things’
2019-07-15 20:47:32.514 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘buero.things’
2019-07-15 20:48:17.508 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘buero.things’

switch didnt react

2019-07-15 20:41:21.730 [vent.ItemStateChangedEvent] - sonoffcorin1_Switch changed from ON to OFF

2019-07-15 20:41:22.034 [ome.event.ItemCommandEvent] - Item ‘sonoffcorin1_Switch’ received command ON

2019-07-15 20:41:22.035 [nt.ItemStatePredictedEvent] - sonoffcorin1_Switch predicted to become ON

2019-07-15 20:41:22.035 [vent.ItemStateChangedEvent] - sonoffcorin1_Switch changed from OFF to ON

2019-07-15 20:41:22.360 [ome.event.ItemCommandEvent] - Item ‘sonoffcorin1_Switch’ received command OFF

2019-07-15 20:41:22.361 [nt.ItemStatePredictedEvent] - sonoffcorin1_Switch predicted to become OFF

2019-07-15 20:41:22.362 [vent.ItemStateChangedEvent] - sonoffcorin1_Switch changed from ON to OFF

2019-07-15 20:41:22.669 [ome.event.ItemCommandEvent] - Item ‘sonoffcorin1_Switch’ received command ON

2019-07-15 20:41:22.672 [nt.ItemStatePredictedEvent] - sonoffcorin1_Switch predicted to become ON

2019-07-15 20:41:22.673 [vent.ItemStateChangedEvent] - sonoffcorin1_Switch changed from OFF to ON

2019-07-15 20:41:23.025 [ome.event.ItemCommandEvent] - Item ‘sonoffcorin1_Switch’ received command OFF

2019-07-15 20:41:23.027 [nt.ItemStatePredictedEvent] - sonoffcorin1_Switch predicted to become OFF

2019-07-15 20:41:23.027 [vent.ItemStateChangedEvent] - sonoffcorin1_Switch changed from ON to OFF

2019-07-15 20:41:23.361 [ome.event.ItemCommandEvent] - Item ‘sonoffcorin1_Switch’ received command ON

2019-07-15 20:41:23.362 [nt.ItemStatePredictedEvent] - sonoffcorin1_Switch predicted to become ON

2019-07-15 20:41:23.363 [vent.ItemStateChangedEvent] - sonoffcorin1_Switch changed from OFF to ON

2019-07-15 20:42:20.037 [ome.event.ItemCommandEvent] - Item ‘sonoffcorin1_Switch’ received command OFF

2019-07-15 20:42:20.041 [nt.ItemStatePredictedEvent] - sonoffcorin1_Switch predicted to become OFF

2019-07-15 20:42:20.041 [vent.ItemStateChangedEvent] - sonoffcorin1_Switch changed from ON to OFF

2019-07-15 20:42:20.666 [ome.event.ItemCommandEvent] - Item ‘sonoffcorin1_Switch’ received command ON

2019-07-15 20:42:20.667 [nt.ItemStatePredictedEvent] - sonoffcorin1_Switch predicted to become ON

2019-07-15 20:42:20.668 [vent.ItemStateChangedEvent] - sonoffcorin1_Switch changed from OFF to ON

2019-07-15 20:42:21.131 [ome.event.ItemCommandEvent] - Item ‘sonoffcorin1_Switch’ received command OFF

2019-07-15 20:42:21.131 [nt.ItemStatePredictedEvent] - sonoffcorin1_Switch predicted to become OFF

2019-07-15 20:42:21.136 [vent.ItemStateChangedEvent] - sonoffcorin1_Switch changed from ON to OFF

2019-07-15 20:42:21.615 [ome.event.ItemCommandEvent] - Item ‘sonoffcorin1_Switch’ received command ON

2019-07-15 20:42:21.616 [nt.ItemStatePredictedEvent] - sonoffcorin1_Switch predicted to become ON

2019-07-15 20:42:21.618 [vent.ItemStateChangedEvent] - sonoffcorin1_Switch changed from OFF to ON

2019-07-15 20:42:22.040 [ome.event.ItemCommandEvent] - Item ‘sonoffcorin1_Switch’ received command OFF

2019-07-15 20:42:22.041 [nt.ItemStatePredictedEvent] - sonoffcorin1_Switch predicted to become OFF

2019-07-15 20:42:22.042 [vent.ItemStateChangedEvent] - sonoffcorin1_Switch changed from ON to OFF

2019-07-15 20:42:22.494 [ome.event.ItemCommandEvent] - Item ‘sonoffcorin1_Switch’ received command ON

2019-07-15 20:42:22.496 [nt.ItemStatePredictedEvent] - sonoffcorin1_Switch predicted to become ON

no more ideas…

you have to look to your mqtt broker if OH broadcasting commands and if yes to which topics, if no there is a problem with binding tho

if you are using default sonoff tasmota configuration it should be something like

    stateTopic="stat/sonoff/POWER"
    commandTopic="cmnd/sonoff/POWER"

and for telemetry it is

    stateTopic="tele/sonoff/STATE"
    stateTopic="tele/sonoff/LWT"

If you would show us your actually used thing config ruin AND the mqtt setup of your son off device (topic and full topic setting).
The problem is caused in the conjunction of those.

Well, you will have to show us how your thing channel has ended up after all that work

The way it started out was wrong
Type switch : power [ stateTopic=“buero/sonoffcorin1/POWER”, commandTopic=“buero/sonoffcorin1/Power”]

Power is not the same as POWER

None of the examples that you have been copying have the same stateTopic and commandTopic, for example

Type switch : switch "Power Switch" [
stateTopic="wohnzimmer/MediaCenter/POWER",
commandTopic="wohnzimmer/MediaCenter/cmnd/POWER",
on="ON",
off="OFF"
]

Look closely for cmnd

Switch Topic:
buero/sonoffcorin1

Type switch : switch “Power Switch” [ stateTopic=“buero/sonoffcorin1/POWER”, commandTopic=“buero/sonoffcorin1/POWER”, on=“ON”, off=“OFF” ] - dont work

Type switch : switch “Power Switch” [ stateTopic=“buero/sonoffcorin1/POWER”, commandTopic=“buero/sonoffcorin1/POWER”, on=“1”, off=“0” ] - dont work

Type switch : switch “Power Switch” [ stateTopic=“buero/sonoffcorin1/power”, commandTopic=“buero/sonoffcorin1/power”, on=“ON”, off=“OFF” ] - dont work

Type switch : switch “Power Switch” [ stateTopic=“stat/buero/sonoffcorin1/POWER”, commandTopic=“cmnd/buero/sonoffcorin1/POWER”, on=“ON”, off=“OFF” ] - dont work

Type switch : switch “Power Switch” [ stateTopic=“stat/buero/sonoffcorin1/power”, commandTopic=“cmnd/buero/sonoffcorin1/power”, on=“ON”, off=“OFF” ] - dont work

Type switch : switch “Power Switch” [ stateTopic=“stat/buero/sonoffcorin1/POWER”, commandTopic=“cmnd/buero/sonoffcorin1/POWER”, on=“1”, off=“0” ] - dont work

item

Switch sonoffcorin1_Switch “sonoffcorin1 Power” (Sonoffs) { channel=“mqtt:topic:sonoffcorin1:power” }

Switch sonoffcorin1_Switch “sonoffcorin1 Power” (Sonoffs) { channel=“mqtt:topic:sonoffcorin1:POWER” }

Switch sonoffcorin1_Switch “sonoffcorin1 Power” (Sonoffs) { channel=“mqtt:buero:sonoffcorin1:power” }

all are in the event log.

i tested all things with all switches yesterday.

Did you consider using an extermnal MQTT-Viewer (like MQTTfx) IOT to see what Messages are really sent by openHAB and the sonoff device?

please paste here your mqtt mosquito_sub output for given topic so we can see what actually your sonoff is subscribed to