I’ve always been fascinated by how technology can blend seamlessly with nature, and my recent journey into creating a sunset-based lighting automation has been nothing short of magical. Let me share my experience and some tips for anyone looking to achieve a similar effect.
The Vision
The idea was simple yet profound: have my living room lights gradually dim as the sun sets, creating a smooth transition from daylight to night. I wanted this to happen every day, regardless of the season, so the automation needed to be adaptive and precise.
The Setup
I started by setting up a Sun Elevation sensor using a template. This sensor tracks the sun’s position in real-time, providing the necessary data for my automation. Here’s how it looks:
yaml
sensors:
- platform: template
sensors:
sun_elevation:
value_template: ‘{{ states.sun.sun.attributes.elevation }}’
Next, I created an automation that triggers every two minutes between 4 PM and 11 PM. This time frame ensures it captures the sunset period throughout the year. The automation checks the sun’s elevation and adjusts the brightness of my lights accordingly.
The Formula
The key to a smooth transition lies in the formula I developed. It calculates the brightness based on the sun’s elevation, ensuring a gradual fade:
python
brightness = ((0.0625 * (elevation ** 2)) - (31.125 * elevation) + 246.5)
This formula ensures that the lights don’t suddenly turn off but instead dim progressively as the sun sets.
The Automation
Here’s the full automation setup:
yaml
alias: Sunset Transition
trigger:
- platform: time
minutes: ‘/2’
condition: - condition: and
conditions:- condition: time
after: ‘16:00:00’
before: ‘23:00:00’ - condition: numeric_state
entity_id: sensor.sun_elevation
above: 0
below: 9 - condition: or
conditions:- condition: template
value_template: ‘{{ states.light.livingroom_group.attributes.brightness < ((0.0625*(states.sun.sun.attributes.elevation**2))-(31.125*states.sun.sun.attributes.elevation)+246.5)|int }}’ - condition: template
value_template: ‘{{ states.light.livingroom_group.attributes.brightness==null }}’
action:
- condition: template
- condition: time
- service: light.turn_on
entity_id: light.livingroom_group
data_template:
profile: sunset
brightness: ‘{{ ((0.0625*(states.sun.sun.attributes.elevation**2))-(31.125*states.sun.sun.attributes.elevation)+246.5)|int }}’
The Result
The outcome has been nothing short of breathtaking. Every evening, as the sun dips below the horizon, my lights dim in perfect harmony with nature. It’s as if the room itself is breathing, adjusting to the changing light outside. This automation has transformed my evenings into a serene experience, seamlessly transitioning from day to night.
Tips for Success
- Sensor Accuracy: Ensure your sun sensor is accurately configured. The
suncomponent in Home Assistant is reliable, but double-check your longitude and latitude settings. - Light Setup: Use lights that support brightness adjustment. LED bulbs with dimming capabilities work best.
- Automation Timing: Experiment with the trigger interval and time frame to match your local sunset patterns.
- Formula Fine-Tuning: Adjust the formula coefficients based on your location and lighting preferences. A slight tweak can make a significant difference in the smoothness of the transition.
Conclusion
Creating a sunset-based lighting automation was a rewarding project that combined technology with the beauty of nature. It’s a small but meaningful way to enhance daily life, making every sunset a special moment. If you’re looking to add a touch of magic to your home, I highly recommend giving this a try!
Happy automating! ![]()
![]()