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:
- Go to Settings > Automations & scenes.
- Open an existing automation, or select Create automation > Create new automation.
- In the And if section, select Add condition.
- From the search box, search for and select State.
- In Entity, select the entity to check.
- Optional: In Attribute, select an attribute to check instead of the main state.
- In State, select the state that the entity must have. To allow several states, select more than one.
- 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.
- Select Save.
Options in the UI
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.
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:
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.
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.
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.
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.
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:
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"]:
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_idvalues 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.
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
-
Entity: Washing machine running (
-
Condition: State
-
Entity: Sam (
person.sam) - State: Home
-
Entity: Sam (
-
Action: Send a notification message
-
Target: My Device (
notify.my_device)
-
Target: My Device (
YAML example for a laundry notification when someone is home
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
-
Entity: Front door (
-
Action: Lock lock
-
Target: Front door lock (
lock.front_door)
-
Target: Front door lock (
YAML example for locking the front door at night
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.
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.