星路

追寻那一缕星光,在漆黑夜晚前行

0%

【踩坑系列】Home Assistant中Aqara人体传感器的触发状态异常

前不久将Aqara人体传感器接入了HA,联动控制楼梯灯,使用下来感觉除了感应距离和范围小了点,灵敏度还是可以的。另外发现了一个问题,HA中它的state有点迷,基本都是“触发”状态,不能够正常同步真实状态。


1.环境

Ubuntu18.04 + HA 0.71.0


2.过程

{[HA安装目录]}/components/binary_sensor/xiaomi_aqara.py中XiaomiMotionSensor类的init方法增加一行代码即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#……省略……#
class XiaomiMotionSensor(XiaomiBinarySensor):
#……省略……#
def __init__(self, device, hass, xiaomi_hub):
"""Initialize the XiaomiMotionSensor."""
self._hass = hass
self._no_motion_since = 0
if 'proto' not in device or int(device['proto'][0:1]) == 1:
data_key = 'status'
else:
data_key = 'motion_status'
XiaomiBinarySensor.__init__(self, device, 'Motion Sensor', xiaomi_hub,
data_key, 'motion')
self._should_poll = True #增加的代码行

Tips

HA启动过程会为binary_sensor.xiaomi_aqara这个platform注册一个更新数据的周期性任务(任务中通过should_poll属性判断该设备是否调用update方法去更新数据),前提是该platform下的设备的should_poll属性不能全为False。而代码中默认的should_poll属性都是False,所以导致无法正常更新数据。故需要在设备初始化的时候设置一下should_poll的值即可。


3.小结

3.1.接入HA

Aqara人体传感器通过米家APP加入网关,HA使用xiaomi_aqara配置网关信息即可。HA启动会自动发现设备,然后生成一个binary_sensor.motion_sensor_xxxxxxxxxxxxxx的entity

3.2.Aqara人体传感器工作方式

1)触发后,设备立刻报送移动状态[{“motion_status”:”motion”}] 以及光照度[{“lux”:100},{“illumination”:100}]

2)触发后的1分钟内是罢工状态,即不会监测是否有人

3)触发后1分钟,motion_status变为no_motion,但不会主动上报!(就是这么任性),需要主动去读取状态