Multiple Actions with different delays in one Automation

Hi all,

I would like to model the following:

I have a motion sensor in the bathroom and would like ONE automation to do the following:

If no motion is detected:

  • turn off the lights after 5min
  • turn off the fan after 20min

It seems like the delay function I can use in the actions block is a root level element and therefore it gets applied to all actions which are defined? Or is this just a limitation of the UI that it gets rendered this way? But looking at the documentation (https://www.home-assistant.io/docs/scripts/#delay) it also looks like it is a root level element…

Thanks in advance,

Andreas

You can use choose in your action to create IF THEN ELIF ELSE like constructs.

But why do you need this? Can you not simply:
Trigger
Delay 5 min
Turn off light
Delay 15 min
Turn off fan

1 Like

Which would require two actions, or?

My current automation looks like this:

- id: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
  alias: shower.motion_clear.lights_off
  description: ''
  mode: single
  trigger:
  - type: no_motion
    platform: device
    device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    entity_id: binary_sensor.ms_3_motion
    domain: binary_sensor
    for: '00:05:00'
  action:
  - type: turn_off
    device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    entity_id: switch.ls_2
    domain: switch
  - type: turn_off
    device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    entity_id: switch.ls_1
    domain: switch

So I used for: '00:05:00' in the trigger definition… Which works fine if I don’t want to define 2 actions with different delays. The delay option in the action blocks seems to have the same restriction as I can only specify one which is applied the all actions…

If possible I would like to keep all actions which are triggered by ā€˜no_motion’ in one action…

Just put the delay in between the two actions:

- id: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
  alias: shower.motion_clear.lights_off
  description: ''
  mode: single
  trigger:
  - type: no_motion
    platform: device
    device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    entity_id: binary_sensor.ms_3_motion
    domain: binary_sensor
    for: '00:05:00'
  action:
  - type: turn_off
    device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    entity_id: switch.ls_2
    domain: switch
  - delay:
       minutes: 15 
  - type: turn_off
    device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    entity_id: switch.ls_1
    domain: switch
2 Likes

Ah thanks, for whatever reason I didn’t thought about the script just being processed sequentially and therefore I can just add the delays as needed in between the different actions.

So exactly also what @Burningstone said I first didnt get :slight_smile:

1 Like