Binary sensors in Home Assistant play a crucial role in smart home setups, with their core function being to report one of two possible states: either 0
(off) or 1
(on). These sensors come in various forms, contributing to the seamless operation of connected devices such as light switches, Wi-Fi outlets, contact sensors, and locks.

The rationale behind binary sensors
While sensors inherently possess the capability to represent on
and off
states, binary sensors offer a more simplistic and efficient alternative. Home Assistant, upon detecting a binary sensor, is aware that it can only ever report a 0
or 1
, making their representation on the frontend, such as with the Glance Card, more straightforward.
The binary nature of these sensors also simplifies their use in Home Assistant automations and scripts, as users only need to verify if a sensor is off
or on
, rather than comparing its state to a predefined value.

Exploring Home Assistant's binary sensor device classes
Binary sensors can be assigned specific device classes, such as those indicating whether a door is open or closed, if a lock is secure, or if movement is detected. A comprehensive list of device classes can be found in the Home Assistant documentation.
Some Home Assistant binary sensors, like Aqara motion sensors, automatically report the correct device class when integrated with Home Assistant via Zigbee2MQTT. However, not all devices possess this capability, necessitating manual customization of the entity. Additionally, there are instances when a binary sensor may report an incorrect device class, which can be rectified through customization. Device classes are vital for accurately displaying binary sensors on the Home Assistant frontend and enhancing the aesthetics of the Home Assistant Dashboard.

Delving into binary sensor examples
A myriad of devices function as binary sensors, and users can even create their own using Home Assistant's binary sensor template. For instance, if you have a thermometer and merely want to know if a room is cold
or not cold
, you can create a binary sensor based on the thermometer to report the cold
state when a specific temperature is reached. Examples of binary sensors in use include Aqara motion sensors, contact sensors, and Sonoff switches running ESPHome. Binary sensor templates can also be employed for room occupancy detection.