Let’s assume you create an input_boolean
to indicate when away temperature should run, and it’s called input_boolean.enable_away_temperature
. To make this an “easy” single automation, we’ll use a choose block.
- alias: Away temperature
trigger:
# Any time the temperature inside or outside changes, check the conditions
- platform: state
entity_id: sensor.outside_temperature
- platform: state
entity_id: sensor.inside_temperature
# Also check on HA startup, or when you reload automations
- platform: homeassistant
event: start
- platform: event
event_type: automation_reloaded
condition:
# Only run when enabled
- condition: state
entity_id: input_boolean.enable_away_temperature
state: 'on'
# Only run if it's below 10 degrees outside
- condition: numeric_state
entity_id: sensor.outside_temperature
below: 10
action:
- choose:
- conditions:
# The heater must be off
- condition: state
entity_id: switch.heater
state: 'off'
# And inside is less than three degrees warmer than inside
- condition: template
value_template: "{{ states('sensor.inside_temperature')|float - states('sensor.outside_temperature')|float < 3}}"
sequence:
# Turn on the heater
- service: switch.turn_on
entity_id: switch.heater
- conditions:
# The heater is on
- condition: state
entity_id: switch.heater
state: 'on'
# It's more than 5 degrees warmer inside than out
- condition: template
value_template: "{{ states('sensor.inside_temperature')|float - states('sensor.outside_temperature')|float > 5}}"
sequence:
# Turn off the heater
- service: switch.turn_off
entity_id: switch.heater
Of course, if it’s -5 outside, this would let the house get below freezing. You could add some more logic to the templates to handle that. For example
value_template: "{{ (states('sensor.inside_temperature')|float - states('sensor.outside_temperature')|float < 3) or (states('sensor.inside_temperature')|float < 5) }}"
and
value_template: "{{ (states('sensor.inside_temperature')|float - states('sensor.outside_temperature')|float > 5) and (states('sensor.inside_temperature')|float > 5) }}"
That will ensure that the inside temperature never gets below 5 degrees.