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
Bill of Material
- 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