Hey everyone! I wanted to share my experience with automating my dining room lights to adjust based on sunrise and sunset times. It’s been a fun project, and I think others might find it useful too. ![]()
![]()
I’ve been using an automation setup for a while now, but I realized that the fixed time-based adjustments weren’t accounting for the changing daylight hours. So, I decided to tweak it to follow the sunrise and sunset more accurately. Here’s how I did it:
-
Understanding the Problem: My initial setup used fixed time slots to adjust brightness, but it didn’t account for the gradual changes in daylight during different seasons. This meant the lights were sometimes too bright or too dim depending on the time of year.
-
Research and Planning: I looked into how to integrate sunrise and sunset data into my automation. I found that using time-based triggers with dynamic adjustments was the way to go. This involved setting up a script that calculates the brightness based on the current time relative to sunrise and sunset.
-
Implementation: I set up an automation that triggers when the dining room lights turn on. The script then calculates the appropriate brightness percentage based on the time of day. For example, it starts dimmer in the early morning, increases as the sun rises, and adjusts again as it sets. Here’s a snippet of the script I used:
yaml
- alias: Dining Room Brightness Adjustment
trigger:- platform: state
entity_id: light.dining_room
from: ‘off’
to: ‘on’
action: - service: light.turn_on
data_template:
brightness_pct: >
{% set hour = now().hour | int %}
{% if hour >= 7 and hour < 8 %} 15
{% elif hour >= 8 and hour < 9 %} 40
{% elif hour >= 9 and hour < 18 %} 100
{% elif hour >= 18 and hour < 19 %} 50
{% elif hour >= 19 and hour < 20 %} 30
{% elif hour >= 20 and hour < 21 %} 10
{% else %} 1
{% endif %}
kelvin: >
{% set hour = now().hour | int -%}
{% if hour >= 6 and hour < 8 %} 3000
{% elif hour >= 8 and hour < 18 %} 3500
{% elif hour >= 18 and hour < 20 %} 2500
{% else %} 1700
{% endif %}
entity_id: light.dining_room
- platform: state
-
Testing and Adjustments: After setting it up, I tested it over a few weeks to ensure it worked as expected. I made some minor adjustments to the brightness levels to better match the natural light conditions. It’s been working great, and I love how the lights now adapt to the changing daylight!
-
Tips for Others: If you’re looking to set something similar up, I recommend starting with a basic script and gradually tweaking it based on your observations. Also, consider using a service like
sunin Home Assistant to get accurate sunrise and sunset times for your location.
I hope this helps someone looking to enhance their home lighting automation! Let me know if you have any questions or if you’ve tried something similar. ![]()