Hi everyone. I have two automations. The first turns off a switch when another is turned on and the second attempt, which is the first switch, is only on 6:20 minutes. Is he well armed? Can it be done in a single automation? thanks
- id: '1638316271524'
alias: Activar Bomba cambio de agua
description: ''
trigger:
- platform: state
entity_id: switch.1
from: 'off'
to: 'on'
action:
- service: switch.turn_off
entity_id: switch.2
- alias: Manter Bomba cambio de agua
trigger:
- platform: state
entity_id: switch.1
to: "on"
for:
minutes: 6
seconds: 20
action:
- service: switch.turn_off
entity_id: switch.1
Yes, if you look at the trigger documentation you’ll see you can have multiple triggers. Merging these two won’t bring any advantages, but there’s no technical reason you can’t merge them.
only with templates if you are comfortable with them.
one way would be:
- id: '1638316271524'
alias: Activar Bomba cambio de agua
description: ''
trigger:
- platform: state
entity_id: switch.1
from: 'off'
to: 'on'
- platform: state
entity_id: switch.1
to: "on"
for:
minutes: 6
seconds: 20
action:
- service: switch.turn_off
data:
entity_id: >
{% if trigger.entity_id == 'switch.1' %}
switch.2
{% else %}
switch.1
{% endif %}
there are other ways to do it (shorten the template to one line with shorthand notation, add an “id” to the trigger and use that instead of the entity_id, etc) but they all use the same basic gist.