Amalgamated Automation question

Hi all,

Just a quick question. Is it possible to stack actions withing an automation.
eg.
Turn sample light on
|
Delay for a set time
|
Turn on sample switch
|
Delay for a set time
|
Perform another task.

etc.

Obviously I know I can create multiple automations that are triggered by the actions of the previous command and build in a delay, I’m just wondering if I can amalgamate several automations into one.

Yes. The very first example in the documentation has an example. Automation actions - Home Assistant

I should have checked that. Okay, just to be sure, the following is perfectly legit.

- id: '1559390538796'
  alias: Morning
  description: Start of Holiday mode morning routine
  trigger:
  - at: 07:00
    platform: time
  condition: []
  action:
  - delay: 00:{{ '{:02}'.format(range(0,30) | random | int) }}:00
  - data:
      entity_id: light.spare_bedroom
    service: light.turn_on
  - delay: 00:{{ '{:02}'.format(range(0,10) | random | int) }}:00
  - data:
      entity_id: light.landing
    service: light.turn_on
  - delay: 00:{{ '{:02}'.format(range(0,10) | random | int) }}:00
  - data:
      entity_id: light.hall
    service: light.turn_on

I am not sure about the use of the template there. That is above my pay grade.

Ah okay. Nothing for it but to test I suppose :stuck_out_tongue:

Delay does support templates and your template does look valid except for one thing. It must be enclosed in quotes. e.g.

  - delay: "00:{{ '{:02}'.format(range(0,10) | random | int) }}:00"

See more examples here: https://www.home-assistant.io/docs/scripts/#delay

I entered the template as such when I created the automation directly in automations.yaml. Then I discovered that the automation editor will display the template anyway and removes the quotes. I’ve just tested it (sans quotes) and it appears to work as expected.

Is there a limit to the number of actions I can add to an automation?