Building blocks in automations and scripts

When an automation or script runs, it goes through a list of steps. Each step is an action or a building block:

  • A building block controls whether, when, and in which order the other steps run. It can check a condition, wait, repeat steps, choose between steps, or run steps at the same time.
  • An action makes something happen, for example, turning on a light or sending a notification. For more about actions, refer to Actions in automations and scripts.

Automations and scripts use the same building blocks.

How automations and scripts run their steps

When an automation starts, it first checks its conditions under And if. If they are met, it goes through the steps under Then do, from top to bottom. A script has no conditions section, so it goes through its steps under Sequence right away.

The difference is when they run: an automation runs by itself when one of its triggers reacts, and a script runs when you start it, for example, from a dashboard, from an automation, or with Assist. For more about the difference, refer to Concepts and terminology.

To add a step in the editor, select Add action. To add a building block, select Blocks in that dialog. In YAML, you write actions and building blocks in the same list. For details, refer to Writing steps in YAML.

For how to create scripts, pass them values, and wait for them to finish, refer to Scripts. For scripts in YAML, refer to the Scripts integration.

Available building blocks

Each building block has its own page with its options and examples, grouped by categories in the list of building blocks.

Writing steps in YAML

In YAML, the steps are a list under actions: in an automation, or under sequence: in a script. If there is only one step, you can leave out the list.

Every step can have an alias. The alias is the name of the step that the editor and the trace show. In the editor, you set it with Rename.

In an automation, the steps go under actions::

AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
actions:
  - alias: "Turn on ceiling light"
    action: light.turn_on
    target:
      entity_id: light.ceiling
  - alias: "Notify that ceiling light is turned on"
    action: notify.notify
    data:
      message: "Turned on the ceiling light!"

In a script, the same steps go under sequence::

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]
sequence:
  - alias: "Turn on ceiling light"
    action: light.turn_on
    target:
      entity_id: light.ceiling
  - alias: "Notify that ceiling light is turned on"
    action: notify.notify
    data:
      message: "Turned on the ceiling light!"

In an automation, templates in the steps can use the trigger variable, which describes what started the automation. For details, refer to available trigger data.

Options for any step

These options work on every step, both actions and building blocks. The only exception is Continue on error, which conditions don’t have.

Continuing when a step fails

By default, an automation or script stops when a step fails. The run is marked as failed, and the error is logged. If a step can fail without affecting the rest, for example, a notification to an unreliable service, you can continue with the next step instead.

In the editor, in the Menu of the step, select Continue on error. For details, refer to Continuing after an action fails.

In YAML, add continue_on_error: true to the step:

ActionAn action makes Home Assistant do something, for example, turn on a light, send a notification, or activate a scene. Automations and scripts run a list of actions. [Learn more]
- alias: "If this one fails..."
  continue_on_error: true
  action: notify.super_unreliable_service_provider
  data:
    message: "I'm going to error out..."
  • alias: "This one still runs" action: persistent_notification.create data: title: "Hi there!" message: "I'm fine…"

Continue on error doesn’t ignore errors in the configuration, such as a broken template. The error is still shown in the trace and in the logs.

An action whose target is unavailable or doesn’t exist doesn’t fail. Home Assistant skips that target and logs a warning, so the next step runs even without Continue on error. The action does fail if an entity that you selected directly doesn’t support it, or if the action should return response data and none of its targets match.

Turning off a step

To try an automation or script without one of its steps, turn the step off instead of deleting it. Home Assistant skips it until you turn it on again.

In the editor, in the Menu of the step, select Disable. For details, refer to Turning off a trigger, condition, or action.

In YAML, add enabled: false to the step:

AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
actions:
  # This step is skipped.
  - enabled: false
    alias: "Notify that the ceiling light is being turned on"
    action: notify.notify
    data:
      message: "Turning on the ceiling light!"

This step runs.

  • alias: "Turn on the ceiling light" action: light.turn_on target: entity_id: light.ceiling

enabled can also be a limited template, which can’t use the state of entities. In a blueprintA blueprint is a script, automation, or template entity configuration with certain parts marked as configurable. This allows you to create multiple scripts, automations, or template entities based on the same blueprint, with each having its own configuration-specific settings. Blueprints are shared by the community on the blueprints exchange in the forum. [Learn more], it can be a blueprint input. Home Assistant checks the value each time the step is about to run.

actions:
  - delay: "0:35"
    enabled: !input input_boolean