Binary sensor

Binary sensors are similar to other sensors in that they monitor the states and conditions of different entities. Where binary sensors differ is they can only return one of two mutually exclusive values. For example, a binary sensor for a window may report a value of open or closed, a switch on or off, a condition true or false.

This either/or constraint is what makes these sensors binary. They are digital in nature, whereas analog sensors, like temperature and weight sensors, return a range of values.

Some binary sensors are created automatically when you add a device integration. For example, adding the ecobee integration will create a binary sensor to detect room occupancy. Other binary sensors can be created manually using the template integration or using an input boolean helper.

Note

Building block integration

This binary sensor is a building block integration that cannot be added to your Home Assistant directly but is used and provided by other integrations.

A building block integration differs from the typical integration that connects to a device or service. Instead, other integrations that do integrate a device or service into Home Assistant use this binary sensor building block to provide entities, services, and other functionality that you can use in your automations or dashboards.

If one of your integrations features this building block, this page documents the functionality the binary sensor building block offers.

Binary sensor states

A binary sensor has two states: on or off. In the Home Assistant interface, its device class determines the icon and the label shown for each state. For example, a lock binary sensor shows Unlocked when its state is on and Locked when its state is off.

In addition, the entity can have the following states. Each item shows the interface label, followed by the stored state:

  • Unavailable (unavailable): The entity is currently unavailable.
  • Unknown (unknown): The state is not yet known.

Device class

The device class tells Home Assistant what a binary sensor detects, such as an open door or motion. Home Assistant uses the device class to choose the icon and the labels for on and off, such as Open and Closed. The device class also decides where you can use the binary sensor, such as in triggers and conditions, on the Security dashboard, or in voice assistants. If a binary sensor doesn’t show up where you expect it, check its device class.

The integration that provides the binary sensor sets the device class. When you create a binary sensor yourself with a template helper, you choose the device class.

Device classes in automations and templates

  • Automations: Some device classes have their own triggers and conditions, such as Door opened. Of your binary sensors, these triggers and conditions only list the ones with that device class. The list below shows the triggers and conditions of each device class.
  • Templates: The device class is the device_class attribute of the entity. Use the stored value, such as door. For example, you can find entities by device class.

List of available device classes

A binary sensor without a device class shows On and Off as its state labels.

Each item shows the name you see in the Home Assistant interface, followed by the device class as Home Assistant stores it. Below each item are the labels the interface shows for the on and off states, and the triggers and conditions of the device class, if it has any.

For sensors that measure values, see the sensor device classes.

Changing the device class of a binary sensor

If a binary sensor shows up as the wrong type, for example as an opening instead of a door, you can change its device class.

You can only change the device class in the UI if the binary sensor has a unique ID. A binary sensor without a unique ID shows a message in its entity settings instead. For such a binary sensor, you can change the device class in YAML with customization.

  1. Go to Settings > Devices & services > Entities and select the binary sensor.
  2. In the top-right corner, select Settings .
  3. Under Show as, select the type that matches your device.
  4. Select Update.
    • Result: The binary sensor shows up as the new type in triggers and dashboards.

If you created the binary sensor with a template helper, change the device class in the options of the template helper instead.