Two automations in one?

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.

I’d do it with the trigger id and a choose block.

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.

something like above would do the same

Only if the only time switch 2 was turned on would be if switch 1 turned on.

if switch 2 gets turned on outside of the automation then the automation would never trigger and switch 1 would never get turned off.

then i’m reading his requirements wrong :slight_smile:

You might be correct but I didn’t get that from the description or the two automations he posted.

  - id: '1638316271524'
    alias: Activar Manter Bomba cambio de agua
    description: ''
    trigger:
      - id: '2'
        platform: state
        entity_id: switch.1
        from: 'off'
        to: 'on'
      - id: '1'
        platform: state
        entity_id: switch.1
        to: 'on'
        for:
          minutes: 6
          seconds: 20
    action:
      - service: switch.turn_off
        target:
          entity_id: 'switch.{{ trigger.id }}'

Thanks for the help. It would look like this. I turn on at 7:00 p.m. and there switch 2 turns off but switch 1 only remains on for 6:20

It is possible that it turns on at 7:00 p.m. but Monday, Wednesday and Friday for example?

  - alias: Comenzar cambio   
    trigger:
      - platform: time
        at: "19:00"
    action:    
      - service: switch.turn_on
        entity_id: switch.enchufe_retorno_reposicion


  - id: '1638316271524'
    alias: Activar Bomba cambio de agua
    description: ''
    trigger:
    - platform: state
      entity_id: switch.enchufe_retorno_reposicion
      from: 'off'
      to: 'on'
    action:
    - service: switch.turn_off
      entity_id: switch.10000a5f83
    - delay:
      hours: 0
      minutes: 6
      seconds: 20
      milliseconds: 0
    - service: switch.turn_off
      entity_id: switch.enchufe_retorno_reposicion

trigger:
  - platform: time
    at: '19:00:00'
condition:
  - condition: time
    weekday:
      - mon
      - wed
      - fri
action:    
  - service: switch.turn_on
    entity_id: switch.enchufe_retorno_reposicion
  - service: switch.turn_off
    entity_id: switch.10000a5f83
  - delay:
    hours: 0
    minutes: 6
    seconds: 20
    milliseconds: 0
  - service: switch.turn_off
     entity_id: switch.enchufe_retorno_reposicion

i’m having troubles with identiation here :slight_smile:

Thanks so much for the help

So I am well identified. If it doesn’t throw an error in the delay

  - alias: Cambio de agua
    trigger:
      - platform: time
        at: '19:00:00'
    condition:
      - condition: time
        weekday:
          - mon
          - wed
          - fri
    action:    
      - service: switch.turn_on
        entity_id: switch.enchufe_retorno_reposicion
      - service: switch.turn_off
        entity_id: switch.10000a5f83
      - delay:
          hours: 0
          minutes: 6
          seconds: 20
          milliseconds: 0
      - service: switch.turn_off
        entity_id: switch.enchufe_retorno_reposicion