Openhab and Sonoff Switch


(Francesco) #1

hi
i have a sonoff and i want to command it from openhab by rasberry pi.
This is the configuration of the sonoff:

mqtt.cfg:

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
 localbroker.url=tcp:the ip of the raspberry:1883
 # Optional. User id to authenticate with the broker.
 localbroker.user=openhabian
 # Optional. Password to authenticate with the broker.
 localbroker.pwd=the password

sonoff.items

Switch LivingRoom_Light "Interruttore WiFi Sonoff" <light> (LR,gLight)
 { mqtt=">[localbroker:cmnd/sonoffSERCAM/POWER:command:*:default],
 <[localbroker:stat/SONOFFsercam/POWER:state:default]" } 

sonoff.sitemap

sitemap sonoff label="Sonoff" {
 Frame label="Sonoff" {
 Switch item=LivingRoom_Light
 }
 }

I have the following add on:
MQTT Action
MQTT Binding 2,4
MQTT Persistence
JSONPath Transformation

The problem is that from openhab i am not able to control the sonoff.

Can you hlep me ?


(Jürgen Baginski) #2

Please read in Here.
You are doing the same mistake by using the syntax of the MQTT 1 binding while having the MQTT 2.4 binding installed.


(Francesco) #3

ok
i followed the topic and i changed the sonoff.item so:

Switch LivingRoom_Light "Interruttore WiFi Sonoff" <light> (LR,gLight)
 {channel="mqtt:topic:b7bb37dc:Power1"} 

but i continue to have problem to command by the bottom of openhab the sonoff.

I report the images of my openhan






(Francesco) #4

Now by MQTT.fx i am able to se the message that the switch of openhab send but the sonoff don’t change the status


(CM6.5 H102) #5

If using files try changing the item channel to:

Switch LivingRoom_Light "Interruttore WiFi Sonoff" <light> (LR,gLight)
 {channel="mqtt:topic:localbroker:b7bb37dc:power1"} 

You may need to post your Things file if the above doesn’t work.


(Francesco) #6

Thanks Now it work.
I want to command a sonoff dual but in this way i command only 1 exit.
Can you help me?


(Jürgen Baginski) #7

You have created a channel for Power1, do the same for Power2.


(Francesco) #8

I did bur it doesn’t work


(Jürgen Baginski) #9

These are the configs of my two switches of the Sonoff dual


(Francesco) #10

this is the result


when i push one also the other turn on but i setted the interlock.
I command the same


(Francesco) #11


(Francesco) #12


(Francesco) #13

this is my sonoff.items

Switch LivingRoom_Light "Interruttore WiFi Sonoff" <light> (LR,gLight)
 {channel="mqtt:topic:b7bb37dc:Power1"}

But i must create another file for the second switch?

The other problem is i can only turn off but not turn on


(Francesco) #14

can you show me your configuration please?


(Jürgen Baginski) #15

Sorry, but I do not understand. When pushing Power1 to On the second light switches to On also? What do you try to say by:" but i setted the interlock"?
You need another item for Power2, it can be setup in the same file as the other item(s).

Does the switch not toggle to OFF or does the sitemap icon stay in the ON position?

I did my item config by files, but the screencopy of PaperUI shows the result.
My items config for Power1 is basically the same as yours, I have a second one for Power2


(Jürgen Baginski) #16

BTW: You do not need the MQTT action and persistence binding.


(Francesco) #17

The cases are:
1)sonoff has the 1 switch to on. If i push on the switch in openhab it works (the switch go to off)

2)sonoff has the 1 switch to off. if i push on the switch in openhab the switch go first to on and then to off.


(Jürgen Baginski) #18

Could you post the log entries you are getting in the case 2.)


(Francesco) #19

now the sonoff.items:

Switch LivingRoom_Light "Interruttore WiFi Sonoff" <light> (LR,gLight)
 {channel="mqtt:topic:b7bb37dc:Power1"}


Switch LivingRoom_Light "Interruttore 2 WiFi Sonoff" <light> (LR,gLight)
 {channel="mqtt:topic:b7bb37dc:Power2"}

and in openhab






before to switch from openhab to on the log viewer is

after i switch to on the 1 and the 2 go to on


(Jürgen Baginski) #20

You have both items with the SAME name!
You have to have each item with an unique name!
Can’t say if that solves all the problems.

Please, when showing logs copy and paste only the needed lines!