Conditions

Conditions can be used within a 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] or automationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more] to prevent further execution. When a condition evaluates true, the script or automation will be executed. If any other value is returned, the script or automation stops executing. A condition will look at the system at that moment. For example, a condition can test if a switch is currently turned on or off.

Unlike a triggerA trigger is the part of an automation that makes the automation start when something specific happens, for example, when the sun sets, a door opens, or a button is pressed. [Learn more], which is always or, conditions are and by default - all conditions have to be true.

All conditions support an optional alias.

Logical conditions

AND condition

Test multiple conditions in one condition statement. Passes if all embedded conditions are true.

conditions:
  - alias: "Paulus home AND temperature below 20"
    condition: and
    conditions:
      - condition: state
        entity_id: "device_tracker.paulus"
        state: "home"
      - condition: numeric_state
        entity_id: "sensor.temperature"
        below: 20

If you do not want to combine AND and OR conditions, you can list them sequentially.

The following configuration works the same as the one listed above:

conditions:
  - condition: state
    entity_id: "device_tracker.paulus"
    state: "home"
  - condition: numeric_state
    entity_id: "sensor.temperature"
    below: 20

Currently you need to format your conditions like this to be able to edit them using the automations editor.

The AND condition also has a shorthand form. The following configuration works the same as the ones listed above:

conditions:
  alias: "Paulus home AND temperature below 20"
  - and:
    - condition: state
      entity_id: "device_tracker.paulus"
      state: "home"
    - condition: numeric_state
      entity_id: "sensor.temperature"
      below: 20

OR condition

Test multiple conditions in one condition statement. Passes if any embedded condition is true.

conditions:
  - alias: "Paulus home OR temperature below 20"
    condition: or
    conditions:
      - condition: state
        entity_id: "device_tracker.paulus"
        state: "home"
      - condition: numeric_state
        entity_id: "sensor.temperature"
        below: 20

The OR condition also has a shorthand form. The following configuration works the same as the one listed above:

conditions:
  - alias: "Paulus home OR temperature below 20"
    or:
      - condition: state
        entity_id: "device_tracker.paulus"
        state: "home"
      - condition: numeric_state
        entity_id: "sensor.temperature"
        below: 20

Mixed AND and OR conditions

Test multiple AND and OR conditions in one condition statement. Passes if any embedded condition is true. This allows you to mix several AND and OR conditions together.

conditions:
  - condition: and
    conditions:
      - condition: state
        entity_id: "device_tracker.paulus"
        state: "home"
      - condition: or
        conditions:
          - condition: state
            entity_id: sensor.weather_precip
            state: "rain"
          - condition: numeric_state
            entity_id: "sensor.temperature"
            below: 20

Or in shorthand form:

conditions:
  - and:
    - condition: state
      entity_id: "device_tracker.paulus"
      state: "home"
    - or:
      - condition: state
        entity_id: sensor.weather_precip
        state: "rain"
      - condition: numeric_state
        entity_id: "sensor.temperature"
        below: 20

NOT condition

Test multiple conditions in one condition statement. Passes if all embedded conditions are not true.

conditions:
  - alias: "Paulus not home AND alarm not disarmed"
    condition: not
    conditions:
      - condition: state
        entity_id: device_tracker.paulus
        state: "home"
      - condition: state
        entity_id: alarm_control_panel.home_alarm
        state: "disarmed"

The NOT condition also has a shorthand form. The following configuration works the same as the one listed above:

conditions:
  alias: "Paulus not home AND alarm not disarmed"
  not:
    - condition: state
      entity_id: device_tracker.paulus
      state: "home"
    - condition: state
      entity_id: alarm_control_panel.home_alarm
      state: disarmed

Types of conditions

A condition of an automation has a type that depends on the target of the condition, usually corresponding to the domain of the target. Conditions are grouped in the following main types.

For an overview of every condition across all integrations, refer to the list of available conditions.

Air quality conditions

For the full list of available conditions and its details, refer to the Air quality conditions.

Alarm control panel conditions

The available conditions are:

  • Alarm is armed (alarm_control_panel.is_armed).
  • Alarm is armed home (alarm_control_panel.is_armed_home).
  • Alarm is armed away (alarm_control_panel.is_armed_away).
  • Alarm is armed night (alarm_control_panel.is_armed_night).
  • Alarm is armed vacation (alarm_control_panel.is_armed_vacation).
  • Alarm is disarmed (alarm_control_panel.is_disarmed).
  • Alarm is triggered (alarm_control_panel.is_triggered).

For information about each condition, refer to the Alarm control panel conditions.

Assist satellite conditions

The available conditions are:

  • Satellite is idle (assist_satellite.is_idle).
  • Satellite is listening (assist_satellite.is_listening).
  • Satellite is processing (assist_satellite.is_processing).
  • Satellite is responding (assist_satellite.is_responding).

For information about each condition, refer to the Assist satellite conditions.

Battery conditions

For the full list of available conditions and its details, refer to the Battery conditions.

Calendar conditions

For the full list of available conditions and its details, refer to the Calendar conditions.

Climate conditions

Some of the available conditions are:

  • Thermostat is on (climate.is_on).
  • Thermostat is off (climate.is_off).
  • Thermostat is heating (climate.is_heating).
  • Thermostat is cooling (climate.is_cooling).
  • Thermostat is drying (climate.is_drying).

For the full list of available conditions and its details, refer to the Climate conditions.

Example: Continue only if the climate is heating

conditions:
  - condition: climate.is_heating
    target:
      entity_id: climate.living_room

Counter conditions

For the full list of available conditions and its details, refer to the Counter conditions.

Cover conditions

For the full list of available conditions and its details, refer to the Cover conditions.

Device conditions

For setup steps, YAML options, and examples for the Device condition, refer to Device.

Fan conditions

The available conditions are:

  • Fan is on (fan.is_on).
  • Fan is off (fan.is_off).

For information about each condition, refer to the Fan conditions.

Garage door conditions

For the full list of available conditions and details, refer to the Garage door conditions.

Humidifier conditions

Some of the available conditions are:

  • Humidifier is on (humidifier.is_on).
  • Humidifier is off (humidifier.is_off).
  • Humidifier is humidifying (humidifier.is_humidifying).
  • Humidifier is drying (humidifier.is_drying).

For the full list of available conditions and its details, refer to Humidifier conditions.

Humidity conditions

For the full list of available conditions and its details, refer to the Humidity conditions.

Lawn mower conditions

The available conditions are:

  • Lawn mower is mowing (lawn_mower.is_mowing).
  • Lawn mower is docked (lawn_mower.is_docked).
  • Lawn mower is paused (lawn_mower.is_paused).
  • Lawn mower is returning (lawn_mower.is_returning).
  • Lawn mower is encountering an error (lawn_mower.is_encountering_an_error).

For information about each condition, refer to the Lawn mower conditions.

Light conditions

The available conditions are:

  • Light is on (light.is_on).
  • Light is off (light.is_off).
  • Light is off (light.is_brightness).

For information about each condition, refer to the Light conditions.

Example: Continue only if the living room light is on

conditions:
  - condition: light.is_on
    target:
      entity_id: light.living_room

Lock conditions

The available conditions are:

  • Lock is locked (lock.is_locked).
  • Lock is unlocked (lock.is_unlocked).
  • Lock is open (lock.is_open).
  • Lock is jammed (lock.is_jammed).

For information about each condition, refer to the Lock conditions.

Media player conditions

Some of the available conditions are:

  • Media player is on (media_player.is_on).
  • Media player is off (media_player.is_off).
  • Media player is playing (media_player.is_playing).
  • Media player is paused (media_player.is_paused).
  • Media player is not playing (media_player.is_not_playing).

For information about each condition, refer to the Media player conditions.

Moisture conditions

For the full list of available conditions and its details, refer to the Moisture conditions.

Motion conditions

For the full list of available conditions and its details, refer to the Motion conditions.

Numeric state condition

For setup steps, YAML options, and examples for the Numeric state condition, refer to Numeric state.

Power condition

The available condition is: Power value (power.is_value).

For details, refer to the Power value condition page.

Remote conditions

For the full list of available conditions and its details, refer to the Remote conditions.

Schedule conditions

For the full list of available conditions and its details, refer to the Schedule conditions.

Select condition

The available condition is: Dropdown option is selected (select.is_option_selected).

For details, refer to the Dropdown option is selected condition page.

Siren conditions

The available conditions are:

  • Siren is on (siren.is_on).
  • Siren is off (siren.is_off).

For information about each condition, refer to Siren conditions.

State condition

For setup steps, YAML options, and examples for the State condition, refer to State.

Sun conditions

For setup steps, YAML options, and examples for the Sun condition, which checks the time before or after sunrise or sunset, refer to Sun. For the other sun conditions, refer to the list of Sun conditions.

Switch conditions

The available conditions are:

  • Switch is on (switch.is_on).
  • Switch is off (switch.is_off).

For information about each condition, refer to the Switch conditions.

Temperature condition

The available condition is: Temperature value (temperature.is_value).

For details, refer to the Temperature value condition page.

Template condition

For setup steps, YAML options, and examples for the Template condition, refer to Template.

Template condition shorthand notation

For the shorthand notation of the Template condition, refer to Shorthand notation.

Text condition

The available condition is: (text.is_equal_to).

For details, refer to the Text is equal to condition page.

Time condition

For setup steps, YAML options, and examples for the Time condition, refer to Time.

Timer conditions

For the full list of available conditions and its details, refer to the Timer conditions.

To-do list conditions

For the full list of available conditions and its details, refer to the To-do list conditions.

Triggered by condition

For setup steps, YAML options, and examples for the Triggered by condition, refer to Triggered by.

Update conditions

For the full list of available conditions and its details, refer to the Update conditions.

Vacuum conditions

The available Vacuum conditions are:

  • Vacuum is cleaning (vacuum.is_cleaning).
  • Vacuum is docked (vacuum.is_docked).
  • Vacuum is paused (vacuum.is_paused).
  • Vacuum is returning (vacuum.is_returning).
  • Vacuum is encountering an error (vacuum.is_encountering_an_error).

For information about adding vacuum conditions in an automation and examples, refer to Vacuum conditions.

Valve conditions

For the full list of available conditions and its details, refer to the Valve conditions.

Water heater conditions

For the full list of available conditions and its details, refer to the Water heater conditions.

Zone conditions

For setup steps, YAML options, and examples for the Zone condition, which checks whether an entity is in a zone, refer to Zone. For the other zone conditions, refer to the list of Zone conditions.

Examples

conditions:
  - condition: numeric_state
    entity_id: sun.sun
    value_template: "{{ state.attributes.elevation }}"
    below: 1
  - condition: state
    entity_id: light.living_room
    state: "off"
  - condition: time
    before: "23:00:00"
    after: "14:00:00"
  - condition: state
    entity_id: script.light_turned_off_5min
    state: "off"

Disabling a condition

Every individual condition can be disabled, without removing it. To do so, add enabled: false to the condition configuration.

This can be useful if you want to temporarily disable a condition, for example, for testing. A disabled condition will behave as if it were removed.

For example:

# This condition will always pass, as it is disabled.
conditions:
  - enabled: false
    condition: state
    entity_id: sun.sun
    state: "above_horizon"

Conditions can also be disabled based on limited templates or blueprint inputs.

blueprint:
  input:
    input_boolean:
      name: Boolean
      selector:
        boolean:
    input_number:
      name: Number
      selector:
        number:
          min: 0
          max: 100

  trigger_variables:
    _enable_number: !input input_number

  conditions:
    - condition: state
      entity_id: sun.sun
      state: "above_horizon"
      enabled: !input input_boolean
    - condition: state
      entity_id: sun.sun
      state: "below_horizon"
      enabled: "{{ _enable_number < 50 }}"