For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /developers/core/entity/binary-sensor.md.

二进制传感器实体

Binary sensor 是一种只能有两个 states 的 sensor。从 homeassistant.components.binary_sensor.BinarySensorEntity 派生 entity platforms。

属性

Tip

Properties 应该只从内存中返回信息,不要执行 I/O(如网络请求)。实现 update()async_update() 来获取数据。

NameTypeDefaultDescription
is_onbool | NoneNone必需。Binary sensor 当前是 on 还是 off。
device_classBinarySensorDeviceClass | NoneNoneBinary sensor 的类型。

可用的设备类型

ConstantDescription
BinarySensorDeviceClass.BATTERYOn 表示电量低,Off 表示正常。
BinarySensorDeviceClass.BATTERY_CHARGINGOn 表示正在充电,Off 表示未充电。
BinarySensorDeviceClass.COOn 表示检测到一氧化碳,Off 表示无一氧化碳(正常)。
BinarySensorDeviceClass.COLDOn 表示温度低,Off 表示正常。
BinarySensorDeviceClass.CONNECTIVITYOn 表示已连接,Off 表示已断开连接。
BinarySensorDeviceClass.DOOROn 表示打开,Off 表示关闭。
BinarySensorDeviceClass.GARAGE_DOOROn 表示打开,Off 表示关闭。
BinarySensorDeviceClass.GASOn 表示检测到燃气,Off 表示无燃气(正常)。
BinarySensorDeviceClass.HEATOn 表示温度高,Off 表示正常。
BinarySensorDeviceClass.LIGHTOn 表示检测到光线,Off 表示无光线。
BinarySensorDeviceClass.LOCKOn 表示打开(未锁定),Off 表示关闭(已锁定)。
BinarySensorDeviceClass.MOISTUREOn 表示湿润,Off 表示干燥。
BinarySensorDeviceClass.MOTIONOn 表示检测到移动,Off 表示无移动(正常)。
BinarySensorDeviceClass.MOVINGOn 表示正在移动,Off 表示未移动(已停止)。
BinarySensorDeviceClass.OCCUPANCYOn 表示有人,Off 表示无人(正常)。
BinarySensorDeviceClass.OPENINGOn 表示打开,Off 表示关闭。
BinarySensorDeviceClass.PLUGOn 表示已插上,Off 表示未插上。
BinarySensorDeviceClass.POWEROn 表示检测到电流,Off 表示无电流。
BinarySensorDeviceClass.PRESENCEOn 表示在家,Off 表示外出。
BinarySensorDeviceClass.PROBLEMOn 表示检测到问题,Off 表示无问题(正常)。
BinarySensorDeviceClass.RUNNINGOn 表示正在运行,Off 表示未运行。
BinarySensorDeviceClass.SAFETYOn 表示不安全,Off 表示安全。
BinarySensorDeviceClass.SMOKEOn 表示检测到烟雾,Off 表示无烟雾(正常)。
BinarySensorDeviceClass.SOUNDOn 表示检测到声音,Off 表示无声音(正常)。
BinarySensorDeviceClass.TAMPEROn 表示检测到拆改,Off 表示无拆改(正常)。
BinarySensorDeviceClass.UPDATEOn 表示有 update 可用,Off 表示已是最新。应避免使用此 device class,请考虑改用 update entity。
BinarySensorDeviceClass.VIBRATIONOn 表示检测到振动,Off 表示无振动。
BinarySensorDeviceClass.WINDOWOn 表示打开,Off 表示关闭。