Smart switches are fun, letting you control lights and appliances in your home over the web or even by voice if you’re so inclined. However, they can make day-to-day living more frustrating if they’re not set up properly with regards to your existing light switches. Thankfully, with some simple wiring, it’s possible to make everything play nice.
The method is demonstrated here by [MyHomeThings], in which an ESP8266 is used with a relay to create a basic smart switch. However, it’s wired up with a regular light switch in a typical “traveller” multiway switching scheme – just like when you have two traditional light switches controlling the same light at home. To make this work with the ESP8266, though, the microcontroller needs to be able to know the current state of the light. This is done by using a 240V to 3.3V power supply wired up in parallel with the light. When the light is on, the 3.3V supply is on. This supply feeds into a GPIO pin on the ESP8266, letting it know the light’s current state, and allowing it to set its output relay to the correct position as necessary.
This system lets you use smart lighting with traditional switches with less confused flipping, which is a good thing in our book. If you’re using standalone smart bulbs, however, you could consider flashing them with custom firmware to improve functionality. As always, if you’ve got your own neat smart lighting hacks, be sure to let us know!
33 thoughts on “A Smart Way To Wire Smart Switches”
An entire 3.3V power supply? Wouldn’t a resistor and a diode accomplish the same thing?
Wouldn’t you prefer to maintain decent isolation between your low-voltage stuff and the mains? I’d even recommend a current transformer over a regulator, as you can get the same signal without any extra electrical connection at all.
A resistor, a diode, and a single opto isolator. (This will pulse the GPIO input at line frequency – you could filter it to a steady signal with an additional resistor and capacitor.)
The solution to use a 220v->3.3V power supply is pure insanity
yes, use that simple circuit https://bwir.de/wp-content/uploads/2020/03/led230v_s.jpg
and replace the led with an optocoupler.
Did you miss the additional PC817 opto in series to the 3.3V power supply? Regarding isolation, I would trust on the PC817 far more than on a 2-$-power-supply. And therefore the question remains: Why using the additional 3.3 V PS?
A 47nF dropper, full diode bridge & optocoupler is all what is needed. You can even use this to detect zero crossing.
See the simulation:
At first I thought sounded a bit expensive, then I remembered my box with dozens of 5V 500ma USB power bricks for which I paid by weight.
Find some USB dongles that transmit a unique hard-coded ping signal and you won’t even have to wire up the low voltage side.
The 3.3V signal does not tell you the state of the light. If merely tells you if power to the light is present.
I rest my case.
Why not wire the switch to the micro directly? There is low voltage VCC on the micro and a free pin for input. That way the micro would know the switch status all the time too and could alter the relay accordingly when needed.
That’s exact what I was thinking when reading this. Wire all the switches to the ESP, and let ESP control a SSR to turn on and off anything. You could have half a dozen switches to turn things on and off, plus the IoT side…
they probably didn’t want to break the light. they wanted the regular mechanical light switch side of it to always function reliably, the way it did years ago. not even a knock on the quality of their hack but this is something i’m always taking into account when i deploy one of my hacks into the shared living space. when my hack fails, i still need to be able to turn on the light. if it wasn’t a one-off prototype with bugs yet to be discovered, i wouldn’t have made it :P
So basically, this is like a commercial Shelly device, but with two required power supplies and a whole lot of wiring?
Agree – this falls squarely into the “Interesting but not worth the risk” category – the Shelly 1 is $10-15, neat, safe, and not going to invalidate your home insurance.
And some of the Shelly can measure power as well
I’ve done a wide assortment of Smart Home deployments using Control4 to Home Assistant. I’ve used cheap Tuya Devices, Z-Wave, Zigbee and also used Tasmota/ESPHome on some Tuya Devices that use the ESP8266. I’ve even installed some expensive PoE controlled Lighting.
The only reason why you need the 110 line is to power the Micro Controller inside the Device and to pass the Live/Hot through a Relay to the rest of the circuit. This is why you need a Neutral Wire. The Device knows if the Relay is ON or OFF by the state of the GPIO pin that is controlling the Relay. Some Devices will have another GPIO that will control a RGB LED via PWM to give a indication of the Light. Same thing can control the brightness of a LED Array in a bulb or whatever.
A lot of the cheaper WiFi Switches can control a three way / four way circuit with a single switch as long as the switch is made for 3way and is on the beginning of that circuit. Put it anywhere else and it will turn off or end up with a Disco/Rave Light. That is achieved with a Relay that is controlled from the switch leg and tells a GPIO pin the state of that Relay’s OPEN/CLOSE state and will in turn give you a conditional output. So if the Smart Switch turns on the Light and puts GPIO1 HIGH and you go to the end of the hall and use a dumb switch to turn it off then GPIO2 goes HIGH and GPIO1 is still HIGH. Then you go back and hit the Smart Switch again it will then put GPIO1 LOW but since GPIO2 is still HIGH it will give you a ON state. It’s basically a Electro-Mechcanical OR Gate controlled by a Micro Controller.
@fizzymagic, You would think a Resistor and Diode is all you need but not even close. That Resistor would be massive and would still be toasty. A single Diode would only make it a Half-Wave and would be a dirty DC signal and would require tons of smoothing either by a Pi Filter or a massive Capacitor. Most of these cheap WiFi Tuya based Switches and even the higher end Z-Wave/ZigBee Switches and Lights use a small crude Power Supply with a Current Limit to power the Micro Controller either at 3.3V or 5V.
Depends all on power requirement. If it should be just a signal, you could use high value resistor (M ohm range) to the µC pin. If it has input protection diodes you do not even need diodes. Of course the signal is 50Hz but that does not matter, the µC can take care of that in software.
If you want galvanic isolation use a dropper capacitor in series to the current limiting resistor and an Opto. Here you need 2 diodes.
it would be more interesting to use a LDR so it actually is a feedback loop if the lamp is catually on or not, also with this you could turn it of again if nothing is changing (eg outside light)
What exactly is wrong with a light switch?? Mounted on the wall or on the fixture. On, Off, Done. Not once have I ever said “gee, I wish I could flash my lights on and off over the internet.”
It doesn’t have to be over the internet. A lot of the useful functions of smart bulbs can be done with timers, sensors, dimming and colour control but that’s a lot of wiring to hook up. Powerline networking could be used but wifi’s already present and cheap.
Turning bulbs on and off when people are present, useful for bathrooms and cupboards. Turning them on at set times to wake you up on a winter morning. Changing colour on a schedule to remind you to switch from work to play. Turning off at a set time to remind you to go to bed.
“This project does not apply to me and is therefore useless” is the new “Could have used a 555”
I put tape over the switch.
I had a very similar project a while back: https://hackaday.io/project/19893-low-cost-smart-switch
The advantage with my solution is that you can also plug it to an existing two-way switch.
There is a commercial cheap product available that is certified… https://shelly.cloud/products/shelly-1l-single-wire-smart-home-automation-relay/
Which you can either reflash with your own firmware or disable the shelly cloud and only let it work via mqtt.
The ‘certification’ on this product is not valid for North America, and cannot be installed by homeowners if they do not want to affect insurance coverage. The ‘CE’ mark is NOT a certification; it is a declaration by the manufacturer that may or may not be subject to any formal certification. Australia/NZ certificates, through the registration process, may use standards that are not scoped per North American building codes.
For mains-connected stuff in North America, you need a test certificate from a 3d-party lab that is accredited per NRTL/SCC/NOM where insurance is an issue, or if the equipment will be used in the workplace.
Honestly, you’d need some pretty shitty insurance or pretty suspicious conditions for them to investigate the certifications of the wall switches. (That’s been my experience with (unfortunately) 2 very large claims, at least.)
All I want is a home automation light switch that uses a traditional toggle (not Decora) switch, and the switch actually reflects the state of the what the light is (ignore the bulb might be burned out, that’s a non-issues). When I walk into a room I want to slap the switch the way I’m used to and change the state of the light to the state I expect. Off is down is off, on is up is on.
Send a command to turn the light on from the home automation system, and the light switch physically changes state to reflect the state of the light.
It’s interesting but the downsides i see with this wiring are the power leakeage of the relays (to mantain the relay switched) and the lack of a MQTT on/off state.
Also (at least important in my country) in the case of a power failure the initial state of the lamp once the power is recovered is dependant of the last state of the swtich.
Maybe a more or less good middle solution will be the adition of a button on the switch itself that only inverts the state of the ESP, and the ESP will report the change of state via MQTT to the server.
That’s why latching relays are preferred in lighting control applications. The down-side is having to determine the relay state when your controller resets. This adds a manual switch, so you have to determine the switching state anyhow.
Somebody deleted my strictly technic comment and the Falstad simulation I posted here. THIS is my last comment here on the HaD.
The spam bots only understand grade 2 English, are suspicious of any word more technical than “wire” and hate URLs, it might pop up during the next 24 hours when it gets reviewed.
You better check again! It’s absolutely still there! (Maybe do a ctrl+f do search the page for Falstad or your name.
Its all good until all these fancy gadgets stop working for one reason or another. In todays world, companies are trying to fix things that are not broken and the same is true here with these fancy relays. Just have an Electrician install the proper wiring, 3 way and 4 way light switches so that they continue to work correctly for the next 100 years. In my humble opinion, Keep It Simple. If you want a wifi enabled light switch, thats ok, just make sure it works like a regular light switch when the internet goes down or if you switch your wireless router and then you have to go nuts to reset all your wireless wifi devices. I hope my advise helps. Steve Kavallatis, Chief Electrical Instructor & Inspector.
Please be kind and respectful to help make the comments section excellent. (Comment Policy)