Yeelilght timer in automation

Hi guys,

trying to set up flashing lights in case of opening one of two doors.
So far it’s working but now I would like to add a time that the lights stop flashing after 30 seconds (regardless of the state of the sensors)

this is the current code:

- id: '50'
  alias: 'Alarmblitze bei Tür oder Fensteröffnung'
  trigger:
    platform: state
    entity_id: 
    - binary_sensor.door_window_sensor_158d0001ab6a37
    - binary_sensor.door_window_sensor_158d0002157db4
    to: 'on'
  action:
  - service: yeelight.set_mode
    data:
      entity_id: 
        - light.stehlampe
        - light.terrasse_esstisch
        - light.terrasse_gaestezimmer
        - light.terrasse_grill
        - light.terrasse_lounge
        - light.terrasse_pool
        - light.terrasse_wohnzimmer
      mode: 'alarm'

How can I solve the issue? Would be great if the lamps would just switch off after 30 seconds.

Here is how you setup delay in automations, hope you get the idea :blush:

A better idea is to use a second automation. If your automation triggers again while it is in the delay it will cancel the delay and continue with the actions.

The second automation to turn off after a time can be set up like this

trigger:
  platform: state
  entity_id: blah.blah
  state: ‘on’
  for: 
    seconds: 30

Please excuse the wrong single quote type in the example above. I’m typing this on my phone.