Condition

The Condition building block checks a condition in the middle of a sequence. If the condition is met, the next steps run. If it is not met, the sequence stops. Use it when the next steps should only run in certain situations, for example, only when someone is home.

Using this building block from the user interface

  1. Go to Settings > Automations & scenes and open an automation. To edit a script, open the Scripts tab and open 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 Condition.
  4. In Condition type, select the condition to check, for example, State, and fill in its options.
  5. Select Save.

Options in the UI

Condition type (Required)

The condition to check. Each condition type has its own options. For the available conditions, refer to the list of available conditions.

Using this building block in YAML

In YAML, use condition with the condition type and its options. For the available conditions, refer to the conditions page. This example only continues if Paulus is home:

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: "Check if Paulus is home"
condition: state
entity_id: device_tracker.paulus
state: "home"

condition can also be a list of conditions. The sequence then only continues if all conditions are met:

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: "Check if Paulus is home and the temperature is below 20"
condition:
  - condition: state
    entity_id: device_tracker.paulus
    state: "home"
  - condition: numeric_state
    entity_id: sensor.temperature
    below: 20

Options in YAML

condition string | list | template Required

The condition type, for example, state, followed by the options of that condition. Or a list of conditions, which must all be met, or a template.

Good to know

  • Condition only stops the sequence it is in. Inside another building block, it only stops the actions of that building block. For example, inside a Repeat building block, it only stops the current round of the repeat. Inside Choose, it only stops the actions of that option. Inside Run in parallel, it only stops its own branch.
  • To run different actions depending on whether the condition is met, use If-then or Choose instead.
  • The condition checks the state at the moment the step runs. It isn’t checked again later, so the sequence doesn’t continue when the condition is met later. For more, refer to Conditions check the current state.