Automation targets: entities, devices, areas, floors, and labels

A target is what a 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], a 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], or an actionAn action makes Home Assistant do something, for example, turn on a light, send a notification, or activate a scene. Automations and scripts run a list of actions. [Learn more] works with, in both automationsAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more] and scriptsA script is a saved list of steps that runs when you start it, for example, from a dashboard, with Assist, or from an automation. Unlike an automation, a script has no triggers, so it doesn’t start by itself. [Learn more]. A trigger monitors its targets for a change, a condition checks the stateThe state holds the information of interest of an entity, for example, if a light is on or off. Each entity has exactly one state and the state only holds one value at a time. However, entities can store attributes related to that state such as brightness, color, or a unit of measurement. [Learn more] of its targets, and an action controls its targets. For example, the Light turned on trigger reacts when a targeted light turns on, and the Turn on light action turns on the targeted lights.

A target can be a single 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], or a group of entities, such as all lights in an areaAn area in Home Assistant is a logical grouping of devices and entities that represents a room or space in your home, such as the living room, kitchen, or garage. [Learn more], like a room in your home. Home Assistant finds the matching entities for you.

Types of targets

You can use one or more targets in a trigger, condition, or action. You can also combine different target types, for example, one entity and an entire area.

  • Entity: That one entity, for example, the hallway light.
  • Device: The matching entities of that deviceA device is a model representing a physical or logical unit that contains entities.. If the device has sub-devices, such as the outlets of a power strip, their matching entities are part of the target as well.
  • Area: The matching entities in that area.
  • Floor: The matching entities in all areas on that floorA floor in Home Assistant is a logical grouping of areas that are meant to match the physical floors in your home. Devices & entities are not assigned to floors but to areas. Floors can be used in automations and scripts as a target for actions. For example, to turn off all the lights on the downstairs floor when you go to bed. [Learn more].
  • Label: The matching entities that have that labelLabels in Home Assistant allow grouping elements irrespective of their physical location or type. Labels can be assigned to areas, devices, entities, automations, scenes, scripts, and helpers. Labels can be used in automations and scripts as a target for actions. Labels can also be used to filter data. [Learn more]. If the label is on a device or an area, the matching entities of that device or area are part of the target as well.

Entities that are part of a target

When a target is a device, an area, a floor, or a label, not every entity that belongs to it is part of the target. An entity is part of a target if both of the following are true:

  • It belongs to the device, area, floor, or label you selected.
  • The trigger, condition, or action can work with it.

For example, a Light turned on trigger that targets the living room area monitors all lights in the living room.

An entity belongs to an area if one of the following is true:

  • The entity is assigned to that area.
  • The device of the entity is in that area, and the entity has no area of its own.

To learn how to assign devices and entities to areas, refer to Grouping your assets.

If you select an entity directly, it’s always part of the target, even if it’s one of the entities listed in the next section.

Entities that are not part of a target

Some entities are not part of a target, even if they belong to the device, area, floor, or label you selected.

The following entities are not part of a target because of what the trigger, condition, or action works with:

  • Entities of a different type. For example, for Light turned on, the switches and sensors in the room are not part of the target, and for Window opened, door sensors are not, because the trigger checks the device class.
  • For triggers and conditions, the members of old-style groups. These are groups set up in YAML, with an entity ID that starts with group., such as group.downstairs_lights.

The following entities are not part of a target because of how they are set up:

  • Entities that you assigned to a different area than their device, when you target the area of the device. These entities belong to their own area only.
  • Hidden entities. To hide an entity, turn off Visible in its settings. For example, if an action turns on all lights in the living room, a hidden light in that room stays off.
  • Configuration and diagnostic entities, such as a firmware update or the signal strength of a device. If you put a label on the entity itself, and target that label, the entity is part of the target.

Targets stay up to date

Home Assistant keeps the entities in a target up to date. If you’ve selected an area as a target, and later add a light to that area, the light becomes part of the target right away. You don’t need to edit the automation.

When a target covers several entities

When a target covers more than one entity, you can decide how the trigger or condition combines them.

Triggers: Each, First, and All

Under Trigger when, select one of the following:

  • Each (default): The trigger reacts every time one of the targets makes the change. For example, if three lights turn on, the automation starts three times.
  • First: The trigger reacts when the first target makes the change. It reacts again only after none of the targets is in that state anymore. For example, the automation starts when the first light in the living room turns on, and doesn’t start again until all of them are off.
  • All: The trigger reacts when the last target makes the change, so that all targets are in that state. For example, the automation starts when the last window is closed.

For First and All, Home Assistant skips targets that are Unavailable or Unknown. Most triggers also don’t react when a target comes back from Unavailable or Unknown. For details, refer to Unavailable and unknown state behavior in triggers.

When an automation starts, the trigger data describes the one entity that made the change, not the entire target. For example, trigger.entity_id is the light that turned on, and trigger.from_state and trigger.to_state are the states of that light before and after the change. To learn how to use this data, refer to Trigger data in templates.

Conditions: Any and All

Under Condition passes if, select one of the following:

  • Any (default): The condition passes if at least one of the targets is in that state. For example, at least one light in the living room is on.
  • All: The condition passes only if all targets are in that state. For example, all windows are closed.

Targets that are Unavailable or Unknown don’t count. If all targets are Unavailable or Unknown, Any fails and All passes. For example, if all window sensors in the bedroom are Unavailable, because their hub is offline, Window is closed with All passes, even though Home Assistant can’t tell whether the windows are closed.

Any and All combine the targets of one condition. To combine different conditions, use the And and Or conditions. For example, to check whether a light is on or a door is open, add an Or condition with both conditions in it.

Actions

An action controls all of its targets. For example, if Turn on light targets an area, all lights in that area turn on. For details, refer to Action targets.

Targets in YAML

In YAMLYAML is a human-readable data serialization language. It is used to store and transmit data in a structured format. In Home Assistant, YAML is used for configuration, for example in the configuration.yaml or automations.yaml files. [Learn more], enter the targets under target. Use one or more of the following keys: entity_id, device_id, area_id, floor_id, and label_id. Each key can contain a single ID or a list of IDs. Use the IDs, not the names.

For triggers, set Trigger when with behavior under options. The values are each, first, and all. For conditions, set Condition passes if the same way. The values are any and all.

The following automation reacts when the first light in the living room turns on. If all lights upstairs are off, it turns on the hallway lights.

AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
alias: "Hallway on when living room lights up"
triggers:
  - trigger: light.turned_on
    target:
      area_id: living_room
    options:
      behavior: first
conditions:
  - condition: light.is_off
    target:
      floor_id: upstairs
    options:
      behavior: all
actions:
  - action: light.turn_on
    target:
      area_id: hallway