State changed

The State changed 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. Search for and select the State changed trigger.
  5. In Entity, select the entity whose state or attribute value Home Assistant should watch.
  6. Optional: Select Add entity to watch additional entities.
  7. Optional: In Attribute, select an attribute instead of the main state.
  8. Optional: In From, enter the state (or attribute value) the entity must have before the trigger fires.
  9. Optional: In To, enter the state (or attribute value) the entity must have when the trigger fires.
  10. Optional: In For at least, enter how long the entity must be in the new state, or hold the new attribute value, before the trigger fires. Instead of a Duration, you can enter a Template.
  11. Select Save.

Options in the UI

Entity (Required)

Entity whose state or attribute value to watch.

Attribute (Optional)

Entity attribute to watch instead of the main state.

From (Optional)

The starting state or starting attribute value to match.

To (Optional)

The new state or new attribute value to match.

For at least (Optional)

The amount of time the new state or new attribute value must remain unchanged before the trigger fires. Default is 0 hours, 00 minutes and 00 seconds (fires immediately).

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. For how an automation is built in YAML, refer to Automations in YAML.

When this trigger starts an automation, it passes data about what happened to the automation. You can use this trigger data in the templates of your conditions and actions. To see which data is available, refer to Trigger data in templates.

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

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]
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 | list Required

The ID of the entity or a list of IDs of the entities to watch.

from string | list (Optional)

The starting state or starting attribute value to match. You can use one state, a list of states, or null to match any starting state while ignoring attribute-only changes.

to string | list (Optional)

The new state or new attribute value to match. You can use one state, a list of states, or null to match any new state while ignoring attribute-only changes.

not_from string | list (Optional)

The starting state or starting attribute value to exclude. You can use one state or a list of states. This option is available in YAML only.

not_to string | list (Optional)

The new state or new attribute value to exclude. You can use one state or a list of states. This option is available in YAML only.

attribute string (Optional)

The entity attribute to watch instead of the main state.

for string | integer | map | template (Optional, default: 00:00:00)

The amount of time the new state or new attribute value must remain unchanged before the trigger fires. With a list of states in to, the entity must stay in the state it changed to; changing to another state in the list starts the time again. Accepts a duration string in HH:MM:SS format or a time period mapping in hours, minutes, and seconds. You can also use a template. For a list of all accepted formats and templates, refer to Durations in automations and scripts.

Targets of the trigger

This trigger watches one or more entities:

  • Use the UI option Entity, or YAML option entity_id, to watch one entity.
  • Select Add entity and pick another entity from the UI, or use a list of entity_id values in YAML, to watch more than one entity.

Good to know

  • If you do not set any of From, To, not_from, or not_to, this trigger fires on all state changes. It also fires when only an attribute changes.
  • If you set one of the options From (from), To (to), not_from, or not_to, attribute-only changes do not fire the trigger.
  • In the UI, Any state (ignoring attribute changes) for From or To means “match any state, but only when the state changes.” In YAML, this appears as from: null or to: null (the key is present, but the value is empty), which prevents attribute-only changes from firing. This is useful for sensors that update attributes often while their main state changes less often.
  • You cannot combine the options from with not_from, or to with not_to.
  • If you use the For at least (for) option, the timer resets if Home Assistant restarts or automations reload.
  • If you use For at least (for) with several states in To (to), the entity must stay in the state it changed to for the whole time. The time isn’t added up across the states: a change from one of the states to another starts the time again. For example, with to: ["off", "unavailable"] and for: "00:05:00", a light that is off for 3 minutes and then unavailable for 3 minutes doesn’t fire the trigger after 5 minutes. It fires once the light has been unavailable for 5 minutes.

Try it yourself

Ready to test this? Go to Settings > Automations & scenes, create a new automation, and add this trigger. Save the automation, and then make the trigger react. For example, change the state of the targeted 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], turn on a light that the trigger monitors, or change its brightness. To check whether the automation ran, open its traces.

More examples

Real scenarios where this trigger fires in automations and scripts. Copy any example and adapt it to your setup. In the visual editor, select the UI options listed in the example when they are available, 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: 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 changed
    • Entity: Back door sensor (binary_sensor.back_door)
    • To: On
    • For at least: 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 changed
    • 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."

Automation: send a notification when a sensor value stops changing

If you want to know when a sensor value has not changed for a period, use Any state (ignoring attribute changes) for To and set For at least to the amount of time you want to wait.

  • Trigger: State changed
    • Entity: Power sensor (sensor.current_power)
    • To: Any state (ignoring attribute changes)
    • For at least: 30 minutes
  • Action: Send a notification message
    • Target: My Device (notify.my_device)
YAML example for a sensor value that stops changing
AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
alias: "Notify me when power stops updating"
triggers:
  - trigger: state
    entity_id: sensor.current_power
    to: null
    for: "00:30:00"
actions:
  - action: notify.send_message
    target:
      entity_id: notify.my_device
    data:
      message: "The power sensor value has not changed for 30 minutes."

Still stuck?

To find out why the trigger didn’t react, make the change that it should react to, and then open the traces of the automation. If the automation didn’t run, there’s usually no trace, but some triggers record a Did not trigger trace. For details, refer to Testing automations. For common problems and their solutions, refer to Troubleshooting automations.

If that doesn’t help, 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

Explore related triggers: