I struggle with this every time I try to do something new too. I tried to do what youâre doing but gave up as I couldnât make it behave how I wanted. I donât have the code any more, but it was basically looking to turn the system on if the temperature got above 24 or whatever Iâd set it for. And I think that worked as long as HA was running at the moment that it went from less than or equal to 24 to greater than 24. Whereas I was wanting it to action at anytime if it was above 24. I understand now that thatâs not how itâs supposed to behave but it still didnât do what I wanted so I changed it.
Now I just trigger the Automation to run every 15 mins as I figured the temperature doesnât change that quickly inside.
Automation code:
alias: AC Downstairs Cool (Auto)
description: ''
trigger:
- platform: time_pattern
minutes: /15
condition: []
action:
- service: script.ac_downstairs_set_cool_condition
mode: single
and it runs a Script that has conditions that let it run the actions or not
Script 1 code:
alias: Set AC Downstairs to Cool Conditions
sequence:
- delay: 5
- condition: state
entity_id: input_boolean.ac_auto
state: 'on'
for:
hours: 0
minutes: 0
seconds: 0
milliseconds: 0
- condition: template
value_template: '{{ not is_state("climate.d_stairs", "cool") }}'
- condition: or
conditions:
- condition: template
value_template: >-
{{(state_attr("climate.kitchen", "current_temperature") | float) >=
(states.input_number.ac_down_max.state | float)}}
- condition: template
value_template: >-
{{(state_attr("climate.family", "current_temperature") | float) >=
(states.input_number.ac_down_max.state | float)}}
- condition: template
value_template: >-
{{(state_attr("climate.lounge", "current_temperature") | float) >=
(states.input_number.ac_down_max.state | float)}}
- condition: template
value_template: >-
{{(state_attr("climate.study", "current_temperature") | float) >=
(states.input_number.ac_down_max.state | float)}}
- service: script.ac_downstairs_set_cool
mode: single
And finally, that calls a second Script that actually runs the actions.
Script 2 code:
alias: Set AC Downstairs To Cool
sequence:
- service: climate.set_hvac_mode
data:
hvac_mode: cool
target:
entity_id: climate.d_stairs
- service: climate.set_fan_mode
target:
entity_id: climate.d_stairs
data:
fan_mode: low
- service: climate.set_temperature
data_template:
entity_id:
- climate.family
- climate.kitchen
- climate.lounge
- climate.study
temperature: '{{states("input_number.ac_down_max") | int}}'
mode: single
To explain that code.
I have a variable input_boolean.ac_auto
that I can use to turn HAâs automation of the AC system on or off if I want to have manual control over it for some reason. I also have some input_number
variables for the upper and lower temperatures I want each of my two AC systems to trigger at as I got sick of adjusting the code and it also makes it easier to adjust all the zones temperatures at the same time.
Variable code (in the configuration.yaml
):
input_boolean:
ac_auto:
name: AC Auto
input_number:
ac_up_min:
name: Upstairs Min
min: 16
max: 32
step: 1
ac_up_max:
name: Upstairs Max
min: 16
max: 32
step: 1
ac_down_min:
name: Downstairs Min
min: 16
max: 32
step: 1
ac_down_max:
name: Downstairs Max
min: 16
max: 32
step: 1
The reason I broke it into two Scripts was so that I can call the Actions with or without Conditions. Specifically, when the Automation runs every 15 mins, I want the Conditions to only allow it to running if itâs above the desired temperature, not already turned on and itâs in Auto mode. However, if I adjust the temperature sliders in HA, I want that to be immediately enforced irrespective of the conditions.
Automation for triggering on set temperature sliders being changed:
alias: AC Downstairs Cool (Manual)
description: ''
trigger:
- platform: state
entity_id: input_number.ac_down_max
condition: []
action:
- service: script.ac_downstairs_set_cool
mode: single
My suggestion would be to use the GUI rather than the direct YAML and then if you canât do what you need in the GUI take what youâve already created and add the extra. i.e. the template stuff youâll need to code.
The Developer Tools section in HA is very helpful too.