At the moment I have this automation:
- id: HEATER_OFF_20210107204600
alias: TERMOSIFONI - Spegnimento
trigger:
- minutes: /1
platform: time_pattern
condition:
condition: and
conditions:
- condition: or
conditions:
- condition: time
after: '09:00:00'
before: '16:00:00'
- condition: time
after: '22:00:00'
before: '06:00:00'
- condition: state
entity_id: input_boolean.poweron_bypass_riscaldamento
state: "off"
action:
- service: script.set_heater_off
It powers off the climate if an input boolean is off AND if current time is between 09-16 OR 22:00-06.
In effect my climate starts at 06:00, stop at 09:00, starts at 16 and end at 22.
It works very well, without no troubles with time spanning between 2 days (after 22 and before 06), but I would improve it, using 4 input datetime:
input_datetime:
start_zone_1_heater: # 06:00
has_date: false
has_time: true
end_zone_1_heater: # 09:00
has_date: false
has_time: true
start_zone_2_heater: # 16:00
has_date: false
has_time: true
end_zone_2_heater: # 22:00
has_date: false
has_time: true
I have trouble with the construction of the conditional value template, 'cause I have a bit of trouble with time spanning in 2 days.
I wrote this template
{{ ((states('sensor.time') >
(states.input_datetime.end_zone_1_heater.attributes.timestamp | int | timestamp_custom('%H:%M', False)))
and (states('sensor.time') <
(states.input_datetime.start_zone_2_heater.attributes.timestamp | int | timestamp_custom('%H:%M', False))))
or
((states('sensor.time') >
(states.input_datetime.end_zone_2_heater.attributes.timestamp | int | timestamp_custom('%H:%M', False)))
and (states('sensor.time') <
(states.input_datetime.start_zone_1_heater.attributes.timestamp | int | timestamp_custom('%H:%M', False)))) }}
In effect, at 23:00 I think condition time cannot be evaluated at true, because 23 is greater than end_zone_2 (22), but it NOT smaller than 06:00.
So, my automation could be a bit of…
- id: HEATER_OFF_20210107204600
alias: TERMOSIFONI - Spegnimento
trigger:
- platform: homeassistant
event: start
- platform: template
value_template: "{{ states('sensor.time') == state_attr('input_datetime.end_zone_1_heater', 'timestamp') | int | timestamp_custom('%H:%M', False) }}"
- platform: template
value_template: "{{ states('sensor.time') == state_attr('input_datetime.end_zone_2_heater', 'timestamp') | int | timestamp_custom('%H:%M', False) }}"
condition:
condition: and
conditions:
- condition: or
conditions:
- condition: template
value_template: >
{{ ((states('sensor.time') >
(states.input_datetime.end_zone_1_heater.attributes.timestamp | int | timestamp_custom('%H:%M', False)))
and (states('sensor.time') <
(states.input_datetime.start_zone_2_heater.attributes.timestamp | int | timestamp_custom('%H:%M', False))))
or
((states('sensor.time') >
(states.input_datetime.end_zone_2_heater.attributes.timestamp | int | timestamp_custom('%H:%M', False)))
and (states('sensor.time') <
(states.input_datetime.start_zone_1_heater.attributes.timestamp | int | timestamp_custom('%H:%M', False)))) }}
- condition: state
entity_id: input_boolean.poweron_bypass_riscaldamento
state: "off"
action:
- service: script.set_heater_off
So, at the end, my final question is… Can my automation evaluted as true if I restart HomeAssistant at 23:14, for example?