The sensor which was asked in the question seems to implement exactly the same thing I am doing, that’s why I replied to the old thread, because it is the question which I wanted to know an additional detail.
What I am doing:
The covers in the ground floor shall open 5 minutes before sunrise, but not before eg 6 in in workdays and 8 on weekends and holidays.
So I have some helper input.datetime which are input fields at the settings dashboard
Rolladen_auf_Feiertag
Rolladen_auf_Werktag
Rolladen_zu_max
There are two template sensors
Rolladen_auf_Heute
{{ today_at(max(states('input_datetime.rolladen_auf_werktag')
if is_state('binary_sensor.workday_sensor','on')
else states('input_datetime.rolladen_auf_feiertag')
, as_timestamp(as_datetime(state_attr("sun.sun", "next_rising"))-timedelta(minutes=5)
) | timestamp_custom('%H:%M:%S')
))
}}
Rolladen_zu_heute
{{ today_at(min(states('input_datetime.rolladen_zu_max')
, (as_timestamp(as_datetime(state_attr("sun.sun", "next_setting"))+timedelta(minutes=5)
) ) | timestamp_custom('%H:%M:%S')
))
}}
which are shown on the settings dashboard as information.
The covers are being controlled by a state machine.
Values for Rolladen.Zustand (also editable on that settings dashboard):
Manuell
Auto.Morgensonne
Auto.Mittagssonne
Auto.Tag
Auto.Nacht
The automation “Auto Rolladen Nacht Ende” for instance is triggered by the time Rolladen_auf_heute if state machine is not in state Manuell. It activates the scenes for the covers depending on the weather forecast (cloud and teperature) and sets the state to Auto.Morgensonne or Auto.Tag (depending on the forecast result). And so on.
I documented the state machine in a DrawIo picture, but it is only for myself and maybe my family.
And what made me think about when the events get triggered was the sensor for workday/holiday malfunctioning yesterday … so my whole question here was: How often is that template sensor being recalculated? Was the answer given last year fine or does it do unnecessary operations? And as sun.sun state change is only 2 times a day (sun up or sun down) and an event also occurs on value change of the attribute, I’m fine with the answer.
(am still searching the cause for that workday sensor problem, but that would be another topic - edit: something was broken, am not the only one, see here)