Setting Up Sunrise-Based Lighting Automation

Hi everyone! I hope you’re all doing well. I wanted to share my experience setting up an automation for my living room lights based on sunrise timing. It’s been a fun project, and I think others might find it useful too!

So, the goal was to have my living room lights turn on at 6:50 AM, but only if the sunrise is expected to be 30 minutes or later. This means if the sunrise is at 7:20 AM or later, the lights should come on as planned. If the sunrise is earlier, the lights should stay off. I tried setting this up myself, but it didn’t work at first. Let me walk through how I figured it out!

First, I looked into the automation settings in Home Assistant. I knew I needed to use a time trigger for 6:50 AM and a condition based on the sunrise time. The tricky part was comparing the current time with the sunrise time. After some research, I discovered that using the sun condition with an after offset was the way to go.

Here’s the corrected automation code that worked for me:

yaml
automation:

  • alias: ‘Turn on light at 6:50am if sunrise is on or after 7:20am’
    trigger:
    platform: time
    at: ‘06:50:00’
    condition:
    condition: sun
    after: sunrise
    after_offset: ‘00:30:00’
    action:
    service: light.turn_on
    entity_id: light.living_room_lamp

This setup ensures that the lights only turn on if the sunrise is at least 30 minutes after the trigger time. It’s been working perfectly for me!

I also wanted to share a tip: when working with time-based automations, it’s helpful to test with different sunrise times to ensure everything works as expected. You can manually set the sunrise time in the developer tools to simulate different scenarios.

This project made me realize how powerful Home Assistant can be with just a little bit of tweaking. It’s amazing how you can customize your smart home to fit your specific needs. I hope this helps someone else looking to set up similar automations!

Happy automating! :sun_with_face: