Making Smart Bulbs sense and create Ambient Scenes

Tushar Kulkarni
2 min readFeb 13, 2023

Smart devices just make your life easier, you can just turn it on /off from anywhere using just your phones or web services. But that’s not the only thing they can do, devices like smart bulbs(colorful ones) can notify you with notifications with color change often called as ambient notifications.

Youtube Thumbnail

E.g. Its Snowing outside and the smart bulb color turns blue/white or its very sunny and it turns Bright yellow during your alarm.

You can also mix these up with your morning routines so you know whats the weather like outside and not forget to pick the choice of coat appropriate to the weather :)

I recently bought Kasa Smart Bulbs (TP Link) and I just loved controlling them with my phone. I wanted to do more , so I gave them steroids(a Python Program) and the result was amazing.

I found out that the smart bulbs can also be controlled through python libraries with devices on the same network i.e. with a Laptop having python installed on the same network as the smart bulbs.


  1. Any Laptop with Python installed(Preferably Linux otherwise the following code needs to be tweaked)
  2. Kasa Smart Bulbs along with Kasa library/SDK installed on the Laptop
  3. A wifi network to allow communication between the laptop and the smart bulbs

I won’t say I am a movie buff but I do enjoy watching movies and tv shows, so I made the smart bulbs sense two dominant colors from the movie/tv show that is running and adjust their color to that scene and I believe it turned out very well. I am still in the process to improve the code.

I used the following code to run a script in a linux OS where it uses pyautogui library to constantly take screenshot of the content displayed on the screen and then save the image in the folder.

Run the command kasa once on your terminal to get the IP addresses of your smart bulbs and put them in the script.

I did face a challenge first because the smart bulbs use HSV system to change colors . HSV stands for Hue Saturation and Value . Whereas the colorthief library extracts RGB(Red,Green,Blue) colors , so I had to also convert the RGB color to HSV so the lights could understand the colors.

The Algorithm:

initialize bulbs

while true:
take screenshot
save it in /tmp/
extract colorpalette using colorthief library
update the colors of smart bulbs in an asynchronous manner
sleep for some time

Want to check how it turned out ? You can watch the following video.

Thanks for reading till the end :D !!!