P205 23:31:30 13 FEB
AUTOMATING LIGHTS WITH A RASPBERRY PI
02 SEP 2021

Pi Lights was a fairly simple idea and my first exploration into DIY home automation: measure the ambient light level throughout the day using a Raspberry Pi, then switch Wi-Fi lights on or off automatically.

Implementation

The system polls several light-dependent resistors and averages their readings before deciding whether to switch the lights. Using multiple sensors and rate-limiting changes made the automation less sensitive to brief shadows or sudden changes in brightness. A dedicated light-sensing Raspberry Pi HAT would have been more accurate, but I wanted to see if I could build a first pass using components I already had lying around. I ran the software as a Linux service so it would start automatically and continue working in the background without needing any attention.

I also designed the system to only switch the lights when the threshold was crossed, avoiding constant requests to the Wi-Fi lights when they were already appropriately on or off. This also meant that if I chose to turn the lights off manually, the system would not turn them back on.

The Raspberry Pi setup and room light sensing circuitry

To make the system easier to understand and tune, I also built a small Express server and React client for viewing logs and historical light-level graphs. Seeing the sensor readings over time helped me choose sensible thresholds and diagnose cases where the lights behaved unexpectedly. The project later grew to include a lights-out timer and an Alexa welcome message when I arrived home.

A graph of recorded light levels over time used for debugging and tuning

Reflection

Although the end result performs a simple task, building it involved hardware integration, network-controlled devices, scheduling, and monitoring a service intended to run continuously. It taught me that even small automation projects benefit from useful logs and a way to inspect their behaviour, particularly when they interact with an unpredictable physical environment.

View the project on GitHub