Roboticized Light Switch for Home Automation
by Sverd Industries in Workshop > Lighting
4613 Views, 53 Favorites, 0 Comments
Roboticized Light Switch for Home Automation
Today I'm showing you how I solved the super annoying problem of automating my lights, when it's not possible to change out the light switch or switch to smart bulbs. The solution was to make a roboticized cover which makes my dumb light switch a lot smarter!
For the last few years I've been doing various home automation upgrades to my apartment to make it a lot smarter, but there's always been one glaring issue I couldn't solve: Automating my ceiling lights.
Because I rent the apartment I'm limited in the changes I can do to it. At first I looked for smart bulbs to install in my ceiling spotlights, but because there's so many of them it would be really expensive. Adding to the cost factor is that the special type of light bulb connector couldn't be found with smart home capabilities in my country, so I would have to import the light bulbs. This would significantly increase the cost as well as make it really cumbersome every time one the bulbs burnt out and I needed to change them.
The alternative would be to install a smart switch, which in my opinion would be a lot smarter regardless of the cost and availability of connected light bulbs. But yet again, I couldn't make any permanent changes to the apartment and this includes operating on mains voltage and changing out the light switch.
While I loved the smart home upgrades I could do they acted as a painful reminder of the upgrade I wanted, but couldn't have. I could live in home automation limbo no longer and decided to solve the problem the best way I know how to, by making a robot.
Supplies
- 1 x ESP-12E
- 1 x Push servo 20kg 180 degrees
- 1 x Continuous rotation servo
- 6 x 10k ohm 0806 resistors
- 4 x 100nF 0806 capacitors
- 1 x 10uF SMD ECAP
- 1 x 100uF SMD ECAP
- 1 x 5.1mm female barrel jack
- 2 x Push button 6.0x3.5mm
- 1 x Rotary encoder
- 1 x Rotary encoder knob. Needs to be cut down to 5mm height
- FTDI helper
- 5-6V 600mA power supply
- 1 x AMS1117 3V3 voltage regulator
- Custom PCB. See step 3 for details
Overview
First of all I recommend you watch the video to see the development process and the final light switch in action.
There will be three main components in this build:
- Mechanical design, to recreate me manually using the switch and dimmer
- Control electronics for communicating with Home Assistant or any other MQTT server
- Programming, to make the logic that automates and ties everything together
After building and configuring the project the lights can be controlled through four main ways:
- Through a phone, tablet, computer or whatever you have that can access Home Assistant. I set it up as a local server so it will continue to work even if the internet is disconnected, which is important
- Through voice with Google Assistant, which relays the commands to Home Assistant. This will only work when you have a valid internet connection
- Through a rotary encoder with a built in push button. This would continue to work even if both internet was down and my local automation server stopped responding for some reason
- The final way to control the lights is by manual override. As I can easily enough push or turn the light switch even with the upgrades installed
3D Printing
For the 3D printing I went with a white filament to match my walls and original fixture. The parts where printed in 0.2mm layer height, because there are mostly straight walls this looks really good.
Feel free to deviate both from my color choice and layer height, you do you!
You can always find the up to date 3D files at this link.
PCB and Electronics
I designed the PCB to have a low profile by placing all the components on the front side as well as only using SMD components (except for the power jack). I went with through hole connectors on the power jack to relieve mechanical stress from the power cord. To make the barrel jack sit flush on the PCB as well I trimmed the leads and soldered it from the front side, rather than the backside of the PCB.
To make soldering easy I recommend starting with all the smaller components first before doing the larger ones, like the rotary encoder and ECAPs.
The PCB holder on the mounting plate was designed to take a PCB with a thickness of 1mm. I kind of wish I ordered the circuit board with a white solder mask because that would look really cool if I didn't cover the electronics in the final assembly. You can make the choice I didn't when you make your PCBs, and if you want to use the kind sponsor of the project, JLCPCB, you can get 1-4 layers manufactured for $2 and new users get a $18 discount with the coupon: https://jlcpcb.com/DAA
You can find the GERBER files I designed for the project here.
Uploading Code
The light switch itself receives signal from a MQTT server, if you don't have on setup for yourself (it's super easy on a Raspberry PI), you could use free options like Adafruit IO.
I have setup a MQTT host on my Home Assistant instance running on my local Linux server. This is suuper flexible and let's me use MQTT for all the control signals and Home Assistant to make everything user friendly.
In the pictures you can see the particular settings you need to change when you download the code (Github repo), and which settings to use in Arduino IDE when uploading, choose the COM port on your machine .
To upload the code follow these steps:
- Select modes FTDI, 3V3, and VREG on your FTDI uploader tool
- Push down the pogo pins on the PCB header as shown in the picture
- Press and hold the FLASH button
- Press and hold the RESET button
- Let go of RESET button after a second
- Let go of FLASH button after one more second
- Press upload button in Arduino IDE
- Reset the board
After this first code is uploaded you have the option of uploading new code OTA, the password for this sketch is: ESPOTA. I recommend this guide if OTA is something you want to setup.
Home Assistant
After the microcontroller is connected to the WiFi and MQTT server it can be configured as a light entity in Home Assistant. This will make the smart servo switch act like any other smart bulbs and switches on the market, while maintaining the command structure and custom functions necessary for changing the light in the physical world.
First I added the following lines in my light.yaml file:
- platform: "mqtt"
name: "Smart Switch"
command_topic: "smartswitch/set"
payload_on: "ON"
payload_off: "OFF"
state_topic: "smartswitch/state/status"
brightness_command_topic: "smartswitch/brightness"
brightness_state_topic: "smartswitch/state/brightness"
brightness_scale: 100
optimistic: false
After rebooting Home Assistant the smart switch will show up and be configured like any other entity. This made my ceiling lights available to be controller from all over the world, including form smart speakers like Google Assistant.
Final Assembly
Now it's time to bring it all together!
The tiniest gear can be screwed onto the rotational servo before it, and the bigger servo are screwed onto the main mounting plate. I used the included servo screws for all of this.
The PCB is designed to slide into a pocket where it's held snuggly. You may have to use some force make this happen, but if you feel the PCB bend you're using too much force.
I covered the backside of the mounting plate with double sided tape because again, I can't make any permanent changes in my apartment lol.
For the main dimming gear I coiled and bent some copper wire around the tension pegs to help keep them pressing on the light dimming rotor. I later changed the wire for a rubber band as it feels a bit safer and more robust.
Now it's just a matter of attaching the mounting plate and dimming gear onto old light switch. I also added some white covers for the motors and PCB purely for cosmetic reasons and to make the assembly look less busy. As a finishing touch I fitted a shiny silver knob onto the rotary encoder.
Connect the power and that's it!