State

The State condition checks whether an entityAn entity represents a sensor, actor, or function in Home Assistant. Entities are used to monitor physical properties or to control other entities. An entity is usually part of a device or a service. [Learn more] has a specific state right now. Use it when an automation should only continue in a certain situation. For example, the automation only continues when someone is home, or when a door is closed. It works with any entity, and it can also check an attribute instead of the main state.

With the For at least option, the condition also checks how long the entity has had that state. For example, you can check whether a door has been closed for at least 10 minutes.

Using this condition from the user interface

If you prefer building automations visually, Home Assistant walks you through this condition step by step. You pick what to check, tweak a few options, and save. No YAML knowledge required.

To use this condition in an automation:

  1. Go to Settings > Automations & scenes.
  2. Open an existing automation, or select Create automation > Create new automation.
  3. In the And if section, select Add condition.
  4. From the search box, search for and select State.
  5. In Entity, select the entity to check.
  6. Optional: In Attribute, select an attribute to check instead of the main state.
  7. In State, select the state that the entity must have. To allow several states, select more than one.
  8. Optional: In For at least, enter how long the entity must have had the state. This only works with one state. If you selected an Attribute, For at least isn’t available.
  9. Select Save.

Options in the UI

Entity (Required)

The entity to check.

Attribute (Optional)

An attribute of the entity to check instead of the main state.

State (Required)

The state, or the attribute value, that the entity must have. If you select several states, the condition passes if the entity has one of them.

For at least (Optional)

How long the entity must have had the state. By default, the condition doesn’t check how long. Only works with one state. Not available if you select an Attribute.

Using this condition in YAML

If you work directly in YAML, or you want to know exactly what Home Assistant does under the hood, this section has the technical reference. It lists the field names you use in YAML, their types, and which ones are required.

In YAML, use condition: state. A basic example looks like this:

ConditionConditions check whether something is true at that moment, for example, whether a door is closed. You can use them in automations and scripts. If a condition is not met, the actions that come after it in the same sequence do not run. At the top level of an automation or script, this stops the automation or script. [Learn more]
condition: state
entity_id: person.sam
state: "home"

This passes when Sam is home.

Options in YAML

YAML sometimes provides additional options for more complex use cases that are not available through the UI.

condition string Required

The condition type. For this condition, use state.

entity_id string | list Required

The ID of the entity, or a list of entity IDs, to check.

state string | integer | float | boolean | list Required

The state, or the attribute value, that the entity must have. Use a list to allow several states. Instead of a fixed value, you can use the entity ID of an input_boolean, input_datetime, input_number, input_select, or input_text helper. The condition then compares with the current state of that helper. The main state is always text. An attribute value keeps its own type, so write it the same way. For example, write a number or true without quotes.

attribute string (Optional)

An attribute of the entity to check instead of the main state.

match string (Optional, default: all)

When you check several entities, whether all of them (all) or at least one of them (any) must have the state. This option is available in YAML only.

for string (Optional)

How long the entity must have had the state. Accepts a duration string in HH:MM:SS format, or a time period mapping in hours, minutes, and seconds. You can use a template. Can’t be combined with attribute, a list of states, or a helper entity as the state.

You can use templates in a time period mapping for for. Home Assistant evaluates the templates when it tests the condition. In this example, it gets the number of minutes and seconds from number helpers. If the helpers are set to 5 and 30, the entity must have had the specified state for at least 5 minutes and 30 seconds.

ConditionConditions check whether something is true at that moment, for example, whether a door is closed. You can use them in automations and scripts. If a condition is not met, the actions that come after it in the same sequence do not run. At the top level of an automation or script, this stops the automation or script. [Learn more]
condition: state
entity_id: device_tracker.paulus
state: "home"
for:
  minutes: "{{ states('input_number.lock_min') | int }}"
  seconds: "{{ states('input_number.lock_sec') | int }}"

The following example passes if at least one of two motion sensors detects motion:

ConditionConditions check whether something is true at that moment, for example, whether a door is closed. You can use them in automations and scripts. If a condition is not met, the actions that come after it in the same sequence do not run. At the top level of an automation or script, this stops the automation or script. [Learn more]
condition: state
entity_id:
  - binary_sensor.motion_sensor_left
  - binary_sensor.motion_sensor_right
match: any
state: "on"

If an attribute value is itself a list, put that list inside another list. Otherwise, the condition reads the values as several possible states. The following example passes only if the fan_modes attribute is exactly ["auto", "low"]:

ConditionConditions check whether something is true at that moment, for example, whether a door is closed. You can use them in automations and scripts. If a condition is not met, the actions that come after it in the same sequence do not run. At the top level of an automation or script, this stops the automation or script. [Learn more]
condition: state
entity_id: climate.living_room_thermostat
attribute: fan_modes
state:
  - - "auto"
    - "low"

Targets of the condition

This condition checks one or more entities:

  • Use the UI option Entity, or the YAML option entity_id, to check one entity.
  • To check more than one entity, use a list of entity_id values in YAML. In the UI, add one State condition per entity.

Good to know

  • The condition compares the state exactly. To check whether an entity is unavailable (unavailable) or has an unknown state (unknown), select or enter those states. Otherwise, an unavailable entity doesn’t pass.
  • If the entity doesn’t exist, the condition fails with an error. The error is shown in the trace.
  • If you use a helper entity as the state, and the helper doesn’t exist, the condition fails with an error. The error is shown in the trace.
  • If you select an Attribute that the entity doesn’t have, the condition doesn’t pass.
  • For at least (for) only works with one state. If you select an Attribute, For at least isn’t available. With several states, or with a helper entity as the state, Home Assistant shows an error when you save the automation.
  • After Home Assistant restarts, For at least counts from the moment the entity was loaded again.
  • To check entities of a specific type, conditions such as Light is on can be easier to set up. For all conditions, refer to the list of available conditions.
  • To check whether a numeric value is above or below a limit, use the Numeric state condition.

Try it yourself

Ready to test this? Go to Settings > Automations & scenes, open an automation, and add this condition. Trigger the automation with and without the condition met, and watch whether it continues or stops.

More examples

Real scenarios where this condition gates an automation. Copy any example and adapt it to your setup. In the visual editor, select the UI options listed in the example or paste the YAML code.

Tip

You don’t need to edit YAML to use these examples. Copy a YAML snippet from this page, open the visual automation editor in Home Assistant, and press Ctrl+V (or Cmd+V on Mac). Home Assistant automatically converts the pasted YAML into the visual editor format, whether it’s a full automation, a single trigger, a condition, or an action.

Automation: only send a laundry notification when someone is home

When the washing machine finishes, this automation sends a notification, but only if Sam is home to take out the laundry.

  • Trigger: State changed
    • Entity: Washing machine running (binary_sensor.washing_machine_running)
    • From: Running
    • To: Not running
  • Condition: State
    • Entity: Sam (person.sam)
    • State: Home
  • Action: Send a notification message
    • Target: My Device (notify.my_device)
YAML example for a laundry notification when someone is home
AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
alias: "Laundry is done"
triggers:
  - trigger: state
    entity_id: binary_sensor.washing_machine_running
    from: "on"
    to: "off"
conditions:
  - condition: state
    entity_id: person.sam
    state: "home"
actions:
  - action: notify.send_message
    target:
      entity_id: notify.my_device
    data:
      message: "The laundry is done."

Automation: lock the front door at night if it has been closed for a while

At 23:00, this automation locks the front door, but only if the door has been closed for at least 10 minutes. The 10 minutes make sure that nobody is still going in or out when the door locks.

  • Trigger: Time
    • At time: 23:00:00
  • Condition: State
    • Entity: Front door (binary_sensor.front_door)
    • State: Closed
    • For at least: 10 minutes
  • Action: Lock lock
    • Target: Front door lock (lock.front_door)
YAML example for locking the front door at night
AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
alias: "Lock the front door at night"
triggers:
  - trigger: time
    at: "23:00:00"
conditions:
  - condition: state
    entity_id: binary_sensor.front_door
    state: "off"
    for: "00:10:00"
actions:
  - action: lock.lock
    target:
      entity_id: lock.front_door

Still stuck?

The Home Assistant community is quick to help: join Discord for real-time chat, post on the community forum with the condition you’re using and what you expected to happen, or share on our subreddit /r/homeassistant.

Tip

AI assistants like ChatGPT or Claude can also explain conditions or suggest the right one when you describe what you want in plain language.

Related conditions

Explore related conditions:

  • Light is on: Tests if one or more lights are on.

  • Is in zone: Tests if one or more people or device trackers are in a zone.