What are binary sensors in Home Assistant?

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

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).

Advertisement

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 other than 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.

Advertisement
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.

Advertisement

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 own icon, and it definitely helps in making your Lovelace UI look nicer.

Advertisement

Some binary sensor examples

There are many different 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 a bunch of cheap Sonoff switches flashed with ESPHome. I also use binary sensor templates for my room occupancy detection.

The best Raspberry Pi for Home Assistant in 2020

Home Assistant gets an air purifier card

Advertisement
Liam Alexander Colman, the author and maintainer of Home Assistant Guides.

About Liam Alexander Colman

Liam Alexander Colman has been using Home Assistant for various projects for quite some time. What started of with a Raspberry Pi quickly became three Raspberry Pis and eventually a full-blown server. I now use Unraid as my operating system, and Home Assistant happily runs in a Docker container. My personal setup includes many Zigbee devices as well as integrations with existing products such as my Android TV box. Read on to find out more on how I got started with Home Assistant.

Leave a comment

Advertisement