What are binary sensors in Home Assistant?

Disclosure: This post contains affiliate links. If you click through and make a purchase, I will earn a commission, at no additional cost to you. Read my full disclosure here.

Binary sensors in Home Assistant are sensors which can only ever have one of two states. Their state is either a 0 or a 1. And to make it understandable for us mere mortals: They can either be off (0) or on (1).

Binary sensors came in many shapes and forms. Just think of all the devices in your smart home, many of them will only ever report one of two states to Home Assistant. A light switch will either be turned on or off. A Wi-Fi-connected outlet will either deliver power or not. A contact sensor placed on a door or window will either report it being open or closed. A lock will either be unlocked or locked. I could go on, but I think you get the picture.

A light switch is only ever on or off
A lock can be either open or closed

Why not use sensors?

Sensors can have any state. So obviously, they could also have the states off and on. So, why use binary sensors if you could just replace them with sensors? The answer is rather simple. When Home Assistant sees a binary sensor, it knows that it can only ever have one of two states. It will never report anything besides a 0 or 1. That way, you can easily represent them in your Home Assistant frontend. For example, the Glance Card can tell you in which state a binary sensor is by the colour of its icon.

A glance card in Home Assistant showing the status of multiple binary sensors

Having only two states also makes binary sensors easier to use in Home Assistant automations and scripts. With a sensor, you’d have to compare the state to a predefined value. When using binary sensors, you only have to check whether it is off or on.

What are binary sensor device classes?

Binary sensors can be assigned a specific device class. There is a whole list of device classes available in the Home Assistant documentation. A binary sensor can be set to report on whether a window or door is open, whether a lock is locked or unlocked, whether there is movement detected or not, and so on.

Some binary sensors will automatically report the correct device class. For example, my Aqara motion sensors, which are integrated with Home Assistant using Zigbee2MQTT, are automatically set to the motion device class. But not all devices will do this. In that case, you can set the correct device class by customizing the entity. It can also happen that a binary sensor will report the wrong device class. For example, this can happen when you might be using a door contact sensor on a window.

A binary sensor in Home Assistant
This sensor has the device class motion

Device classes are used to correctly display your binary sensors on the Home Assistant frontend. Each state from every device class will have its icon, and it definitely helps in making your Lovelace UI look nicer.

Some binary sensor examples

There are many types of devices that report as binary sensors. You can also create your own binary sensors using the binary sensor template. Let’s say you have a thermometer, but you’re not really interested in the exact temperature, you only want to know whether a room is cold or not cold. You could create a binary sensor based on that thermometer and have it report cold when a certain temperature is reached. Binary sensors I use include many Zigbee devices from the multiple Xiaomi brand names. I have Aqara motion sensors in just about every room, contact sensors on a few doors and windows, and several cheap Sonoff switches flashed with ESPHome. I also use binary sensor templates for my room occupancy detection.

About Liam Alexander Colman

is an experienced Home Assistant user who has been utilizing the platform for a variety of projects over an extended period. His journey began with a Raspberry Pi, which quickly grew to three Raspberry Pis and eventually a full-fledged server. Liam's current operating system of choice is Unraid, with Home Assistant comfortably running in a Docker container.
With a deep understanding of the intricacies of Home Assistant, Liam has an impressive setup, consisting of various Zigbee devices, and seamless integrations with existing products such as his Android TV box. For those interested in learning more about Liam's experience with Home Assistant, he shares his insights on how he first started using the platform and his subsequent journey.

Leave a comment

Share to...