Multiple Triggered Automation

Hello!

I’ve been trying to create an automation that makes use of multiple triggers and a data_template in the action. It works… sort off…

Just as a example of what I aim to achieve and put in the automation

- id: '1587965772738'
  alias: Test Template
  description: ''
  trigger:
  - entity_id: light.study_room_toilet_lights
    from: 'off'
    platform: state
    to: 'on'
  - entity_id: light.study_room_lights
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data_template:
      message: '{{trigger.to_state.attributes.friendly_name}} just changed from {{
        trigger.from_state.state }} to {{ trigger.to_state.state }}

        '
    service: notify.mobile_app_iphone
  - delay: 00:00:10
  - data_template:
      entity_id: '{{ trigger.entity_id }}'
    service: light.turn_off

Now, if one of the lights is switched on, i get (as expected):

  1. Notification on my phone
  2. The light is switched off after 10s.

However, when one light is switched on and subsequently the other is switched on within 10s:

  1. The second light is switched off
  2. The first light remains on perpetually.

Is there some way that this can be done in a single automation? Or will I have to create an automation for each of the switches around?

Thanks in advance!

You’d need multiple automations as shown here.

The issue is that if your automation is re-triggered while waiting in a delay the delay is skipped and the actions continue from after the delay.

There was a PR to change this behaviour but it is complicated and may take some time to be done in small steps. Tinkerer has shown the best option for the moment.

Thank you both. :grinning: