Building an Ambient Lighting System with Python and Home Assistant
A Python script that reads the dominant color from your screen every second and pushes it to Home Assistant — so your LED strips follow whatever is on screen.
Building an Ambient Lighting System with Python and Home Assistant
I always wanted an Ambilight setup but didn't want to pay Philips prices for it. The idea is simple: read what's on screen, extract the dominant color, and push it to the LED strips around the monitor. Since my whole home runs on Home Assistant, it made sense to route it through there.
The script uses mss for fast screenshots, opencv-python to cluster the pixels and find the dominant color, and a plain HTTP POST to the HA REST API.
On the Home Assistant side I set up a simple automation that reacts to sensor.dominantcolor changes and calls light.turnon with the new RGB value:
I run it as a systemd service on a small Linux box next to my monitor so it starts automatically on boot.
The result is exactly what I wanted: start a movie and the room lights shift along with the color on screen. Costs nothing extra if you already have HA and a WS2812B strip. Full code on GitHub.