State

The State trigger is useful when you want an automation to react to a change in an entity or one of its attributes. Use it when you care about a device turning on or off, a door opening or closing, or a person arriving home.

Using this trigger from the user interface

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

To use this trigger in an automation:

  1. Go to Settings > Automations & scenes.
  2. Open an existing automation, or select Create automation > Create new automation.
  3. In the When section, select Add trigger.
  4. Select the type of trigger to add.
  5. Select State.
  6. In Entity, select the entity whose state Home Assistant should watch.
  7. Optional: In Attribute, select an attribute instead of the main state.
  8. Optional: In From and To, limit which changes should match.
  9. Optional: In For, enter how long the new state must last before the trigger fires.
  10. Select Save.

Options in the UI

Attribute

Optional entity attribute to watch instead of the main state.

From

Optional starting state to match.

To

Optional new state to match.

For

Optional amount of time the new state must last before the trigger fires.

Using this trigger 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 trigger: state. A basic example looks like this:

TriggerA trigger is a set of values or conditions of a platform that are defined to cause an automation to run. [Learn more]
trigger: state
entity_id: binary_sensor.front_door
to: "on"

This runs when the front door changes to on.

Options in YAML

trigger string Required

The trigger type. For this trigger, use state.

entity_id string Required

The entity to watch.

from string

Optional starting state to match. You can use one state or a list of states.

to string

Optional new state to match. You can use one state or a list of states.

not_from string

Optional starting state to exclude. You can use one state or a list of states. YAML only.

not_to string

Optional new state to exclude. You can use one state or a list of states. YAML only.

attribute string

Optional attribute to watch instead of the main state.

for string

Optional time the new state must remain unchanged before the trigger fires.

If you want to trigger on all state changes but ignore attribute-only changes, set one of from, to, not_from, or not_to to an empty value in YAML.

In YAML, from, to, not_from, and not_to each accept either one state or a list of states.

Targets of the trigger

This trigger watches one or more entities selected by entity_id.

  • Use a single entity_id to watch one entity.
  • Use a list of entity_id values in YAML to watch more than one entity.

Good to know

  • If you do not set From or To, this trigger fires on all state changes. It also fires when only an attribute changes.
  • If you set From, To, not_from, or not_to, attribute-only changes do not fire the trigger.
  • You cannot combine from with not_from, or to with not_to.
  • If you use for, the timer resets if Home Assistant restarts or automations reload.

Try it yourself

Ready to test this? Go to Settings > Automations & scenes, create a new automation, and add this trigger. Save the automation, then change the state of the targeted entity to watch the trigger fire on your actual entitiesAn 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].

More examples

Real scenarios where this trigger fires in automations and scripts. Copy any example and adapt it to your setup.

Tip

You don’t need to edit YAML to use these examples. Copy a YAML snippet from this page, open the 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: send a reminder when a door stays open for 5 minutes

If a door stays open longer than expected, this automation sends a message to your phone.

  • Trigger: State
    • Entity: Back door sensor (binary_sensor.back_door)
    • To: on
    • For: 5 minutes
  • Action: Send a notification message
    • Target: My Device (notify.my_device)
YAML example for a door-left-open reminder
AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
alias: "Remind me when the back door stays open"
triggers:
  - trigger: state
    entity_id: binary_sensor.back_door
    to: "on"
    for: "00:05:00"
actions:
  - action: notify.send_message
    target:
      entity_id: notify.my_device
    data:
      message: "The back door has been open for 5 minutes."

Automation: send a notification when someone arrives home

If you want a message when a person arrives, this automation watches for a state change to home.

  • Trigger: State
    • Entity: Person entity (person.sam)
    • To: home
  • Action: Send a notification message
    • Target: My Device (notify.my_device)
YAML example for an arrival notification
AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
alias: "Notify me when Sam arrives home"
triggers:
  - trigger: state
    entity_id: person.sam
    to: "home"
actions:
  - action: notify.send_message
    target:
      entity_id: notify.my_device
    data:
      message: "Sam has arrived home."

Still stuck?

The Home Assistant community is quick to help: join Discord for real-time chat, post on the community forum with the trigger 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 triggers or suggest the right one when you describe what you want in plain language.

Related triggers

These triggers work well alongside this one:

  • Numeric state: Triggers when a numeric value crosses a threshold.

  • Time: Triggers at a specific time, or from a date/time helper or timestamp-style sensor.