Xiaomi body sensor gateway maybe wrong motion detection

Are you sure about that frequency? Last time I checked it was sent frequently IIRC.

Also, I don’t think the proposed fix will fix it 100% :frowning: My two motion sensors just went into ghost mode (reporting motion, with no motion), with about 10 minutes difference. When HA restarts, the components does a “read” for each sensor, and both are reporting “status: motion”. So, it is not only the heartbeats that are wrong :frowning:

If everyone contacts Xiaomi support, the may fix it. Open the Mi Home app, go to Profile > Help & Feedback > Gateway > Report an Issue and say that the motion sensors are reporting false positives when using the local developer API.

I tested this code for about 1 week and these are my considerations:

  • no more false motion / detection since the fix
  • heartbeat is sent either if the gateway is connected to internet or not

@abmantis the only bug is if the home assistant is started/restarted before the heartbeat with motion status is sent, and it stays in this wrong status until the motion sensor send report with no_motion (or heartbeat but it can takes a lot of hours).
The only trusted way to reset the sensor is to trigger it

In my case I’m using home assistant running 24/24h so I didn’t care, but happened to me too while I was testing and I was doing a lot of restart of home assistant service.

The heartbeats I receive are very few in a day (maybe 2 times, maybe 6 times) but anyhow are too few to use them as reliable notification.

I’m going to write to xiaomi support to solve this issue of false positive heartbeat.
Thanks for your feedback abmantis!

You are right. The first bogus event is the heartbeat which triggers “motion”. The HA component starts polling the device for updates on motion. Polling also retrieves the bogus state. If the heartbeat is ignored there is no motion recognized by home assistant and there will be no polling. One exception: If you restart home assistant all sensors are polled once. If your motion sensor is in “ghost mode” you will retrieve the bogus state. :frowning:

My conclusion: Ignoring the heartbeat improves the situation a bit but it cannot be fixed entirely.

@cesco83 Do you prepare a PR for PyXiaomiGateway?

Good news. Have applied the fix, haven’t been able to verify if it solves the problems because of this:

Mine are all in bogus state because I’m not at home so they sensors can’t be triggered.
It might be nice to be able to disable the initial polling, I’m new to HA so restarting a lot.
Therefore my automations won’t work, the motion sensors are triggered, state from off to on. In this case they won’t trigger.

When initial polling is disabled I would prefer the state to be initialized as no motion.

What I’m wondering… should this fix be combined to the disable_poll setting I’ve seen somewhere?
I just enabled debugging and see the Xiaomi sensors are polled every 30 seconds.

Where did you see this feature request? :slight_smile:

I had to look it up, it was in the main beta tread.

Okay. This does not apply anymore to the official component.

With my fix I can avoid false motion detection, but I can’t avoid the troubles underlying the firmware of the gateway.
In theory with this fix, once home assistant is started (and statuses are ok on first startup) you will never get the false motion detection and it will go nice without troubles anymore , because report command is not buggy.

You can also turn off polling by setting

poll_motion=false

I think initial polling is a must to get the current statuses of all components (example know if a door is open or close). I didn’t test if door sensors are buggy too…

Meanwhile I wrote a post to Xiaomi Forum and from Xiaomi App, I hope that they will see the post and fix the bug…you can follow here: http://en.miui.com/thread-778621-1-1.html

@syssi No I didn’t prepare PR, yet :slight_smile:

Do you like? If not, I will do it.

Yes I’m going to make it :wink:

1 Like

Pull request created :wink:

Good job Guys!
Will reply to the Miui Topic in a day or so. to give it some extra attention.

Thanks guys for your support, let’s try to win this battle!!! :smile:

1 Like

is the going to be included in the next home assistant release?

Yes. It’s already merged. Some additional informations about the heartbeat filter:

Hi all,

Since firmware 150 and HA 54.0 my motion sensors are not turning off. The HA logs reveal that all 4 motion sensors are detecting motion every 30 seconds.

This seems like it was supposed to be resolved in this thread however, at least on my install, it is not. Is this fix already present in HA?

Did you update the firmware of your gateway shortly before? Did you do the update remotely? After a firmware update the motion sensor must see real motion once to provide proper measurements afterwards. If you are not at home and there is no motion the sensor gets stuck at “there is motion”-state.

That was exactly the problem. Thanks @syssi !

@rtenklooster, @cesco83 guys, is this issue still relevant for gateway? Is it still reporting wrong motion status in heartbeat?

I have no idea.
For my home security and for stability I have decided not to depend on our Chinese friends anymore.
I bought (a lot) of other Xiaomi sensors, about 20 window / door sensors, switches, pir’s etc.
The hardware is realy great.

I switched my Xiaomi devices to the Deconz Raspbee shield :slight_smile: