I have seen a couple of requests similar to mine, but I have no experience and cannot apply them, so I ask for your help.
I have an input_select with three modes and I created three automations. Right now, when I select one, I run its automation.
It works, but I would like to merge everything into one automation and when the state of the input_select changes, execute the correct condition. So when I restart home assistannt, I will be able to run this automation and pick up exactly where I was before the restart.
#--------------------------------------------------------------------------------------------
# se viene selezionato "programmazione"
- alias: modalita programmazione
trigger:
platform: state
entity_id: input_select.modalita_riscaldamento
to: "programmazione"
action:
# attivo la programmazione
- service: switch.turn_on
entity_id: switch.schedule_schedule_riscaldamento_termosifoni_lavorativi
- service: switch.turn_on
entity_id: switch.schedule_schedule_riscaldamento_termosifoni_festivi
#---------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------
# se viene selezionato "manuale"
# faccio alcune solo una volta appena viene selezionata la modalitĂ manuale
- alias: modalita manuale prima volta
trigger:
- platform: state
entity_id: input_select.modalita_riscaldamento
to: "manuale"
action:
- data_template:
#datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
#Imposto l'ora di fine un'ora avanti
datetime: "{{ ( now().timestamp() + 60 | float * 60 ) | timestamp_custom(\"%Y-%m-%d %H:%M:%S\") }}"
entity_id: input_datetime.ora_fine_accensione_manuale
service: input_datetime.set_datetime
#spengo la programmazione
- service: switch.turn_off
entity_id: switch.schedule_schedule_riscaldamento_termosifoni_lavorativi
- service: switch.turn_off
entity_id: switch.schedule_schedule_riscaldamento_termosifoni_festivi
#accendo manualmente il termostato
- service: climate.turn_on
entity_id: climate.riscaldamento_termosifoni
# controllo ogni minuto se siamo arrivati alla scadena della mosalitĂ manuale
- alias: modalita manuale ogni minuto
trigger:
- platform: state
entity_id: input_select.modalita_riscaldamento
to: "manuale"
- platform: time_pattern
minutes: "/1"
action:
- condition: and
conditions:
- condition: template
value_template: "{{ states.input_datetime.ora_fine_accensione_manuale.attributes.timestamp | timestamp_custom(\"%H:%M\", false) < states.sensor.time.state }}"
- service: input_select.select_option
data:
entity_id: input_select.modalita_riscaldamento
option: programmazione
#---------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------
# se viene selezionato "off"
- alias: modalita off
trigger:
platform: state
entity_id: input_select.modalita_riscaldamento
to: "off"
action:
# selezione OFF: spengo il termostato e disattivo la programmazione
- service: climate.turn_off
entity_id: climate.riscaldamento_termosifoni
- service: switch.turn_off
entity_id: switch.schedule_schedule_riscaldamento_termosifoni_lavorativi
- service: switch.turn_off
entity_id: switch.schedule_schedule_riscaldamento_termosifoni_festivi
#---------------------------------------------------------------------------------------------