Specc
Published on

DIY Smart Light Project

Introduction

This is a very niche project, as a lot of newer houses—and even many older ones—already have a neutral wire for smart light switches, or they can have one installed. This project will be a bit bulky, but it’s a cheap and easy way to get smart-light functionality while gaining experience in coding and working with servo motors.

The Problem

The problem here is that my house is too old and doesn’t have a neutral wire. It’s also not worth installing one at this point, but I still want the full functionality of a smart light switch without compromises. That’s where this idea came in.

Using servo motors and 3D-printed parts for DIY light switches isn’t new, but my situation is unique—I have strange dimmer and fan control switches combined into one single wall unit. This makes it impossible to use most readily available DIY smart switch projects, so I had to design my own solution.

The Solution

I decided to use a more powerful 10 kg servo since the dimmer on my light switch can be a bit stiff, and I wanted to ensure the servo could press it fully off and on. For wireless control and logic, I used a Raspberry Pi Zero 2 W that I had lying around (with a broken camera module). However, you could just as easily use a cheap ESP32 instead.

I installed Ubuntu Server on the Pi, but any lightweight Linux distro would work fine. After installation, I connected via SSH and began the basic setup and troubleshooting.

Before writing the servo control program, I needed to find a suitable mount and bracket. I settled on a 3D-printed linear servo arm and made a few modifications to fit my light switch. Instead of a flat end, I added a small hook to the actuator arm. This hook was specifically designed to fit around the dimmer “handle,” then I printed it and tested the fit.

The first issue I ran into was aligning the hook with the switch while attaching the servo gear to the linear actuator. As you can see in the picture below, it was a bit finicky—I suggest fine-tuning this part before moving on, which I learned the hard way. Once the servo and printed mount were properly aligned and secured, I started developing the control program.

The main challenge was determining the correct servo movement range—enough to fully turn the light on or off, but not so much that it strained the servo or broke the switch. I learned this lesson the hard way after snapping my first actuator by moving the servo too far. After reprinting it with 50% infill and trying again (with plenty of “crunchy noises” and cringing), I finally found the sweet spot: 0.45 for on and -0.45 for off.

In my case, -1 to 1 represents the full servo motion range. This number isn’t a unit like degrees or radians—it depends entirely on your servo’s configuration and linkage geometry. This was the first version of my program, using two separate Python scripts (one for “on” and one for “off”). The next step was fine-tuning and optimization.

Fine Tuning

The first tuning step was deciding how I wanted to control the lights. I chose my iPhone, which meant I needed HomeKit integration for controlling the servo.

I used Home Assistant, which I already run on one of my servers, since it supports a huge range of smart home functions. If you only need it for this one thing, you could install it directly on the Pi, though performance might not be great.

At first, I used SSH shell commands in Home Assistant to connect to the Pi and run the Python scripts for “on” and “off.” This worked, but there was a noticeable delay. Another issue was that HomeKit showed each command as a separate switch, which was confusing and clunky.

After a lot of experimenting, I combined everything into one Python script and switched to MQTT for communication. Setting up MQTT took a bit more work, but it was absolutely worth it.

After several revisions and debugging sessions, I ended up with a single script that could fully turn the lights on or off—and even control brightness with a dimming slider. At first, I used step increments of 0.18 (about five brightness levels between -0.45 and 0.45), but I eventually refined it to 0.01 per step for much smoother, finer control. This is the script I’m using now, and it integrates perfectly with my iPhone for seamless light control.

Conclusion

This project was incredibly fun and a great learning experience—especially in working with servos, MQTT, and Home Assistant. There are certainly better or more elegant ways to accomplish this (some involving hiring an electrician—or possibly electrocuting myself). But for me, this was a creative and practical solution to automate my room lights without touching any wiring.

There are plenty of more practical applications for servo motors, which I plan to explore in the future. For now, this was a fun and surprisingly reliable fix for my “lazy light switch” problem. All of the code and print files are available on my GitHub repository for this project.

If you thought this was in the least bit interesting maybe take a look at my PiKVM Project Thanks!