I like to use the sun attributes next_dawn and next_dusk as timestamp for turning on some outdoor light. Currently I sunset and sunrise with an offset. But this differs between winter and summer and I don’t want to change the offset according to the current season.
Any Ideas?
Thanks in advance.
I think I found out by myself and I can just use dusk and dawn instead of sunrise and sunset.
This wasn’t well documented and I was wondering why in the examples is just sunrise and sunset mentioned, but the attributes for this time value called next_rising and next_setting. I will test dusk and dawn now.
Please report back if this works and what you used
I am using a sun angle below 10 degrees (or something like that) to compensate for different light levels for different times of year - but dusk and dawn might work better
It depends if HA defines twilight by angle (6°) or time (24minutes). Time after sunset or before sunrise will not give you seasonal adjustments. Angle below the horizon will (and should be used). Even though the sun appears to move at a constant rate of 15° an hour the angle of the ecliptic will cause seasonal variations in twilight length as measured by time. See my awesome illustration skill here:
Thanks for your explanation. But I think your are wrong with your point of longer twilight in winter. I live in the northern hemisphere and used this page for calculate the civil twilight http://jekophoto.eu/tools/twilight-calculator-blue-hour-golden-hour/index.php
And this show me for March and my geo positions a civil twilight of 34 minutes and for June I’ve got 46 minutes. Which shows me a longer twilight in summer.
I tested with the event “dusk” and “dawn” but this are no events that are fired. Even at the restart of homeassistant I’ve got a message about a broken automations configuration.
It wouldb be more easy to use if “dusk” and “dawn” where events like “sunset” and “sunrise”.
The angle of the ecliptic and horizon doesn’t actually change with time of year, just latitude.
You would still be accounting for this if using the angle of the sun below the horizon (6 deg) for calculating the time to switch, rather than a fixed time offset.
So I like this and set it to come on below 25° however I think I need another condition so it doesn’t come on in the mornings?
So I want my lounge room lights to come on when the sun is lower than 25° and I manually turn them off when I go to bed at 10pm and I don’t want them to come on again until tomorrow at 25° again…
With regards to next_dusk and next_dawn in action please see my example within the circadian lights automation. This relies on a sensor that dynamically calculates the period of day which I’m in (of course this is independent from local time, any time zones or the ever-changing day length).
The issue with the sun component is that the dusk and dawn values are always directed towards future: Once you have gone beyond e.g. the current next_dusk mark, it immediately switches to the next day’s mark. Therefore I used a trick in order to calculate the dusk and dawn zones. As soon as the result of next_dusk minus next_setting becomes negative, I know that I have entered the dusk-period. Once I pass the next_setting mark, this value turns positive, so I know that I just left the dusk-period.
I do the same for ‘next_dawn’ and this is how the sensor looks like:
- platform: template
sensors:
period_of_day:
friendly_name: 'period of the day'
value_template: >-
{% if (as_timestamp(states.sun.sun.attributes.next_dusk)) - (as_timestamp(states.sun.sun.attributes.next_setting)) < 0 %}
dusk
{% elif (as_timestamp(states.sun.sun.attributes.next_rising)) - (as_timestamp(states.sun.sun.attributes.next_dawn)) < 0 %}
dawn
{% elif (states.sun.sun.attributes.elevation) < 0 %}
night
{% else %}
day
{% endif %}
icon_template: >-
{% if is_state('sun.sun', 'above_horizon') %}
mdi:weather-sunny
{% else %}
mdi:weather-night
{% endif %}
This is what’s shown in the GUI:
You can find the holistic integration with circadian lights below:
The difference is that I’m just changing the value once, and then keep the value until the next change. This prevents it from boucing when changing from dawn to day.