Wait for time to pass (delay)
The Wait for time to pass (delay) building block pauses the automation or script for a set time. Use it when the next steps should run a while later, for example, to turn off a light 5 minutes after it turned on.
Using this building block from the user interface
- Go to Settings > Automations & scenes and open an automation. To edit a script, open the Scripts tab and open the script.
- In the Then do section of an automation, or the Sequence section of a script, select Add action.
- Select Blocks, then select Wait for time to pass (delay).
- In Duration, enter how long to wait.
- Select Save.
Options in the UI
Using this building block in YAML
In YAML, use delay. You can enter the duration in several formats:
- A number of seconds, for example,
5to wait 5 seconds, or1.5to wait 1.5 seconds. - A time in
HH:MMformat, for example,"01:00"to wait 1 hour. - A time in
HH:MM:SSformat, for example,"00:01:30"to wait 1 minute and 30 seconds. - A mapping with
days,hours,minutes,seconds, andmilliseconds. You can combine them, and you need at least one.
alias: "Wait 5 seconds"
delay: 5
delay:
minutes: 1
All formats accept templates. This example waits as many minutes as input_number.minute_delay is set to:
delay: "{{ states('input_number.minute_delay') | multiply(60) | int }}"
Options in YAML
How long to wait. Use a number of seconds, a time in HH:MM or HH:MM:SS format, or a mapping with days, hours, minutes, seconds, and milliseconds. All formats accept templates.
Good to know
- A delay in milliseconds is at least that long, but not exact.
- A delay with a template can only be edited in YAML.
- A restart of Home Assistant stops automations and scripts that are waiting. They don’t continue after the restart.
Examples
Automation: Turn off the light 5 minutes after the last motion
When the hallway motion sensor detects motion, this automation turns on the hallway light, waits 5 minutes, and turns the light off again. The automation uses the Restart mode: each time the sensor detects new motion, the automation starts over, and the 5 minutes start again. With the default Single mode, the light turns off 5 minutes after the first motion, even if the sensor detects new motion in the meantime.
-
Trigger: State changed
-
Entity: Hallway motion (
binary_sensor.hallway_motion) - To: Detected
-
Entity: Hallway motion (
-
Action: Turn on light
-
Target: Hallway light (
light.hallway)
-
Target: Hallway light (
-
Action: Wait for time to pass (delay)
-
Duration:
5minutes
-
Duration:
-
Action: Turn off light
-
Target: Hallway light (
light.hallway)
-
Target: Hallway light (
-
Mode: Restart. To change it, select Menu
> Change mode.
YAML example
alias: "Turn off the hallway light 5 minutes after the last motion"
mode: restart
triggers:
- trigger: state
entity_id: binary_sensor.hallway_motion
to: "on"
actions:
- action: light.turn_on
target:
entity_id: light.hallway
- delay:
minutes: 5
- action: light.turn_off
target:
entity_id: light.hallway