Skip to main content
The binary sensor platform represents entities with two states: on/off, detected/not detected, open/closed, etc. Binary sensors are used for things like motion detection, door/window sensors, and occupancy detection.

Base Class

All binary sensor entities inherit from BinarySensorEntity, which is defined in homeassistant.components.binary_sensor.

Entity Description

Binary sensor entities can optionally use BinarySensorEntityDescription to define static metadata:

Required Properties

is_on

Returns True if the binary sensor is on, False if off, or None if unknown.

Optional Properties

device_class

Indicates the type of binary sensor. This affects the icon displayed in the UI and what the on/off states represent.
Common device classes:
  • BATTERY - On = low, Off = normal
  • BATTERY_CHARGING - On = charging, Off = not charging
  • DOOR - On = open, Off = closed
  • GARAGE_DOOR - On = open, Off = closed
  • MOTION - On = motion detected, Off = no motion
  • OCCUPANCY - On = occupied, Off = not occupied
  • OPENING - On = open, Off = closed
  • PLUG - On = plugged in, Off = unplugged
  • PRESENCE - On = home, Off = away
  • PROBLEM - On = problem detected, Off = OK
  • SMOKE - On = smoke detected, Off = clear
  • WINDOW - On = open, Off = closed

State Property

The state property is final and automatically returns “on” or “off” based on is_on:

Example Implementation

Push vs. Poll

For binary sensors that receive push updates (like webhooks or event-based systems):

Real-World Example

From the demo integration (homeassistant/components/demo/binary_sensor.py):

Entity Attributes

Binary sensors typically don’t have additional state attributes, but you can add them if needed:

Important Notes

  • Binary sensors should set _attr_is_on rather than implementing state directly
  • The state property is final and automatically converts is_on to “on”/“off”
  • Set _attr_should_poll = False for sensors that receive push updates
  • Binary sensors with EntityCategory.CONFIG cannot be added (will raise HomeAssistantError)
  • Always set a device_class to get the appropriate icon and on/off semantics

Device Class Meanings

Each device class has specific semantics for what “on” and “off” mean:

See Also