Switcher – A WiFi Open Source Power Switch and Socket Based on ESP8266

head_small

This is my latest project – The Switcher, a Wifi, open source, power switch and socket.

Built with modularity in mind – It can be mounted as a wall lights switch or used as a standalone power socket. Switcher gives the ability to control your lights, or any other household appliance, wirelessly over the wifi network and the Internet! There is a dedicated iOS App and web interface which can be used with any browser! You can build your own designs to make unique wall light switches for your house.

The switch uses the prominent ESP8266-01 module, an Arduino program, a 3D printed box and modules. It is free and open source, so you can build and modify it on your own!

Caution

This project can be dangerous! The circuit is attached directly to the mains electrical grid and is exposed to high  voltages! Make sure you understand what you are doing and that, a mistake can be harmful or even lethal!!!

Hardware

pcb

 

The circuit is very simple. The main goal was to make it small enough so that it can fit into the wall console where a standard light switch is put. The main obstacle was to find a small and powerful enough power supply,  because the ESP can consume a lot of energy sometimes. So I came up with this module – Hi-Link 5v/3w which can be found easily on the Internet.
The other decision I made was to use a triac instead of a relay, because the triac is smaller, faster and also in the future I would like to add a dimming capabilities to the switch.

At the center of the circuit is the ESP8266 module. Pins 2 (Rx), 3 (RST), 4 (GPIO0), 5 (CH_PD), 6 (GPIO2) are pulled high to prevent booting the ESP into programming mode. This requires “inverting” the GPIO pins programmatically. Also in this case the Rx pin is used for button input and its UART function is disabled in the program.
The power supply module steps down the voltage to 5V, but the ESP requires 3.3V, that’s why I use LM1117 voltage regulator. I could have used 3.3V power supply directly, but I’ve decided to have both: 5V and 3.3V which later paid off because in the shields (modules) I am using RGB leds and touch sensors which operate on 5V.
GPIO0 of the ESP8266 is used to switch on/off the controlled appliance. This is done through an optocoupler and a triac. The optocoupler (MOC3023) isolates the low-voltage circuit from the high-voltage one and the triac (BT136) is doing the switching.

circuit

pcb_board

You can find an Eagle project on my github repository: eagle project

You can order pcb directly form OSHPark: Order from OSH Park

Bill of Material

You can buy some of the parts on banggood.com or on aliexpress.com

  • ESP8266-01 (buy from banggood.com
  • LM1117 (buy from aliexpress.com)
  • MOC3033
  • BT136
  • 3.3K SMD resistors (0603), 5 pieces
  • 430 SMD resistor
  • 470 SMD resistor
  • 10uF SMD tantalum capacitor (P package), 2 pieces
  • 3pin terminal block 3.5mm (DEGSON)

For the modules:

Modules

<todo>

Firmware

Repository: Switcher Firmware

The firmware is very simple. It is written in C++ (Arduino) and uses several libraries from the Arduino/ESP8266 project. Additionally I am using the Adafruit NeoPixel library to control RGB LEDs for the on/off indicator. Currently it supports the bare minimum:

  • Setting up a wifi hotspot for initial configuration
  • mDNS discovery
  • REST API for remote control and query of the switch state.
  • Configuration is persistent and is permanently stored in the onboard EEPROM memory of the ESP8266 module.

Initial Sequence and Handling

When you first connect a brand new power switch it will try to connect to a wifi network. Because one is not configured it will wait for 30 seconds and then give up. A wifi hotspot will be started with name following this convention: Switch – xxxxxx where xxxxxx is a six digit number burned during programming. To configure:

  1. Connect to the wifi network created by the switch and from the browser open this URL: http://192.168.4.1/configure
  2. Enter your wifi network’s SSID and password.
  3. The device will reboot. Once it starts again your switch will be accessible from within you wifi network.

To connect to the switch you can use its IP address or its mDNS name, which is the-name-of-the-switch.local. The name of the switch is the six digit number present in the hotspot’s name.
The REST API is quite simple. It uses only HTTP GET for now. The endpoints are:

  • /on – Turns the switch (and what is connected to it) on
  • /off – Turns the switch off
  • /state – Gets the current switch state. This URL returns a simple json payload such as:
    {

    • id: “000019”,
    • state: 0,
    • ip: “192.168.1.103”

    }

  • /config – Used to configure the device. Currently only configuration for the wifi network are available
  • /color – Used for demo purposes to switch the RGB LED to the given color for five seconds.

Box

switcher_strip

3D model files: 3D Model

The case for the device and the modules are created using Autodesk Fusion 360, which is a great program and is free for makers!
The device is modular: it has one base module containing the actual device and several add-on modules adding different capabilities. Currently there are lights switch module and european type electric socket (schuko type) which can be used to remotely control any device.
Very cool feature is that you can change wall switches on the fly. So if you are bored with the current color, you can change it with different one instantly. You can design and print your own which is not necessary to be a square one! Think about the possibilities!

You can find the 3d models and gcode here. The gcode was used to print the prototypes on Ultimaker 2, with .5 mm head and PLA material. You can see the results in the gallery.

 

base_wall wall_off

wall_on

 

thumb_IMG_0760_1024

 

iOS App

iOS App Source: iOS App

The iOS program is also very simple. It is different from the others similar apps with that, it doesn’t use lists to show the available switches. I wanted a simpler more visual experience. So I came up with the idea to use custom buttons (which are in the form of light bulb at the moment) which you can drag and drop around, rename and also combine. Combining switches is actually something very powerful. If you drag and drop one button onto another, this creates a paired button. When you switch a paired switch on or off, it will turn on or off all the devices attached to this button.
That way you can turn on all your lights at home with just one click!

ios_app

Source Code and Models

Links

Gallery

« 1 of 2 »

64 thoughts on “Switcher – A WiFi Open Source Power Switch and Socket Based on ESP8266

  1. Well Done! I was impressed by the Hi-Link 5v/3w and powering the ESP directly from the current. But I am somehow confused by the PCB and Schematics ( they are not labeled). Will be great if you put more photos of naked PCB with the elements.
    Regards.

    1. Hi, the discover switches functionality provides a very easy way to list all the switches installed in the house. It just tries to access the url: http://192.168.1.1-254/status in a loop. If it successfully fetches status of a switch then, the later is saved in the app. Basically with this approach I’ve avoided the need to create a form where to enter switch details manually.

  2. Well Done! I didn’t find any authentication, I mean authentication to switch on or off. I missed it or there is not?

    1. There is no authentication at the moment. I rely on the fact that the network itself is secured. This is not sufficient of course but its a prototype after all 🙂

  3. Great idea, great implementation. What were your aprox. costs per unit? You have bill section but I couldn’t find costs there. Thanks

  4. Please note that the PCB layout of the ground surface break the isolation cut. I suspect that the high voltage isolation rules need to be enforced in some others places.

  5. You spoke about touch sensors in your intro and some of the pictures allude to it as well. Any details on this? Love the project! Would love to have something similar done at home. Like the Hi-Link module. Cannot find the 5V one on ali express though. Only 3.3 and 12V. Thanks again

  6. Is there any way to make these work in a wall switch where there is no neutral? I’ve been interested in doing a project like this for some time but it’s always killed me that in my house the neutral is wired directly to the lamp. There is only a 2 wire “leg” that comes down from the lamp to the switch to control the hot (120V) side of the circuit.

    Any ideas?

    1. Why not physically add the neutral wire. Pull back the switching wire and add put back the switching wire together with the neutral line.

  7. Great project, would love to build and just ordered components. Have a question, though: I seem can’t see on schematics where to connect the WS2812 LEDs?
    Thank you.

    1. I have to describe that part better. I will do it when I have some more time. Anyway, the LED is connected to J3 connector if you look at the schematic.

  8. great project !! and at the best time as well 🙂 the only thing i miss is the ground in the outlets. any advice how to add them ?

    1. I’ve asked an electrician to do that for me. In my case, one meter above the switch there was a junction box, where all the cables were connected together. From there we pulled the neutral line to the switch box.

  9. The unlabeled box in the bottom right of the schematic that shows AC in and 5v out which is not in the BOC appears to match the “Hi-Link 5VAC-DC” silkscreen. I’m guessing the part number is Hi-Link HLK-PM01.

  10. You can replace module – HiLink 5v / 3w for a cell phone charger or something similar?

  11. Hello Hristo, I am very new to programming the ESP, I have been experimenting with some remote switches, I was very interested in the section of your project that allowed the WIFI details to be entered in at a later date when implemented. I would like to utilise this in one of my projects however my skills are limited and i am unable to separate this section from your code.
    Would you be able to help me out with this please?

    1. You are right P$2 is neutral and P$3 is hot (line). However you attach the Lamp (or other appliance) to P$1 and P$2. When in switched position the P$1 will be hot as well.

  12. Nice project. I also use Hi-Link. I am now attempting squeeze the LED Matrix (WS2812 8×8) to switch.

  13. Hi, would it be possible to have a photo posted with the upclose front of the board with all the parts mounted except the ESP module? I want to try to build one for me but i want to see better the board and identify all the components soldered. Having a video posted building one top to bottom would definetely bring you many friends on youtube. Thank you in advance for your support.

    1. Hello Paco, I’ve added pictures of step-by-step assembly of the device. You can find them in the gallery. Having a video is a good idea indeed, but I’m not sure when I will have time do one.

  14. Thanks. I see the photos now. Would it be possible to upgrade the design with a ESP-12 MCU instead of the ESP-01 and have the PINS (digitals and analog) available on one side of the board?

  15. if i understand you can replace a wall switch by plugging neutral and plugging the 2 black lead cable of the switch in lmp and l.

    or

    at the light itself whit neutral and leed black

  16. Cool project! I had a similar idea some time ago.
    Where did you get this metal mounting bracket from?

  17. I just posting to say “great project”. Even when some parts “sounds” like many other projects, going deep into the code and the way you designed it allowed me to solve some issues I was dealing with and thing that doesn’t is like other stuff we can find in the internet. Thanks for sharing the project.

  18. Great project, I was looning for a solution like this, the sonoff isnt an inwall module. But i am also wondering tge same as Paco
    (31/10/2016), will you be upgrading your design for use with the ESP-12E?

      1. Thank you for the quick reply. I do have another question if you dont mind. Where did you buy the CVILUX CW3S & CVILUX CU3 connectors. I cant seem to find them online. And if i cannot buy them in the Netherlands, which other connectors would you recommend?

  19. Good job! But it seems to me that the design is somewhat flawed for light switches: most of current electrical installations doesn’t provide both L and N into the wall. So you’re stuck. Fibaro dimmer modules supports 1-Wire installations, do you think it would feasible?

    1. Hi Renaud, I never thought about mass producing my switch, that’s why I never thought about covering all types of installations. I really don’t know currently, how it might be redesigned to work on L lines only. I am not aware how the Fibaro Dimmer works.

  20. Hey Hristo! Great project for little budgets! I’m trying to do something similar but with one big difference: Instead of using an IOs app or browser to switch the plug, I want to use a simple manual switch (which needs to be connected to (another) wifi of course- any suggestions how to realise this? Thanks, Jacob

    1. Hi Jacky, actually the same device – either with the wall switch or with the electric outlet “shields” – can be used for a manual switch as you suggest. It only needs to be reprogrammed, so that whenever you press the button you don’t switch the triac on or off but instead send an http request.

      Another possibility I thought about is to use the amazon dash or amazon iot buttons – https://aws.amazon.com/iotbutton/

Leave a Reply