Putting a Sonoff in your wall switch box

I was able to get a single sonoff to control a 3 way light (2 switches controlling 1 light). Basically what I did was put the sonoff in the box that had the wire that went up to the light, hooked up that light switch as a GPIO 14 input on the sonoff. Then I converted the tx pin (serial out) to GPIO1 with use of 4.7k resistor, and used the traveler wire running to the second switch as an input to GPIO 1. It works perfectly. I have pictures and a wiring diagram and I’ll try and post a nice write up on how I did this.

1 Like

This is my approach to get 3 sonoff in the wall. To mention is maybe that this will be the kitchen and I won’t see it as there will be a furniture in front of it


2 Likes

nicely done!

I found this nice single gang box on thingiverse:
https://www.thingiverse.com/thing:2830060

Here the finished version …

2 Likes

So here’s how I wired up a 3 way (US) 2 way (UK) light using a single sonoff.
It assumes that your 3 way light was setup in a specific way. The following things need to all be coming into one wall box

  • Power from breaker box
  • dedicated wire to light

additionally your traveler wire needs to do NOTHING but run between the two wall boxes

  • dedicated traveler wire to the second switch

Modifications to sonoff:

  • 2 conductor 26awg wire soldered onto GPIO 14 & ground pins
  • 4.7k resister connecting 3.3v to the TX pin, along with another 2 conductor 26awg wire with 1 conductor connected to TX (along with the leg of the resistor) and the other connector going to ground.

It’s very important that you verify that your wiring configuration is setup identically to this, or things will probably go up in smoke. An inductive voltage tester is pretty handy to help make these determinations.

So we are going to call Box1 the main box, with power in from breaker box, wiring up to light, and one end of the traveler wire.

Box 2 will be the wall box that has a switch and the other end of the traveler wire in it

Box1:

  • Connect the black & white wires from the breaker box to the input of your sonoff.
  • Connect the black & white wires going to the light to the output side of the sonoff.
  • Connect the switch to GPIO 14 & ground of the sonoff (I find that tinning about 2 inches of the end of the 26awg wire makes using the switch screw terminals, which were designed to accept 12-14awg solid wire much easier to use)
  • Using a couple of wirenuts connect the second pair of 26awg wire to the red & black wires of the traveler wire. Again, about 2 inches of twisted and tinned ends make wirenutting 26awg wire to 14/16 solid wire much easier.

Box2:
*Connect the red/black wires to the switch

Setup the sonoff

  • GPIO14 is set to “09 Switch1”
  • GPIO1 Serial Out is set to 10 “Switch2”

Now, make sure both switches are in the “off” position and turn on power at the breaker. Changing either switch from on to off or off to on will result in the light toggling state. Basically we set it up like we would a normal sonoff, then use the existing traveler wire, that previously carried the high voltage, into another low vlotage GPIO switch.

Here is a pretty basic diagram showing what I did, along with the modifications to the sonoff.

1 Like

Nice work! Two switches toggling the various GPIO pins. I like it! I’ve been using 10k resistors on my standard single switch installs in the wall box to prevent ghost switching. I’m no expert on the values used and just go by what others recommended. Should I use 10k or 4.7k? Shouldn’t I also use it on the GPIO 14 switch of this setup? I don’t get the ghost switching all the time but after I had an issue with a couple of them I threw in the GPIO14 10k pullup on all of mine now.

Is the sonoff basic really rated at 10amps for 110/120V users in USA? It looks to me since the input power is rated from 90V to 250 VAC and the maximum power is rated for 2200W, ITEAD chose 10 amps max. I assume 10 amps was based on 220/250VAC users. For 110V it should be more like 18 amps or so. Correct or I am just going haywire?

I’m not sure about the difference between 4.7k and 10k. It’s been a long time since my circuit design and analysis classes. But I do remember we always used 4.7k as pull-up/pulldown resistors, and since I had a ton of them hanging around, that’s what I used.

From my understanding, GPIO 14 already has an internal pull-up resistor attached to it, so you do not need to add another one. I never add one to GPIO 14 and have yet to have any issues.

Yep, that’s what I’d read :+1:

It does look like people have used a 4.7 to 10k with success, some even had to go further with additional filters. I’ve had mixed success myself along with others and read about GPIO 14 having a configurable pullup.

Another way to do it using the single GPIO 14 pins with the 2 switches. Cool idea…ff’wd to about 4:45 or so if the link doesn’t take you to the time.

Very cool method, wonder why I never ran across that video. I spent a good amount of time searching for how to setup my 3 way switches with a single sonoff.

The other thing I did was I modified a dimmer switch to work along with the sonoff. I had just spent a ton of $ over the last few years converting all my old incandescent dimmers to led compatible dimmers. I wasn’t about to spend a ton more $ converting them again to smart dimmers, so I came up with using the switch part of the dimmer to turn the sonoff on and off, then route the output power from the sonoff through the dimmer circuitry. So now, while I can turn the lights on or off from the physical switch, or home assist, I still have to manually dim them.

It’s on my list of things to do to write up how I hooked up the dimmer with the sonoff.

Now if only someone made a Esp8266 based LED dimmer. Cheap WiFi flashable LED dimmer. I would be all over that.

1 Like

Ok, I’m going to resurrect an old thread…

I think this has been asked, but it seems like most answers are still for a 3 way switch. How about a 4 way switch? Below is a picture of the wiring in my wall. I have 3 total switches controlling 3 lights (1 switch at the bottom of the stairs, and 2 switches upstairs at different ends of the hallway). From what I’ve read it seems the only way to do this would be to do the same process DrZzs did with a sonoff in each switch box, and disconnecting the red traveler wire. My only concern with this is if hassio is offline then the switches aren’t going to work as they should. Any other thoughts on wiring this scenario?

I thought maybe I could put a sonoff in the light switch (far left switch in picture below) that has the 3 wire cable coming from the 4 way switch, and the 2 wire cable going to the lights, but I dont know what I would do with the remaining red wire assuming GPIO14 and Ground go to the 2 legs of the switch like you would normally wire any other switch. Would connecting it this way and leaving the Red traveler wire work?

Thank you in advance!!

Is that exactly how it is in your wall?
The trick is, do you have the “power in” and the “to lights” wires in the same box? If you do, you can use just one Sonoff like I did in the MakerFaire display: https://youtu.be/EroQ_Eos1HY

The problem with putting the sonoff in the far left box and powering it from the wires from the other switches, is that when one of those switches gets turned off, it will turn off the sonoff too.

In that scenario you are just inserting the gpio14/gnd wires into the multiswitch setup. But that’ll only work if you have power-in and lights-out in the same box. The only other way I can think of to do it with just one Sonoff would be to put the sonoff in the box that has the “to lights” wires and then power the sonoff from another circuit in that box (if there is one that has capacity). You’d have to be pretty sure about what that new circuit is powering so you don’t create a potential overload.

Realistically, if you have the exact situation as that diagram you probably can’t do it with just one sonoff.

I’m trying to get into the habit of doing live streams on Sundays. I may get a chance later today if I get out of work (at my real job) before too late. If you are free and can join in, this would be a good topic to discuss. And it might be easier to explain in that format.
If not tonight then some other sunday. Or find me on Discord sometime and we can have a chat.

Hope that helps!

Helps a ton!

I guess I was kind of just trying to figure out a way, that if hassio is down the WAF will still be high since it will work as intended. I think for now I may just leave it as is (dumb), but yeah that pic is exactly what I have, no power AND lights in the same box :frowning:

thanks as always DrZzs!!

there might be a way to have the Tasmota devices communicate directly with each other. I think your wifi would still need to be available. Not sure exactly, but I kinda remember reading there was some way to do that.

I know there is “group topic” so you can send the “on” command to one topic and all the switches will respond, but that means your MQTT broker would still need to be functional. It wouldn’t rely at all on the automation though, so that’s one less possible point of failure.

Good luck with it!

That could be another option, except my mqtt server is also running on the same pi… ha oh well, the stair lights dont need automated for now. Maybe they will be one of the ones that get an ecobee or something similar, I’m sure there’s a solution out there. For now I will just automate the master bedroom closet light to turn off when someone forgets… ha

1 Like

I have created a 3D Print design for a Decora Switch Body that accepts a Sonoff Basic.

The SonDek, a Sonoff Powered Decora Light Switch by TekMason - Thingiverse

If you find it useful shoot me a like.

1 Like