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


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!


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!!!




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.



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:




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:
  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: “”


  • /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.



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





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!


Source Code and Models



« 2 of 2 »

78 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.

    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: 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. Did you think about and are there plans to add a current flow/power measurement?

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

  12. 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?

  13. Can you add views of connections of both side of the board. I don’t get the P$1 connection amusing P$2 is neutral and P$3 is hot

    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.

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

  15. 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.

  16. 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?

  17. 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.


    at the light itself whit neutral and leed black

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

  19. 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.

  20. 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. Unfortunately I don’t have much free time to spend on this project. You can subscribe, so that you get any updates on this page in the future.

      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?

  21. 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.

  22. 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/

  23. Hello Hristo,

    Why is there a big sleeve in the middle of the pcb board?

    1. Hello, the “sleeve” is to physically separate the high-voltage and the low-voltage parts of the circuit, so that no spark can jump from one to the other.

  24. Hi Hristo,
    Great project! I am thinking of implementing something like this directly into lamp that I am designing and i believe it is not a problem , but i am wondering how difficult is to make an app (android version too)

    1. Hello, in my view making a simple app isn’t very difficult. The switch exposes a REST api so the only thing you need to know is how to handle HTTP requests.

      1. No idea what you just said 🙂 I understood shouldn’t be so difficult… 🙂 I’ll try to find someone to help me with it. I’m more a fabrication guy.
        Few other questions, maybe I missed something…
        I’m not sure if I understood, you have to add your socket / controller to a wireless network before you install it into the wall, or there is an option to do it trough the app? Also manual switch (with indicator and touch sensor) is separated and remotely connected to the switch?

        Thank you for sharing, I’m always blown away by cool projects people do in their spare time.


        1. Hi Jan, you don’t have to join a network before installing the switch. When you switch it on, it will try to connect to a configured network if there is one. If it can’t succeed in a minute it will offer an access point with a name like “switch – 000123”, to which you can connect and configure your wifi parameters.

          The physical switch and indication module is attached to the base of the switch, but it is connected through wires, not remotely.

  25. Hi, where did you buy or get the metal terminals for mounting the female schuko? Thank you very much!

      1. Thank you very much for the fast reply. I can´t find those terminals too. I will search for alternatives.

  26. Hi Hristo,

    Thank you for the great project!

    I came across it recently and researched more on powering the ESP8266 from the mains.
    The results point out that some thermal, overload and overvoltage protection for the low- and high-voltage circuits can be added relatively easily using some fuses and a varistor.

    I found more information in this article:

    Kind regards,

      1. Hello Hristo,
        I am in the process of realizing your project.
        Unfortunately the program always does a “wdt reset” and I can’t find out why.
        Do you have any idea?
        Translated by Google.

  27. Hi Hristo, very nice project. First time saw your Switch I’m trying to make one. Downloading software from GitHub with Arduino IDE compile and upload to ESP8266-01. Connect resitance for stability exactly like on your schematic. Connect power and then after 30 seconds should see Switch-000035 on my network list. Unfortunly nothing all the time receiving from Tx periodicaly.

    wdt reset
    load 0x4010f000, len 3584, room 16
    tail 0
    chksum 0xb0
    csum 0xb0
    Am I do something wrong or forgot something?

    Nice regards

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.