Triggered by

The Triggered by condition checks which 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] started the automation. Use it when an automation has several triggers, and it should do something different depending on the trigger. For example, one automation can close the blinds at sunset and open them at sunrise.

You often use this condition in a Choose or If-then block between the actions, so that one part of the actions only runs for one trigger. You can also use it in the And if section.

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. Make sure that the automation has the triggers you want to check.
  4. In the And if section, select Add condition.
    • To use the condition between the actions, add it to the conditions of a Choose or If-then block instead.
  5. From the search box, search for and select Triggered by.
  6. Under Trigger, select one or more triggers of the automation.
    • The triggers are listed with their number and a description.
  7. Select Save.

Options in the UI

Trigger (Required)

The triggers to check. The condition passes if one of the selected triggers started the automation. Home Assistant gives the selected triggers an ID if they don’t have one yet.

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: trigger, and refer to the trigger by its trigger ID. 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: trigger
id: sunset

This passes when the trigger with the ID sunset started the automation.

Options in YAML

The options in YAML are the same as in the UI.

condition string Required

The condition type. For this condition, use trigger.

id string | integer | list Required

The ID of the trigger, or a list of IDs. The condition passes if one of these triggers started the automation. A trigger without an ID uses its position in the list of triggers as its ID, starting with 0.

The following example passes if one of two triggers started the automation:

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: trigger
id:
  - front_door_opened
  - back_door_opened

Good to know

  • When you select triggers in the editor, Home Assistant creates and manages their trigger IDs for you. It removes the IDs that it created when no Triggered by condition uses them anymore. If you use trigger.id in a template or in action data, set the ID yourself in YAML instead.
  • If the editor shows Missing trigger, the condition refers to an ID that no trigger has anymore. This can happen if you delete a trigger, or change its ID in YAML. To clear the reference, clear the checkbox of the missing trigger.
  • If the editor warns that triggers share the same ID, select Fix.
    • Home Assistant gives each of these triggers its own ID and updates the Triggered by conditions.
    • Duplicate IDs that no Triggered by condition uses are removed. This also happens if a template or action data uses them.
    • Templates and action data that use trigger.id aren’t updated, so check them yourself.
  • A trigger without an ID uses its position as its ID. In YAML, you can write that ID as a number or as text. For example, 0 and "0" both refer to the first trigger.
    • Positions start at 0, but the editor numbers the triggers from 1. For example, trigger 1 in the editor has the ID 0 in YAML.
  • When you select Run actions, or start the automation with the Trigger automation action, no trigger starts it. Run actions always skips the conditions in And if, and the Trigger automation action skips them by default. In both cases, the actions run.
    • A Triggered by condition in a Choose or If-then block is still checked. It doesn’t pass, so that part of the actions doesn’t run.
    • If you turn off Skip conditions in the Trigger automation action, a Triggered by condition in And if doesn’t pass either. The automation stops.
    • To test the automation with a trigger, refer to Using a simulated trigger to test an automation.

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: close the blinds at sunset and open them at sunrise

This automation has two triggers. A Choose block uses Triggered by to close the blinds at sunset, and to open them at sunrise.

  • Triggers:
    • Sun
      • Event: Sunset
    • Sun
      • Event: Sunrise
  • Action: Choose
    • Option 1:
      • Condition: Triggered by
        • Trigger: The sunset trigger
      • Action: Close cover
        • Target: Living room blinds (cover.living_room_blinds)
    • Option 2:
      • Condition: Triggered by
        • Trigger: The sunrise trigger
      • Action: Open cover
        • Target: Living room blinds (cover.living_room_blinds)
YAML example for blinds that follow the sun
AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
alias: "Blinds follow the sun"
triggers:
  - trigger: sun
    event: sunset
    id: sunset
  - trigger: sun
    event: sunrise
    id: sunrise
actions:
  - choose:
      - conditions:
          - condition: trigger
            id: sunset
        sequence:
          - action: cover.close_cover
            target:
              entity_id: cover.living_room_blinds
      - conditions:
          - condition: trigger
            id: sunrise
        sequence:
          - action: cover.open_cover
            target:
              entity_id: cover.living_room_blinds

Automation: get a notification only for the back door

When the front door or the back door opens, this automation turns on the hallway light. It only sends a notification if the back door opened.

  • Triggers:
    • State changed
      • Entity: Front door (binary_sensor.front_door)
      • To: Open
    • State changed
      • Entity: Back door (binary_sensor.back_door)
      • To: Open
  • Action: Turn on light
    • Target: Hallway light (light.hallway)
  • Action: If-then
    • If: Triggered by
      • Trigger: The back door trigger
    • Then: Send a notification message
      • Target: My Device (notify.my_device)
YAML example for a notification only for the back door
AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
alias: "Hallway light and back door notification"
triggers:
  - trigger: state
    entity_id: binary_sensor.front_door
    to: "on"
    id: front_door_opened
  - trigger: state
    entity_id: binary_sensor.back_door
    to: "on"
    id: back_door_opened
actions:
  - action: light.turn_on
    target:
      entity_id: light.hallway
  - if:
      - condition: trigger
        id: back_door_opened
    then:
      - action: notify.send_message
        target:
          entity_id: notify.my_device
        data:
          message: "The back door was opened."

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:

  • Template: Tests if a template renders true.