When the sun sets at a partical level you could make an automation to turn on the lights with a transition of a couple of minutes till it’s dark. But how long would the transition be? It depens on the time of year.
I have made a formula that calculates the brightness of the light depending on the elevation of the sun. This automation will work every day of the year. The lights will go on very smoothly. I love this
alias: ''sunset transition'
trigger:
- platform: time
minutes: '/2'
seconds: 00
condition:
condition: and
conditions:
- condition: time
after: '16:00:00' (the time when a sunset could start in a year)
before: '23:00:00' (the time when a sunset could end in a year)
- condition: numeric_state
entity_id: sensor.sun_elevation
above: 0
below: 9
- condition: or
conditions:
- condition: template
value_template: '{{ states.light.(livingroom light 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 light group).attributes.brightness==null }} '
action:
- service: LIGHT.TURN_ON
entity_id: light.(livingroom light group)
data_template:
profile: sunset
brightness: '{{((0.0625*(states.sun.sun.attributes.elevation**2))-(31.125*states.sun.sun.attributes.elevation)+246.5)|int}}'
For the sun.elevation sensor I have used a template sensor:
Yes, I use the flux light adjustment switch in combination with this. it gets even more smooth. Good point. I have used the sun component as you can see. A weather attribute is a good addition to this. If it’s cloudy. You could increase the brithness of the lights
Will have to take a look at this and combine a few things, I’m putting up my weather station outside soon and it will have a lux value sensor on it to mix in for light adjustments with weather.
you can use the values in the example. I have chosen the value 9 because that’s the angle of the sun with the horizon when it’s beginning to get dark. when the value is 0 the light is at it’s brightest and the automation stops
I don’t want to trigger every 2 minutes the whole day. Only when it’s possibly needed…Maybe it doesn’t make sense but I think it’s more focused on the sunset’s time window
This looks great, gonna try this out the weekend. Super cool. So this will go from off to 100% as the sun sets from 9 degrees to 0 degrees above horizion.
I assume you have a group called “livingroom light” I’m still getting used to the finer naming with yaml, but wouldn’t you need underscores?
So If I wanted to copy this exactly, I should create a group with only lights and name it “Livingroom Light Group” or “Livingroom Light”. My automations with groups dont do anything like this, just mostly turn them on or off, but the enties are named "group.outdoor_lights_sunset’ for example.
Yes, the name of the light group is not (livingroom light group). It’s just an example. You could use light.livingroom for example. A group of lights is seen as one entity. Like it is one light bulb:
I run luminiscence (lux) sensors in some rooms, and use that information to see when I should turn on/off the lights. (Subtracting the lightsources from the sensor value, of course.)
i’m adapting his automation with my garden lights, i’ve made some changes, removing the first condition time leaving the sun elevation can some one tell me in it’s ok? i whant that the group.luci_parete_giardino turn on at the dusk( in my case at below -2) and the transition stop after 30-40 min ( at above -7) is this code correct?