I have an away mode set up that puts a manual thermostat into an “away” mode (think: house doesn’t get above 30 celsius or below 16 celsius) when I’m gone. However, I am trying to set up a way to trigger it so that the away mode shuts off as much as an hour before I return home so that the house is actually warm.
I’ve created the below automation; I get an error at the Delay portion. Is Delay not able to use if/elif statements, and if so then do you guys have some advice on what I’m trying to do?
- id: returninghome
alias: Returning Home Mode
trigger:
- platform: state
entity_id: input_select.tam_status, input_select.sbm_status
to: 'Travelling Home'
condition:
- condition: state
entity_id: input_select.family_status
state: "Away"
- condition: template
value_template: "{{ (states('input_number.thermostat_temp') | int - state_attr('climate.upstairs', 'temperature') |int ) | abs > 3 }}"
action:
- service: homeassistant.update_entity
data_template:
entity_id: >
{% if trigger.entity_id == 'input_select.tam_status' %}
sensor.tam_travel_home
{% elif trigger.entity_id == 'input_select.sbm_status' %}
sensor.sbm_travel_home
{% endif %}
- delay: >
{% if trigger.entity_id == 'input_select.tam_status' and (state_attr('sensor.tam_travel_home','duration') | replace(" mins","") | int < 60 | int) %}
minutes: 0
{% elif trigger.entity_id == 'input_select.tam_status' and (state_attr('sensor.tam_travel_home','duration') | replace(" mins","") | int > 60 | int) %}
minutes: "{{ (state_attr('sensor.tam_travel_home','duration') | replace(' mins','' | int - 60 | int }}"
{% elif trigger.entity_id == 'input_select.sbm_status' and (state_attr('sensor.sbm_travel_home','duration') | replace(" mins","") | int < 60 | int) %}
minutes: 0
{% elif trigger.entity_id == 'input_select.sbm_status' and (state_attr('sensor.sbm_travel_home','duration') | replace(" mins","") | int > 60 | int) %}
minutes: "{{ (state_attr('sensor.sbm_travel_home','duration') | replace(' mins','' | int - 60 | int }}"
{% endif %}
- service: input_boolean.turn_off
entity_id: input_boolean.thermostat_away