Run in sequence
The Run in sequence building block groups actions that run one after the other. Each action starts after the previous one has finished. Use it to keep related actions together, so you can collapse them in the editor, or to run a group of actions in order inside Run in parallel.
Using this building block from the user interface
- Go to Settings > Automations & scenes and select an automation. To edit a script, go to the Scripts tab and select the script.
- In the Then do section of an automation, or the Sequence section of a script, select Add action.
- Select Blocks, then select Run in sequence.
- Inside the building block, select Add action, and add the actions of the group.
- Optional: To give the group a name, select Menu
> Rename. - Select Save.
Options in the UI
This building block has no options. You add the actions inside it.
Using this building block in YAML
In YAML, use sequence with a list of actions. To give the group a name, add an alias:
alias: "Turn on devices"
sequence:
- action: light.turn_on
target:
entity_id: light.ceiling
- action: siren.turn_on
target:
entity_id: siren.noise_maker
Options in YAML
Good to know
- The actions of an automation or script already run one after the other. Run in sequence doesn’t change that. It helps you organize them.
Examples
Automation: Turn on devices, then send notifications
When motion is detected, this automation runs two groups of actions: one that turns on devices, and one that sends notifications. The groups and their actions run one after the other, four actions in total.
-
Trigger: State changed
-
Entity:
binary_sensor.motion - To: On
-
Entity:
-
Action: Run in sequence, renamed to
Turn on devices-
Action: Turn on light
-
Target: Ceiling light (
light.ceiling)
-
Target: Ceiling light (
-
Action: Turn on siren
-
Target: Noise maker (
siren.noise_maker)
-
Target: Noise maker (
-
Action: Turn on light
-
Action: Run in sequence, renamed to
Send notifications-
Action: Send a notification message
-
Target: Person 1 device (
notify.person1_device) -
Message:
The motion sensor was triggered!
-
Target: Person 1 device (
-
Action: Send a notification message
-
Target: Person 2 device (
notify.person2_device) -
Message:
Oh oh, someone triggered the motion sensor...
-
Target: Person 2 device (
-
Action: Send a notification message
YAML example
triggers:
- trigger: state
entity_id: binary_sensor.motion
to: "on"
actions:
- alias: "Turn on devices"
sequence:
- action: light.turn_on
target:
entity_id: light.ceiling
- action: siren.turn_on
target:
entity_id: siren.noise_maker
- alias: "Send notifications"
sequence:
- action: notify.send_message
target:
entity_id: notify.person1_device
data:
message: "The motion sensor was triggered!"
- action: notify.send_message
target:
entity_id: notify.person2_device
data:
message: "Oh oh, someone triggered the motion sensor..."