Thinking of using OpenHAB but would like some advice first

Yes just not alexa driven though

Correct it is shown in the off state

Sorry @crumpy10
I am not very clear on what you are trying to achieve…

Yes, its a hard one to explain but easy to demonstrate.:confused:

OK, A normal 2 way lighting circuit has the ability to switch the light on and off at both switches.

The way I have used the Sonoff pro is as one of those light switches, for example in my office that has one normal light switch. Great so far.

The problem I have is that Alexa, knows if one of the relays is energised or not. So lets say its getting dark in my office and I lazily(as you do with home automation!) ask Alexa to turn the office lights on. Before she does anything the circuit is as shown above Off. She then turns the relay on and the lights come on, all good. I finish the day and hit the light on the way out the door, light turns off. Now the problem occurs tomorrow when I try and ask Alexa to turn the lights on again later in the day. She thinks they are still On, because the relay is still energised. So I have to ask her to turn them Off to get them On. The same situation you described above.

Does that make sense?

Do you think there is any way around this?

Thanks for your time and patience…


You need to find a way to tell OH that you turned off the light.
There are two wires going from your wall switch to your sonoff.
change the wiring.
Only the sonoff relay to drive the light
The two wires from your wall switch go to the GND and SDA on the sonoff headers
Configure the tasmota to feed bach the switch position to OH and toggle the relaly

Yeah thats my obstacle at the moment.

Thats one way of doing it but due to restrictions of wiring and also if the system is down I want anyone else to be able to use the normal light switch to turn lights on. I am trying to keep the wiring standard with the addition of a relay, that way the home automation can always be updated or removed if required.

Is this possible or is it going to be very slow or not work in my situation? Is there a way I could intercept the Alexa command to openhab and do this?

Sorry I am a real novice at this but trying to learn.



It will not work in your situation as OH has the relay ON and doesn’t know the light is OFF
You need two items:

Switch Relay { your tasmota binding }
Switch WallSwitch
Switch Light

And a rule:
Assuming the the light is ON when both switches and ON or OFF

rule "Light"
    Item Relay changed or
    Item WallSwitch changed
    if (Relay.state == WallSwitch.state) Light.postUpdate(ON)
    else Light.postUpdate(OFF)

But we come back to this
You NEED to feedback the switch position to OH

Yes I understand, its the reporting back that stumped me… But I have just had an idea that I will explore tomorrow (its late in NZ), what about connecting some type of CT coil to a GPIO to read back the ‘On or Off’ status to OH…



“Thats one way of doing it but due to restrictions of wiring and also if the system is down I want anyone else to be able to use the normal light switch.”
By having it worked like that the sonoff is doing it all, no openHAB MQTT or whatever is needed! You either switch the sonoff directly or using the other rewired switch you toggle a change.
I’m using a sonoff dual that way! While openHAB was down for maintenance the migth could be switched.

Hi Vincent,

OK, So I have been working on this over the last few weeks, on and off (sorry excuse the pun!)

What I now have is a standalone Arduino with CT sensors that detect when there is a load on the lighting circuits of the Sonoff 4 channel. I have also managed to get the Arduino to send a MQTT message that the circuit is either ON or OFF. Either when Alexa is used to operate the Sonoff or the conventional switch is used. Its sends the message because it detects the load.

So I now have a way of feeding back the state to OH!

But this is where I am a little stuck and showing my OH and programming lack of knowledge. I am trying to figure out how I log the fact that the light is physically off in the OH system. So that if someone then uses Alexa to switch the light back on, the system checks the state and turns it on.

Hope this makes sense.

Any pointers would be great.



Hello vzorglub,

Not sure if you have seen this post updated? I have managed to figure out a way of feeding back the info to Openhab, I am just a bit stuck on what I need to do next…

The code and rule you showed, I dont understand how the MQTT message I am sending back is used to update the switch?

Hope you can help, I think I am getting close to making this work. I just dont have enough Openhab experience…yet.


How did you do that and what is the item definition?

Thanks for your reply.

I have an arduino that has a CT coil sensor connected to it. When this arduino and coil sense a voltage on the live wire to the light it sends an MQTT message to Mosquito saying the light is ON, and the same when its turned OFF.


 //First 4 Channel Pro Sonoff for 2 way lighting
Switch Sonoff4ch_1Channel1 "Kitchen Lights" <light> (gLight) [ "Switchable" ] { mqtt=">[broker:cmnd/sonoff4chan_1/POWER1:command:*:default],<[broker:stat/sonoff4chan_1/POWER1:state:default]" }
Switch Sonoff4ch_1Channel2 "Family Lights" <light> (gLight) [ "Switchable" ] { mqtt=">[broker:cmnd/sonoff4chan_1/POWER2:command:*:default],<[broker:stat/sonoff4chan_1/POWER2:state:default]" }
Switch Sonoff4ch_1Channel3 "Dining Lights" <light> (gLight) [ "Switchable" ] { mqtt=">[broker:cmnd/sonoff4chan_1/POWER3:command:*:default],<[broker:stat/sonoff4chan_1/POWER3:state:default]" }
Switch Sonoff4ch_1Channel4 "Office Lights" <light> (gLight) [ "Switchable" ] { mqtt=">[broker:cmnd/sonoff4chan_1/POWER4:command:*:default],<[broker:stat/sonoff4chan_1/POWER4:state:default]" }

These are your sonoff items.
What message does the arduino send to mqtt?
Do you have an OH item for that?

Ah, this is the section of code in the arduino that sends the MQTT message-:

 if ((Irms >= 1) && !sonoff4ch1_On) {

    Serial.println("Light is ON");
    client.publish("stat/sonoff4ch1/", "Kitchen light is ON");
    sonoff4ch1_On = true; //Remember what state the light is
  else if ((Irms <= 1) && sonoff4ch1_On)
    Serial.println("Light is OFF");
    client.publish("stat/sonoff4ch1","Kitchen light is OFF");
    sonoff4ch1_On = false; //Remember what state the light is

But I dont understand how I make an item for openhab when its a message not an item?? Sorry I am very new to Openhab and not a programmer by trade…but very willing to learn.


And this is an arduino different than your sonoff, right?

Yes, its on a standalone Arduino Uno with an ethernet shield connected to the network. The CT coil is around the common wire to the light which senses the ON or OFF.

Ok, change the arduino code to:

if ((Irms >= 1) && !sonoff4ch1_On) {
    Serial.println("Light is ON");
    sonoff4ch1_On = true; //Remember what state the light is
  else if ((Irms <= 1) && sonoff4ch1_On)
    Serial.println("Light is OFF");
    sonoff4ch1_On = false; //Remember what state the light is

And change your items to:

Switch Sonoff4ch_1Channel1 "Kitchen Lights" <light> (gLight) [ "Switchable" ] { mqtt=">[broker:cmnd/sonoff4chan_1/POWER1:command:*:default],<[broker:arduino/channel1:state:default]" }

Thank you, I will have to do this when I get home tomorrow night. I am working remotely from home until then.

I will let you know how it goes.


OK I have made those changes and they work ok it seems.
The Arduino sends the messages to Mosquito, which I can see in MQTTfx.
I can also see the state change event in the Openhab log viewer.
It appears to update the basic UI after a page refresh.
Alexa does not see the state change though, she is still seeing the relay state in the Sonoff.

If Openhab is seeing the change of state of the light being physically on or off, how does Alexa not see the same?

There must be more I need to do? Do I somehow have to disable the state updates from the Sonoff? or did changing the broker in the items file do this?

Sorry for all the questions.