3 way switch with sonoff

I was wondering if it might be possible to create a Virtual (for lack of a better word) 3 way switch? I have a hall that has 2 lights and 2 switches but for some reason they did not wire it as a 3 way. So i have 1 switch that controls 1 light and the other switch controls the other light. I am trying to do this on the cheap if possible along with not having to run more wire to make it a 3 way circuit. I wasnt sure if there would be a way to code 2 single switches to work as a 3 way. If it wouldnt work well with a sonoff and a normal rocker switch then I can break down and buy 2 wifi or zwave switches but I would really like to accomplish this with 2 sonoff’s if possible.


1 Like

I don’t have a sonoff, but they are based off the ESP8266 which I use a lot for my own custom switches and you can do this if you don’t mind a little hacking.

From what I’ve seen you should be able to solder a wire onto the sonoff and with probably a slight modification to the custom software that is available make it so the existing rocker switches are picked up by the sonoff as a digital input.

From there you just toggle the light state if the rocker switch is flipped and have homeassistant toggle the other light as well.

He put one in the box, but he is using a momentary switch. This just gives you an idea of what you need to do.

You can do it with 2 units. I use the Tasmota firmware that allows use of gpio14 as a switch interface and you can then tie the switch interface to a different mqtt topic than the main relay, so you use 1 unit as the power switching unit and the other as a signalling unit. both units then have the mqtt power payload as TOGGLE not ON or OFF, so all you are doing is switching the relay state from one to the other on some input, be that on or off, from the switch connected to gpio 14

You can do it with 1 unit and re-work the switched live wires as signalling etc but above is how i did it.

PS you need to look at using a small interface between the power (3.3v), common and gpio14 pins and the switch to enable reliable switching otherwise there is too much noise on the cables normally that causes the sonoff to flap between on and off, unless you want disco lights that is.

You’re after a two way not a three way. Three way is one light with three switches.

Are you hoping to join the two lights so they come on together or have two two way circuits?

Incorrect. He is referring to a 3-way switch configuration. a light (or set of lights) controlled by two switches is a 3-way switch configuration. His wiring is currently as he describes one switch per light which is a 2-way switch. What you mentioned (one light with three switches) is a 4-way switch configuration.

He’s on the right track with suggestions from people to use the Tasmota firmware on a sonoff. I’ve never done it but in theory it works wether you re-wire and use some wire as signaling, or run a secondary wire for control.

It’s you who’s incorrect, perhaps try using Google before replying next time…



I also have several Sonoffs running Tasmota using existing switches connected to the gpio.

And that is where UK Electrical Code and NEC (North American Electrical Code) differ. A 2-way configuration in the UK is the same as a 3-way configuration in North America electrically, but nomenclature is different. So really we are talking about the same thing. Also a 3-way configuration in the UK is the same as a 4-way configuration in North America electrically, again the nomenclature is different. And for the record, I didn’t need to use Google as my Dad is a Licensed Master Electrician in the US and I learned from him.

Because no one stated their location, people make assumptions. I made an assumption based on my location (North America, specifically the states) and you made an assumption based on your location (UK). Until the OP states their location, we are both wrong (or correct depending on your point of view).

Regardless, the Tasmota firmware for the Sonoff and a little MQTT magic (maybe an additional control wire) will solve their issue.


Should’ve guessed given you lot have a record of not being able to spell and using the wrong words to describe things :slight_smile:

Yup I am sorry. I did not say where I am which is the USA. I too was an electrician. My problem is with the coding. :slight_smile: I do know that I can wire a switch on to the sonoff board i just dont know fully enough rhe configuration both on them and in HA. Radebe2k mentioned what sounded like a way to habe the input switch be on a different topic than the relay. If thats the case i believe i can figure out the code as where i could not get my head wrapped around was that to my knowledge when you activated the switch on the sonoff it would activate the relay even if it isnt communicating with the broker. If i can use the switch on the sonoffs it would be easy to write an automation to control the relays.

Watch this…

and this…

…and then let us know where your unclear.

Setting up the individual light switches is easy, as is the automation, it’s just the end result that’s clever and you don’t need to do anything else for that :slight_smile:

I have flashed my current sonoffs (for other lights) with tasmota and watched the bottom video last night prior to this post. Since I do not have any to play with currently (as my current ones are in use) I think im having an issue on GPIO14 and understanding how it works. The way it looks in the video is it essentially works the same as the push button on the board except you can set it to work with a normal rocker switch which when the switch is “turned on” GPIO 14 would be pulled HIGH to switch the relay on and LOW when its turn off. Now the question is does it actually still control the relay directly or is it strictly just a sensor that can be utilized in HA?

The reason I ask this is with a 3 way switch (2 switches and 1 light or any amount of lights tied together) setup the rockers will not always be in a matching up down position. Such as if both rockers are currently in the down (Normally off) position then I turn Rocker 1 to the up position to turn the light on but then use Rocker 2 to turn the light off Both switches will now be in the on/up position. If understand how the sonoff configuration is working correctly the lights will just stay on.

Now you can tell me I am digging to deep into this and that you can make it work the correct way with HA automations but I guess i would need to see an automation to understand how it would work. If GPIO 14 is strictly capable to be used as a Sensor in HA with no direct control of the relay I can figure out the automation easily but if it does control it directly like i suspect thats where i need the help understanding.

I hope this makes sense and you can follow. I promise i’m not trying to be difficult. :slight_smile:

Thanks for all the help in advance.

You’re overthinking it, take it at face value and it really is simple.

If you set the GPIO14 sensor to 09 Switch1 in the web ui, the state of the switch is triggered when there is a change in the state between GND and GPIO14 on the board, it doesn’t matter whether it is low to high or high to low, if the switch is on it will go off, if it’s off it will go on, in your terms the way up the switch is is irrelevant. The Sonoff broadcasts it’s state to MQTT so HA reflects that in the front end. This is why you can use a traditional switch connected to GPIO14 and GND on the Sonoff to toggle it rather than kill the power to the whole thing. You do that to your other light as well so you have to independent switches operating the same.

The magic happens when you then set up the automation in HA as I have explained before, you use the trigger of the state of one light changing to toggle the other and vice versa, simple as they come.

Then you’ll have what appears to be a normal two way circuit, using three way switches if you want to use the daft US naming convention, which can be controlled by either of the physical switches or any number of remote ways via HA and everything will stay perfectly in sync.

I have a little vero board that contains a 2 way screw terminal, a 3 way header, a 10k resistor and a 1uF cap, the cap goes between ground and gpio14 and the resistor goes between 3.3v and gpio14. Hopefully it’s needless to say that DO NOT CONNECT THIS TO 240\110VAC this is for signalling only, not power supply.

basically what this little doohickey does is filter out any noise inducted onto the old switch wires as a lot of the wall switch cabling will run in bunches next to other live lines, this will increase the noise on the signal going to GPIO14 and cause the unit to switch when you don’t want it to, trust me i’ve had the unintentional disco lights happening outside the front of my house all night before.


Haven’t had any problems with any of mine but I can see it could be an issue with longer cable runs to the switch eg Sonoff at the light fitting rather than by the switch.

Thanks for posting, very simple solution :+1:

Thanks Bobby_Nobble that makes sense now.

Hey Guys, I just tried this with a couple that i have and it works great. Thanks for the help on this.

More than welcome, glad to hear you’re all sorted :+1:

As I’m sure you found, it’s far easier to do than talk about which is why I think a lot of people get put off by the guides.

Yes i would agree with that.

I tried to get all the past reply together to get a conclusion but I’m new to this so I got a bit confused. I have I believe a 4-way switch ( 4 switches that control 5 lights in total on my hallway and stairs) I’m trying to figure out how to correctly wire the sonoff device followed by the correct setup on the software interface. Can someone help me out please. Thank you.

@Jaireco 4 way wiring is far more complex and can have many many different layouts inside the wall than any brief explanation in a forum could clarify. Using the Sonoff this way, I doubt that it would comply with any electrical codes so think about the consequences of a fire or ???