An ESP8266 in Every Light Switch and Outlet

[Hristo Borisov] shows us his clever home automation project, a nicely packaged WiFi switchable wall socket. The ESP8266 has continuously proven itself to be a home automation panacea. Since the ESP8266 is practically a given at this point, the bragging rights have switched over to the skill with which the solution is implemented. By that metric, [Hristo]’s solution is pretty dang nice.

esp8266-smart-lightswitchIt’s all based around a simple board. An encapsulated power supply converts the 220V offered by the Bulgarian power authorities into two rails of 3.3V and 5V respectively. The 3.3V is used for an ESP8266 whose primary concern is the control of a triac and an RGB LED. The 5V is optional if the user decides to add a shield that needs it. That’s right, your light switches will now have their own shields that decide the complexity of the device.

The core module seen to the right contains the actual board. All it needs is AC on one side and something to switch or control on the other The enclosure is not shown (only the lid with the shield connectors is seen) but can be printed in a form factor that includes a cord to plug into an outlet, or with a metal flange to attach to an electrical box in the wall. The modules that mate with the core are also nicely packaged in a 3D printed shield. For example, to convert a lamp to wireless control, you use a shield with a power socket on it. To convert a light switch, use the control module that has a box flange and then any number of custom switch and display shields can be hot swapped on it.

It’s all controllable from command line, webpage, and even an iOS app; all of it is available on his GitHub. We’d love to hear your take on safety, modularity, and overall system design. We think [Hristo] has built a better light switch!

84 thoughts on “An ESP8266 in Every Light Switch and Outlet

  1. Love it, but yes it would need some grounding, am wondering if you have a lot of esp8266 devices on your wifi, plus the normal wifi load (phone’s, tablets, laptops) isn’t a normal accespoint going to get smashed

    and 2.4GHz is already so full. isn’t a radio module on 866 of 443 MHz more stable

  2. Devices that are ment to be plugged in these outlets (lamps) don’t have earth connection at all, so it is not dangerous for that use scenario. However, if outlet leaves possibility to plug fridge, angle grinder or some other device that requires earth connection it’s a bad design. Since outlets are 3D printed I suppose it wouldn’t be a problem to make some kind of notches that will get in the way with earth-enabled plugs while allowing those that has no earth.
    Otherwise, those are pretty nice internet-enabled plugs, I like that AC/DC adapter that makes whole thing very compact.

  3. “Every Light Switch and Outlet”?

    So, like 50? With ESP8266?

    Power consumption? Why promoting the wasting of energy (and money)?
    Delay until the light actually turns on after pushing the button?

  4. How can you power this module installed in the place of a light switch?
    In most european countries the switch only breaks the live wire going to the lamp socket.
    So if you switch that off with this module you kill your own power supply. If you switch it on you (the ESP power supply) will be in series with the light bulb which makes most of the light bulbs unusable (I know, i tried)
    Do they have an additional (3 cables total) neutral or protecting earth in their light socket holes?

    1. @pusher The lack of neutral in UK switches is why I’d go with battery power and a TI CC1310. Probably a latching relay rather than a triac too.

      #1 Rule of any home automation system is that my wife has to be able to turn the light on or off with a switch regardless of flat batteries or bugs in my code.

    2. And yet dimmers work.

      Draw the circuit out and include the load and wiring back to the mains panel.

      The light switch doesn’t have to be totally off, it just has to provide a low enough power to the load that it doesn’t operate.

          1. Yes they do draw power.

            Lutron has special pull-out programming tabs for some electronic dimmers for use with CFL or LED bulbs.

            They set the minimum TRIAC on time to be low enough to keep the light off but high enough to keep the dimmer powered on.

  5. Two more problems:
    The used BT136 is rated for only 4A. Where i live, a typical mains outlet delivers 16A. So to avoid burning down the house, a fuse is needed.
    The switching on of the BT136 seems not to happen near voltage zero crossing. At least the utility companies where i live do not like this because of EMI / missing PFC.

    1. 4A at 230V, that’s more then 900Watt, I would say that is more then sufficient for any lightbulb!
      If you are worried about burning down the house, well that can happen at any current.
      But, let’s assume he’s using a component that can handle 16A, well then you let must have a device capable of drawing/handling 230×16=3680W NOW that would be a possible fire hazard! The device by itself, the wiring in the house, etc. And then we haven’t spoken about contact resistance in the power outlet pins, these could/would be very hot, melt the plastic of the 3D printed case eventually leading to all sorts of problems. 16A is a lot for a simple power outlet!
      So in short, when used for connecting simple lightbulbs or devices… I think he’s safe on the BT136 regarding it’s current capabilities.

      1. From memory, all devices connected to mains must be able to handle the current rating of the main breaker for that circuit. In Australia this is 10A for light circuits and 16A for power outlet circuits (usually – some outlets can be higher). If your device is intended for connection to a light circuit, it must be capable of handling 10A, so 4A will not cut it. This remains true even if you expect to use less – and for LED bulbs, perhaps a lot less.

        1. You can use the 4A TRIAC, but you need an extra fuse (5*20mm part is sufficient). This is mostly to protect the TRIAC from a failed bulb. Otherwise the TRIAC would act as a fuse, which is normally not desirable.

      2. Ehm, you must count with everyday use. Leave device like this with someone who does not care and your house is on fire. People still trying to put AC air heater on 25meter (>80ft.) power strip and wondering why they catch a fire. So that is why good electrician must be smarter and anytime trying to fight against risks of using electricity.

    2. A fuse is *required* for safety. The idea is to make sure than none of the components and wiring has to handle more than their rated current in case of a *fault*. It doesn’t matter how much nominal current is.

      Not sure about flammability rating for printed plastic. :P

  6. The AC wiring is just too close to the digita part of the circuit, this could lead to arcs that could potentially destroy the device in case of power spikes.

    The AC part of the circuit probably does not meet certification requirements for applications that have AC outlets exposed, for example it does not have a fuse rated at the max current that can be handled.

  7. I swore when I saw this.
    I’ve had a ton of time sitting on my butt lately, thinking about how to do something (instead of being able to do something).
    I decided it was time to improve the humble light switch with a simple wifi connection (especially of 802.11s actually has any acceptance). The ESP8266 modules have become insanely inexpensive.

    The tripping point I’ve had is how to present some of the basic “smarts” behind the switch plate to the user. In essence, when a “non-connected user” (person in the house, but not on the network/not trusted with the access) wants to turn on the light, they need to be able to turn on the light. If they want to dim the light, they should be able to dim the light. Nine times out of ten, the local, manual user should be able to override the remote user.

    I got stuck on this. The whole light switch should be cheaper than the nice light switch at the hardware store down the street (~$50-~$70). I think it could be done much cheaper than that. The goal being to get one of these in each room, along with a temperature sensor, maybe a motion sensor or light sensor.

    How do you keep it inexpensive, but allow a user to walk in and see the status of the switch? Ideally, they should be able to look at the switch and see that it is off versus on (up versus down position). Servo mounted switch? Powered linear slide? Not cheap.
    The switch itself should consume a very small amount of power. As an ecology, smart equipped plugs could ultimately reduce power consumption, even as they sip small amounts of power through the day. All of the parasitic power losses due to chargers and standby systems could be solved by a smart home grid, a sensor at every power dispenser. Want to watch TV, pull out your phone and power up those outlets involved. I shudder to think how much parasitic power is involved right there. But there is no way that one of my house denizens is going to flip the switch every time she wants to watch TV. But she will pick up the remote, or even her cellphone (frequently she turns on the TV and pulls out her cellphone anyway….)

    I love this project. Keep pushing at it. Small, incremental changes are going to make it awesome.

    1. I have been looking for 3 position latching rocker switches for exactly this reason.

      Position 1 – on, manual override.
      Position 2 – retain the setting from which you entered position 2, allow remote control.
      Position 3, off, manual override.

      So far, I have been unable to find anything that matches the above requirements.

      To explain “position 2” a little better:

      Position 1 and 3 provide explicit on and off capabilities, which addresses Rule 1 of home automation mentioned above (the wife must always be able to turn the light on or off). These could potentially be hard wired to mains, entirely bypassing the automation (and any failures thereof).

      Position 2 is used to allow remote operation. The RF and microcontroller is powered up. If the switch was previously in Position 1 (i.e. on), the output should remain on. If the switch was previously in Position 3 (off), the output should remain off.

  8. Applications notes of AC-DC converter modules almost always demand a fuse and a varistor, often also mains filters. And using a triac without a fast acting fuse means asking for trouble.

    No one stops you from plugging a 3000W heater into that socket. Good luck with the 2*0.75mm mains wire.
    Hopefully the triac will protect the wire by blowing up without starting a fire.

    Don’t try this at home, kids.

    1. And in Mexico too. I saw them run a red wire and a green wire to the socket, then they wired the green to the ground AND neutral socket pins. He told me all those black wires were a waste of money!

      I believe this is TN-C earthing

  9. Yeah but in most countries the light switches do not have neutral or earth connections just a single phase broken in two pieces (hence the two cables) joined by the switch. The “real” neutral is at one end of the light bulb.

  10. There seem to be more and more projects of this type in the literature, and I thought it might
    be time to temper the well-intentioned enthusiasm with some real-world practicality, and legality.
    First, a fact or two (please be advised that I have no knowledge of regulations outside of the USA).
    Most jurisdictions in the USA will issue you a ‘Right to Kill Yourself’ electrical permit, also known as a “Homeowner’s Electrical Permit”. An example of such a permit, taken directly
    from the internet, is shown at the end.
    Notice the particularly pesky phrase which somehow seems to worm its way into all documents of this type: “…the work must meet…the National Electric Code…”.
    Now, the NEC boys and girls, being absolutely humorless, insist that work conforming to the
    NEC’s rules and regulations extend to all wire and devices employed.
    Did you find the ‘gotcha’?–all DEVICES must conform to the NEC’s high standards, which means UL approval. The NEC doesn’t care whether the DEVICE you employ is a light switch, a toaster, or a 25 KW emergency power generator; they’re ALL ‘devices’.
    Two last items of which you should be aware–(a) Any time you bring any electrical ‘device’ into your house and plug it in, you are considered to be under the contractual influence of the Homeowner’s Electrical Permit; (b) The second item involves a much more chilling consequence; if your insurance carrier can trace a fire in your house to a non-UL-listed device, they will not honor any claim for damages.


    “…I also understand that the work must meet the Building Code and the National Electrical Code and I am required to obtain the inspection(s) from to ensure the above requirements have been met. This includes a final inspection.
    If I am found to have falsified this application in any way, I will face legal action including a fine and/or imprisonment.”

  11. Can we also use this one as an example of naive and hopeful ignorance? You want to hope that their insurer or whatever passes for a national electrical regulatory agency in their country never sees this.

    UL exists for a reason, and this is so very far from UL compliance (isolation, creepage/clearance, flammability… everything) that it’s frankly terrifying.

    I’m all for DIYing things but you need to know what you’re doing. The downside to this whole “maker” craze is that people make seriously dangerous stuff with no clue as to why it’s dangerous, and it’s not just the builder who is at risk from it all.

    1. I agree but the problem runs deeper:
      Don’t build yourself a smart phone if you can’t ensure its safety and that it doesn’t start burning.
      Don’t build a car if you can’t build reliable electronics
      Don’t build a car if you can’t guarantee environmental standards
      Don’t build a wireless module if you can’t ensure FCC compliance (The one from China with kilometers of range is just fine. It even has the FCC stamp).
      Don’t build an iphone charger if you can’t do it according to safety standards.

      Oh and don’t build your own smart plug. But you can buy and use anything from China. That’s alright. No questions asked. Just don’t look inside.

  12. I have looked for an esp8266 based module that is UL listed, and I don’t think they exist. If you put this in your wall and your house burns down for ANY reason (not related to your project), your insurance company will probably not pay, because you have a non UL listed device. Be smart … Is it worth several hundred thousand dollars?

    1. In the US, maybe you’re right, although I suspect you haven’t double checked that it’s true even there.
      Outside of the US, things are different. Insurers in France would not refuse claims because of that — it’s not in the contract or in law that they can. I believe it will be the same elsewhere in Europe.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s