This repository is now archived- this functionality can be better achieved using Home Assistant. While this script may be useful if you're in need of something extremely lightweight, Home Assistant is significantly easier to set up & maintain, and is probably still lightweight enough for most people.
A simple script that automatically syncs some Kasa dimmers to a day/night cycle at a location of your choosing. I keep reptiles, so I use this to simulate a more natural environment in their enclosures than what off-the-shelf solutions provide. I run it on a Pi Zero W, but it should work basically anywhere as long as it's on the same network as your hardware.
- Not every bulb can dim- fluorescent UVB bulbs for instance cannot- so you may find your bulb is flickering or whining.
- The dimmer's networking component can fail silently. If you notice that your system simply stops working with no error messages in the log, you may want to try replacing your dimmer.
Requires Python 3.9 or greater and at least one Kasa Smart Dimmer
- Clone this repository into a folder with read/write access
- Install requirements.txt
- Follow this guide to get your Kasa device information
- Modify the config file so that it accurately reflects your setup and needs
- Run the script
There are four solutions that currently exist for managing reptile lights.
-
Turning all your bulbs on and off every day by hand is 100% free and you could create any day/night cycle you want. It also sucks.
-
Mechanical timers are cheap, intuitive, and widely available, making them popular with beginners. They come with two major downsides- they're noisy, and they drift. You have to do a maintenance check every couple of months to keep up with seasonal daylight changes & fix drift, as well as whenever there's an outage.
-
Electrical timers are very similar to mechanical timers, but use a chip to keep time. Nowadays, they're barely more expensive than mechanical timers, and totally silent. They're also less prone to drift, though it will still happen over time. Otherwise, they function identically and carry the same downsides. In my opinion, they're strictly better than mechanical timers, barring that some may have a slightly less intuitive user interface.
-
Smart plugs are a bit different. Because they're internet-enabled, they're completely immune to drift & resilient to power outages and, because they're fully electric, they're completely silent too. Many can be easily programmed to turn on and off at sunrise/sunset, and they can be dirt cheap. In some ways, these are an ideal solution for your average reptile keeper. The main downside is that there's no standardization- some use an app, some use a hub; some apps are good, some apps suck; and many apps require your phone to be on the same wifi network for scripting to work. They also tend to be shockingly easy to hack, and so can function as a backdoor into your home network. Finally, they're harder to setup than mechanical/electric timers, requiring you to install an app, connect the devices to your network, and configure the devices.
I've used all of these solutions with my reptiles at various points, and I definitely favor smart plugs. However, I got tired of their issues, so I made my own solution. It uses Kasa brand smart devices, because, at time of writing, they have a great API and Python library that makes scripting super easy. Some advantages are-
- No app: No app means no reliance on any infrastructure other than my own. In today's world where any service can be killed at any moment, this provides me with tremendous peace of mind.
- Robust: If the power goes out, I can trust that everything will go back to normal as soon as the power goes back on. If someone accidentally turns a plug off, it'll turn itself back on.
- Sunrise/Sunset: No off the shelf solutions supports simulated sunrise and sunset via dimming, but this script does. This does require dedicated hardware, but I think it's worth the extra headache. That said, it's easy to remove this feature if you don't want it.
The main disadvantage of this script is that it needs to be running 24/7- meaning some kind of dedicated hardware is preferrable. It's lightweight enough that it should run on anything that supports Python, for instance, I'm running it on a Pi Zero. The other downside is that it is far and away the most complicated solution, requiring a fair amount of technical background to set up comfortably. That said, if you're comfortable with that, I think this solution will suit you better than any other.