I have tons of automations that should fire only during certain time interval - from 18:00 till 6:00.
In all of them I have to use time checks with After and Before. It would be great if I could tune this time interval everywhere simultaneously without editing each automation by hand.
I tried using templating for Time helper there, but it doesn’t seem to work
condition: time
after: "{{ ... }}"
before: "{{ ... }}"
So is there some way to just insert some time variables there or do I have to use this monstrous construction generated by chatGpt just to check a time interval?
condition:
condition: template
value_template: >
{% set start_time = strptime(states('input_datetime.start_time'), '%H:%M') %}
{% set end_time = strptime(states('input_datetime.end_time'), '%H:%M') %}
{% set current_time = now().strftime('%H:%M') %}
{% if end_time >= start_time %}
{{ start_time <= strptime(current_time, '%H:%M') <= end_time }}
{% else %}
{{ strptime('00:00', '%H:%M') <= strptime(current_time, '%H:%M') <= end_time or start_time <= strptime(current_time, '%H:%M') <= strptime('23:59', '%H:%M') }}
{% endif %}