Automating Lights Based on Sunset: A Smooth Experience

Hey everyone! I wanted to share a little project I’ve been working on to automate my outdoor lights based on sunset. It’s been quite the learning experience, and I thought I’d document it here in case others are looking to do something similar.

I’ve always loved the idea of my lights turning on automatically as the sun sets, but I wanted something a bit more nuanced. I didn’t just want them to come on at a fixed time; I wanted them to adjust based on the actual sunset time, which varies throughout the year. Plus, I wanted a bit of randomness in the timing to make it feel more natural.

So, I started by setting up an automation in Home Assistant. I used the built-in sun sensor to track when the sun is below a certain elevation, which I set to 25 degrees. This works well because it accounts for twilight, ensuring the lights come on when it’s truly getting dark. I also added a time condition to make sure everything happens after 4 PM, just to be safe.

Here’s where it got interesting. I decided to add a random delay to the automation. This way, the lights don’t all come on at the exact same time every day. Instead, they turn on within a 15-minute window after the sunset trigger. It gives my neighborhood a more organic feel, and I love the subtle variation each evening.

I ran into a little hiccup, though. Initially, the automation would trigger immediately when I turned it back on after being away. It took me a bit to figure out that the issue was with the numeric state condition not updating properly. I had to adjust the logic to ensure it only triggers once the sun has dipped below the threshold after the automation is reactivated. A quick tweak to the conditions in the automation solved the problem!

Now, everything works seamlessly. The lights come on at just the right time, with a bit of randomness to keep things interesting. It’s such a small thing, but it really enhances my evenings at home.

If anyone else is looking to set something like this up, I’d recommend starting simple and then adding layers of complexity as you get comfortable. The satisfaction of seeing your lights automatically adjust to the natural world is pretty unbeatable!

Happy automating everyone! :star2: