I have currently a dozen turn_on_xxx and turn_off_xxx scripts. Below is just a sample.
As you can see they all do the same action different times.
turn_on_xxx
set swtich to on
start timer
send notification
turn_off_xxx
set swtich to off
stop timer
send notification
Is there a way to template the above 3 action to just have only 2 scripts turn_on_xxx and turn_off_xxx
automation:
- id: start_scenes
initial_state: 'true'
alias: 'start scenes'
trigger:
- platform: state
entity_id: switch.stp_keuken_microgolf,switch.stp_keuken_oven
from: 'off'
to: 'on'
action:
- service: python_script.easyplus
data_template:
script_id: "turn_on_{{ trigger.to_state.name }"
- id: stop_scenes
initial_state: 'true'
alias: 'stop scenes manual'
trigger:
- platform: state
entity_id: switch.stp_keuken_microgolf,switch.stp_keuken_oven
from: 'on'
to: 'off'
action:
- service_template: "script.turn_off_{{ trigger.to_state.name }}"
script:
turn_on_microgolf:
sequence:
- service: homeassistant.turn_on
entity_id: switch.stp_keuken_microgolf
- service: timer.start
entity_id: timer.microgolf
- delay:
seconds: 4
- service: notify.telegram
data_template:
message: 'microgolf program: {{states.switch.stp_keuken_microgolf.state}}'
turn_off_microgolf:
sequence:
- service: homeassistant.turn_off
entity_id: switch.stp_keuken_microgolf
- service: timer.cancel
entity_id: timer.microgolf
- delay:
seconds: 4
- service: notify.telegram
data_template:
message: 'microgolf program: {{states.switch.stp_keuken_microgolf.state}}'
turn_on_oven:
sequence:
- service: homeassistant.turn_on
entity_id: switch.stp_keuken_oven
- service: timer.start
entity_id: timer.oven
- delay:
seconds: 4
- service: notify.telegram
data_template:
message: 'oven program: {{states.switch.stp_keuken_oven.state}}'
turn_off_oven:
sequence:
- service: homeassistant.turn_off
entity_id: switch.stp_keuken_oven
- service: timer.cancel
entity_id: timer.oven
- delay:
seconds: 4
- service: notify.telegram
data_template:
message: 'oven program: {{states.switch.stp_keuken_oven.state}}'