Aqara motion sensors in ZHA - "occupancy" wonky while "motion" part works fine

Xiaomi aqara motion sensors in ZHA create both a binary_sensor.motion_sensorx, and binary_sensor.occupancy_sensorx, and for most lights, the occupancy has a sensible timeout, so that’s what I use for most light automations.

But about 6 hours, a few of them have stopped responding. That is, the occupancy sensor is perpetually on, while the motion sensor for the same device works as expected (off, since no one is there).

I’m guessing, since the ones that won’t turn off had turned on at about the same time, that it could be that HA was restarted, and the sensors changed to off during to restart?

If so, is there a workaround for this? I mean, I can of course manually change their state, but is there a way to avoid this in the future? It’s not always that this would be noticed, it could just result in all the lights upstairs, or in the basement, being on until we happened to go there again (sometimes days later).

EDIT: After manually setting the state to “off”, they just turned back on again. I needed to physically go and wave in front of them, and then wait for them to turn off. So maybe it wasn’t due to state change during HA restart, it seems like they kept sending the “occupancy = on” back to HA if I changed from developer tools.

How are these sensors connecting to Home Assistant, VIA an Aqara hub or something else? I added some of these recently and they connect via a Sonoff Zigbee hub and I don’t have any issues with them losing their state etc…

In terms of motion vs occupancy, typically I find that the motion resets itself after around 2 minutes of no motion and occupancy seems to be around 10 minutes before it resets which is quite useful if you’re checking for occupancy in a room.

They’re connected via a ConBee II stick and ZHA. Looking at the state history, I can see motion being typically 70 seconds, though sometimes less than 1 minute (I assume that’s when no one keeps moving in the area?), while occupancy is usually to 10 minutes.

They switch off again now, but this long “on” time is certainly new!

I set up almost all my automations using occupancy, since this use to have a sensible timeout, but in the kitchen I used motion with a 90 or 180 second delay for turning off (depending on time of day), since the 90-120 seconds the occupancy used to have was too short and using occupancy in the kitchen would result in the lights turning off when you were working for a few minutes.

However, I have also switched from deCONZ to ZHA, and I must admit, I can’t remember if the long timeout was only after that switch.

OK its almost identical to my setup then just that I’m using the Sonoff hub although I am going to replace it with a dongle to try and get better range and will convert the hub to a repeater.

I have one of the Aqara sensors in my bathroom and use the motion sensor to turn on the lights to a low light for 90 seconds during the middle of the night, I then use the occupancy sensor to check for occupancy during the day if the light was left on by mistake.

I noticed that the motion sensor may get triggered when you first walk in but sometimes clears its state even if you are still in the room but perhaps not moving enough which is why I think the occupancy sensor is useful.

Also planning on doing a similar thing in our kitchen but will do as you have and use the occupancy sensor for that.

Can’t we just use "motion stopped detected for at least 10 minutes " logic to do the exact same thing as occupancy?

You could and its most likely what the device itself is doing anyway and then just exposing that as an additional sensor.

I don’t think that would resolve his issue though I’ve found with these Zigbee devices that if they’re doing this arb state change / stale state thing its because of poor signal / placement and isn’t something that corrects itself you generally need to put in a repeater.

I have ~30 repeaters throughout the house. But I stopped using occupancy, and instead use these either in combination with mmWave sensors or with a timeout (slight hassle in large, complex AppDaemon automations, but works once set up).

Yeah I find these Zigbee motion sensors to be a bit hit and miss to be honest and wired / powered motion sensors work far better.

I’m quite keen to get my hands on the new Aqara FP2 when its available and would like to move to mmWave as well as it is considerably more configurable and nice for running automation for different areas within a room.