home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.05k stars 29.72k forks source link

Unifi Protect delay sensor 'Detected Object' #66861

Closed Mulle00 closed 2 years ago

Mulle00 commented 2 years ago

The problem

There is a delay of 4 to 5 seconds that sensor 'Detected Object' is triggered in HA. When using this sensor to take a snapshot, it is always too late. Time between HA and Unifi Protect is fully in sync.

Example: Unifi Protect on my cloud key see the person at 10:45:31 AM, the sensor 'Detected Object' in HA is triggered at 10:45:35 AM.

What version of Home Assistant Core has the issue?

core-2022.2.7

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Unifi Protect

Link to integration documentation on our website

https://www.home-assistant.io/integrations/unifiprotect

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

probot-home-assistant[bot] commented 2 years ago

unifiprotect documentation unifiprotect source (message by IssueLinks)

probot-home-assistant[bot] commented 2 years ago

Hey there @briis, @angellusmortis, @bdraco, mind taking a look at this issue as it has been labeled with an integration (unifiprotect) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

AngellusMortis commented 2 years ago

Not really a bug or anything we can do about. We cannot control the timestamps HA sets for state changes. And HA is single threaded, async and integrations have no control over the event loop. So the Websocket message is sent to HA right away, but depending on the load on your server, it may take it a few seconds to process the message.

If you enable debug logging you can see when the Websocket message is processed.

bdraco commented 2 years ago

If there is a 4 to 5 second delay you likely have blocking I/o in your event loop

Turn on debugpy in your configuration.yaml and restart

Mulle00 commented 2 years ago

It is only with the 'Detected object' that there is a delay. All other sensors work perfectly like motion and doorbell ring (and all the other integrations).

It could also be that Unfi Protect (not the integration) takes a bit more time to detect something like 'person' or 'vehicle' and so is a bit slower to pass the data to the integration.

I have added 2 examples. The 'motion' sensor is perfect on time. The 'detected object' is with a lot of delay.

HA has enough memory and cpu. Only 3% CPU usage

Motion sensor : OK doorbell_motion Detected object : delayed doorbell_person .

AngellusMortis commented 2 years ago

Smart detections are not treated any differently than any other sensor in HA. If they are then only sensor being delayed, it is not coming from HA or the HA integration. It is coming from UniFi Protect.

In UniFi Protect, smart detect events are child events for motion events, so UniFi Protect might be reporting the start of the motion event, not the smart detect event and not telling you when the smart detect event was actually started.