Hi guys, I have the following automation. it is pretty long and the only thing changed between each action the number of the timer in the topic. can someone help me template it so it will be shorter and will support adding more timers in the future? something like a ‘for’ loop that runs from 1 to 4…
Thanks in advanced for anyone who tries to help.
Naor
- alias: "Toggle The Timers"
id: 'gardentimerstoggle'
initial_state: true
trigger:
- platform: state
entity_id:
- input_boolean.raindelay
action:
- service: mqtt.publish
data_template:
topic: sonoff4chpro1/cmnd/timer1
payload: >
{% if is_state( 'input_boolean.raindelay' , 'on') %}
{"Arm":0}
{% elif is_state( 'input_boolean.raindelay' , 'off') %}
{"Arm":1}
{% endif %}
- service: mqtt.publish
data_template:
topic: sonoff4chpro1/cmnd/timer2
payload: >
{% if is_state( 'input_boolean.raindelay' , 'on') %}
{"Arm":0}
{% elif is_state( 'input_boolean.raindelay' , 'off') %}
{"Arm":1}
{% endif %}
- service: mqtt.publish
data_template:
topic: sonoff4chpro1/cmnd/timer3
payload: >
{% if is_state( 'input_boolean.raindelay' , 'on') %}
{"Arm":0}
{% elif is_state( 'input_boolean.raindelay' , 'off') %}
{"Arm":1}
{% endif %}
- service: mqtt.publish
data_template:
topic: sonoff4chpro1/cmnd/timer4
payload: >
{% if is_state( 'input_boolean.raindelay' , 'on') %}
{"Arm":0}
{% elif is_state( 'input_boolean.raindelay' , 'off') %}
{"Arm":1}
{% endif %}