This is a follow up to “Using Sonoff as a Light Switch”

  1. Leave it connected. Go to your Router and find the new device with “sonoff” in the name. Get its IP address and put it in the browser. If everything worked you should see the control page for the sonoff.
  2. Under Configuration Change GPIO 14 to “09 Switch 1”. Then Save.
  3. If you’re using a rocker switch you’re done.  If you’re using a Push Button switch you need to go to the Console and type: “switchmode1 4” enter.  If you’re interested in all the available TASMOTA commands, here’s the link:
    1. https://github.com/arendst/Sonoff-Tasmota/wiki/Commands
  4. Now, Solder a wire to the Ground hole and another to the GPIO 14 hole.
  5. Turn off the breaker for the circuit you’re going to be working on. Or if you don’t mind electrical sparks or shocks, go ahead and leave it on.
    1. There are a few wiring arrangements you might find in the box.
      1. If all you see is one pair of wires going to the switch, which is unlikely but possible, then put the switch back in cuz you can’t connect a sonoff to that switch.
      2. Hopefully you see 2 pair of wire entering the box.  The white wire from each is tied together and the black wires go to the switch.  That’s the best case and easiest because all you have to do is take out the switch. Connect one pair to the input and one to the output.  If your sonoff doesn’t turn on, then switch the input and output.
      3. What I found in almost all my switch boxes was several pair of wires coming in.  All the whites tied together and all the blacks tied together, except one. That one black and it’s companion white are going to the lights. The other leg of the switch is also black and comes from the bundle of black wires. That is the Hot wire coming from the breaker.
  6. Connect the black wire coming from the circuit breaker to the “L” Input side of the Sonoff, and then a wire from the bundle of white wires to the “N” on the input side.
  7. Connect the Black wire that goes to the light to the “L” Output side of the Sonoff and the White wire that is with it, to the “N” on the Output side.
    1. I used flexible 12g wire to make moving the sonoff in the junction box a little easier.
  8. Then connect the GPIO 14 wire to one leg of the switch and the Ground wire to the other leg.
  9. To make the sonoff as small as possible, I cut the push button down with wire clippers, then wrapped electrical tape around the whole thing to insulate it.  
  10. At this point, turn the breaker back on to test it before you stuff it all in the junction box.  
  11. If it all works, then put it back together and do the Happy Dance. Or 30 seconds of wild fist pumping if you prefer.
  12. Now in Home Assistant you can set up a switch using the MQTT topics that will communicate with the Tasmota’d Sonoff:

switch:

 – platform: mqtt

   name: “Back Porch”

   command_topic: “cmnd/sonoff/power”

   state_topic: “stat/sonoff/POWER”

   qos: 1

   payload_on: “ON”

   payload_off: “OFF”

   retain: true

 

Restart home assistant and test it all out.  That’s it.  Now the hardest part is to decide which other switches in your house you’re going to upgrade.

 

The End

 

If you followed the last video you should have a Sonoff basic with TASMOTA running. With that in hand you’re ready to connect the Sonoff to your existing Light Switch and get in set up in Home Assistant.  This is the fun part!

 

With the USB adapter still connected to the Sonoff and the Computer you can find out if your firmware flashing worked.  Go into your router and look for a new connected device that has the project name you used in your user_config.h  Unless you changed the project name significantly it should say “sonoff1blahblah”.  Now take the IP address for that device and put it in your browser. That’ll show you the main Sonoff Menu page.  While we’re here we can get the sonoff ready to become a wall switch.  Under Configure Module, set GPIO14 to 09 Switch 1.  Save and it’ll restart in a couple seconds.  Now if you are using a standard rocker switch, you’re done.  But, if you want to use a push button or momentary switch, there’s one more thing to do.  Go to Console and type “SwitchMode1 4” and hit Enter. That’s in.  You can disconnect it from the USB adapter.  

Now you’ll want to solder a wire to GPIO14 and Ground (3-6” of small gauge wire).  Then you’re ready to connect it to your existing switch.  

When you open the switch box, it may not be obvious which wires come from the circuit breaker and which go to the lights.  It matters for the Sonoffs, so we have to figure it out. Here’s one way to do it. Before you turn off the breaker, use your multimeter to check the wires that are connected to the switch and determine which one is “hot”.  The non-hot wire will be the one going to the lights, and the hot wire is coming from the circuit breaker.  Alternatively, you could just guess. Turn the breaker off, connect it, turn the breaker back on, and test it. It won’t break the Sonoff if you connect the output to the circuit breaker.  So if you hook it up and it doesn’t work, you can just reverse it.

The solid copper wires can be difficult to work with.  I used some 12g stranded wire for my connections to the Sonoff. Connect the wires from the breaker to the input side, Neutral and Line (hot).  And the wires going to the lights to the output side.  Connect the GPIO14 and ground wires to your switch. Make sure everything is connected and no 110v wires are exposed.  Turn the breaker on and test it out.  If your switch works and you can go to the Sonoff IP address and Toggle the lights, that’s a good enough test for now. We’ll do the Home Assistant component next. Tuck the Sonoff back into the switch box carefully and put your switch plate back on.

Now go to your Home Assistant configuration file.  Add this Switch component.  The Name is what will show up in Home Assistant. The mqtt topic is set by TASMOTA and the project name. The middle section of the topics is your project name for each switch. You can change the Icon using mdi:icons. Once you’ve added all your sonoffs, check your config, and restart Home Assistant.  It should work like this:

 

This is powerful! Anything that runs on 110v can now be a “smart/connected” device for $5! If you have ideas for other things to control with one of these let me know.  I went a little crazy and bought a bunch. In a couple weeks I’ll show you how to do the same thing with a low voltage version of the Sonoff I’m using to control my 12v Crown molding LEDs.

Next couple videos are going to be about Holiday LEDS.  Comparing 5v and 12v, and then updating the Arduino Sketch with OtA capability.

 

End.