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!
Table of Contents
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:
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)
- 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:
- CVILUX CU3
- CVILUX CW3S
- RGB led – WS2812B
- A button
- Touch sensor – Jog Type Touch Sensor
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:
- Connect to the wifi network created by the switch and from the browser open this URL: http://192.168.4.1/configure
- Enter your wifi network’s SSID and password.
- 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:
- /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.
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
- How to use the ESP8266-01 pins
- Hi-Link Power Supply Performance Test
- Adafruit NeoPixel library
78 thoughts on “Switcher – A WiFi Open Source Power Switch and Socket Based on ESP8266”
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.
I’ve added screenshot of the board for now. Once I have some time will add an annotated picture of the real board.
Hi Hristo Borisov!,
Can you please describe “Discover switches”
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.
Well Done! I didn’t find any authentication, I mean authentication to switch on or off. I missed it or there is not?
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 🙂
Great idea, great implementation. What were your aprox. costs per unit? You have bill section but I couldn’t find costs there. Thanks
Approximate cost is about 15$.
I did something similar with Amazon Alexa support. Check out my repo https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch
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.
Yes, thank you! I’ve missed that somehow.
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
I would love to get the touch part as I am thinking of making some similar switches.
I use this kind of sensors: Jog Type Touch Sensor Module Capacitive Touch Switch Module For Arduino
There are several types available on the internet.
Any way to modify for USA 120v?
The module accepts 100-240VAC
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.
Awesome project, by the way!
I don’t think there is a way with only single wire. You can think of fitting the device on the ceiling where the lamp is.
Why not physically add the neutral wire. Pull back the switching wire and add put back the switching wire together with the neutral line.
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?
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.
Excellent project. Well done.
The BOM lists MOC3023 While the Board silkscreen says MOC3033S. Which is the best part number?
MOC3033 is the best part.
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 ?
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.
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.
Yes, that’s the right part.
Did you think about and are there plans to add a current flow/power measurement?
Currently I have no such plans…
You can replace module – HiLink 5v / 3w for a cell phone charger or something similar?
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?
You will need the handleConfig() method of LightSwitch.ino and also the WifiConfiguration class (.cpp and .h)
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
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.
Nice project. I also use Hi-Link. I am now attempting squeeze the LED Matrix (WS2812 8×8) to switch.
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.
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.
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?
There is an almost identical (ESP8266 based) and a lot cheaper solution called Sonoff from ITEAD. The price is 4.85$ and a lot of people have succeeded in flashing it’s firmware with their own.
Yes, I saw it recently.
hi on your board where i can connect a push button for manual on off ? thanks
The J1 connector is for manual on/off button.
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
Cool project! I had a similar idea some time ago.
Where did you get this metal mounting bracket from?
Hi Pawel, the metal bracket is from a regular manual lights switch. I have taken apart several of those and use the brackets.
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.
Great to hear that! Thank you.
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?
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.
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?
Hi, I have bought them from comet.bg – a bulgarian electronics store. They have online shop and ship internationally, so you can try: https://store.comet.bg/en/Catalogue/CON/Connectors/#eyJpcHAiOiIyMCJ9
I guess many other connectors would work, but you have to look in the specs – max voltage, max current.
I found and orderd them, thank you
It is possible to use an optotriac instead of optocoupler and triac, to spare some place?
Interesting idea, I haven’t thought about it.
Is there by any change a android app?
Currently not. But it should be pretty easy to build one, if only I had the time.
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?
Good question Renaud Cerrato,
I have the same question 😉
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.
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
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/
Why is there a big sleeve in the middle of the pcb board?
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.
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)
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.
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.
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.
I have same project, you can visit my blog
Hi, where did you buy or get the metal terminals for mounting the female schuko? Thank you very much!
for my units I’ve used parts from old AC extenders, adapters, etc.
It turned out to be very difficult to find such terminals. I only managed to find some on alibaba.com, but there you have to order thousands which was not feasibly for my project.
You can try with these keywords: https://www.alibaba.com/trade/search?fsb=y&IndexArea=product_en&CatId=&SearchText=schuko+brass+pins
Thank you very much for the fast reply. I can´t find those terminals too. I will search for alternatives.
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:
Hi Nikolay, this is a needed addition to the device. Thanks for the tip!
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.
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.
load 0x4010f000, len 3584, room 16
Am I do something wrong or forgot something?