Repeat multiple times

The Repeat multiple times building block runs a group of actions a set number of times. Use it when you know in advance how often the actions should run, for example, to flash a light 3 times.

Using this building block from the user interface

  1. Go to Settings > Automations & scenes and select an automation. To edit a script, go to the Scripts tab and select the script.
  2. In the Then do section of an automation, or the Sequence section of a script, select Add action.
  3. Select Blocks, then select Repeat multiple times.
  4. In Count, enter how many times to run the actions.
  5. Under Actions, select Add action, and add the actions to repeat.
  6. Select Save.

Options in the UI

Count (Required)

How many times to run the actions.

Actions (Required)

The actions to repeat.

Using this building block in YAML

In YAML, use repeat with count and sequence. The count can be a template. The template is rendered when the repeat starts. This example has two scripts. The second script calls the first one to flash the hallway light 3 times:

ScriptA script is a saved list of steps that runs when you start it, for example, from a dashboard, with Assist, or from an automation. Unlike an automation, a script has no triggers, so it doesn't start by itself. [Learn more]
flash_light:
  mode: restart
  sequence:
    - action: light.turn_on
      target:
        entity_id: "light.{{ light }}"
    - alias: "Cycle light 'count' times"
      repeat:
        count: "{{ count | int * 2 - 1 }}"
        sequence:
          - delay: 2
          - action: light.toggle
            target:
              entity_id: "light.{{ light }}"
flash_hallway_light:
  sequence:
    - alias: "Flash hallway light 3 times"
      action: script.flash_light
      data:
        light: hallway
        count: 3

Options in YAML

repeat map Required

The repeat settings.

count integer | template Required

How many times to run the actions. Can be a template.

sequence list Required

The actions to repeat.

Repeat variable

While the actions repeat, the repeat variable shows which round is running:

  • repeat.index: The number of the round: 1, 2, 3, and so on.
  • repeat.first: true during the first round.
  • repeat.last: true during the last round.

Good to know

  • You can use any building block inside the repeat, including another repeat.