-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unifi Protect Notification Videos randomly fail. #132524
Comments
Hey there @RaHehl, mind taking a look at this issue as it has been labeled with an integration ( Code owner commandsCode owners of
(message by CodeOwnersMention) unifiprotect documentation |
Automation I'm using:
Debug logs during a bad notification:
|
Thinking out loud here... when the automation requests the
I wonder if there is something going on with the Or -- perhaps exports fail when there is an ongoing event? |
Requesting a 10 second clip that ends 2 seconds in the past via the
Those bash commands will evaluate to a datetime that is 12 seconds in the past, and 2 second in the past. This is making me rethink that perhaps requesting a video clip with an end time too close to Perhaps this is a feature request to add logging to |
@bdraco and @RaHehl -- would it be okay if I added a pull request to A\ specific logging within the (My recommendation would be more general logging, via option (B), but I am open to your advice here.) In either scenario I would log 2 new things: (1) the request parameters, and (2) the response status code. The goal of this PR would be to more visibly log when requesting a video fails, along with details of the request that failed. Right now, if |
@ianalexander I can't speak for @bdraco, but my thought is that debug logging is generally a good idea as long as it's disabled by default. |
Its a bit hard to tell if debug logging is a good idea or if it will have a significant performance impact (even when disabled if it has expensive argument formatting, although this is rare but happens more often than you would expect) until I see an open PR |
I've spent a little more time debugging this today. Here is the current status of what I know, and am still trying to debug:
I've added some logging in my fork and confirmed that this happens when the server returns 500. In
@lutzvahl - given your recent work in this area, maybe you could advise on the best path forward? I would propose two options to consider: A\ I can submit this fork that implements retries for I would recommend (A), as I am currently using this fork in my live home assistant instance and it's definitely working better for me. I still get the occasional error from unifi protect, but the overall failure rate is much less since it will retry if the initial response is 500. |
Thank you for the valuable and detailed analysis of the issue. I really appreciate the time and effort you’ve put into debugging this. Personally, I don't think implementing retries is the right solution. Ideally, we should aim to reproduce this issue using the Protect Web UI or app and then escalate it to the Unifi team for resolution. From my own experience, I know this can be a challenging process, but addressing the root cause is the proper way forward. Implementing retries feels more like a patch than a solution, and it risks masking the underlying issue rather than resolving it. Alternatively, as you mentioned, it might be worth exploring the new API pattern used by the Protect Web UI (/proxy/protect/api/video/prepare and /proxy/protect/api/video/download). However, I’m not deeply familiar with that part of the implementation, so I can’t confidently say if it’s the better path forward without further investigation. |
Thanks @ianalexander for raising the issue and looking into this. IMO we should not add a video_retry() because the _get_image_with_retry() fulfils the use case to provide the image once the event is over. This assumption is not true for the video case. Let's look into the new unifi protect APIs used to download an event video:
@ianalexander Can you create a PR to change the get_camera_video() API function? Happy to help with the implementation |
Thanks for the kind feedback -- you all are the experts so I think it okay not to do retries. After thinking about it more, you're right that it doesn't really solve the underlying issue.
Yes, I can take a stab. This will be my first contribution so I will definitely need your guidance on getting this merged.
While I think that switching to the new API calls should work, I don't know for certain it will. @RaHehl in the event we do need to communicate with the Unifi team would you be able to do that? |
Well, I spoke too soon. I did successfully implement the This curl command will maybe ~5-10% of the time return 500. It happens more frequently if I do ~3 or so quickly one after another:
Those variables in Is this a "my system" problem? Or can any of you reproduce this issue? |
After SSH'ing into by UDM and tail'ing logs while making the curl request above that returns 500 occasionally here are the error messages I see:
This is so strange because it seems to happen randomly. Sometimes it will peacefully export, other times it will start throwing 500. edit: Accidentally closed, then re-opened |
Have you notice that the issue happens only when you are connected to the same network where your HA and UI are? Try. I have the same exact issue and I start thinking it is a dns/reverse proxy issue. |
Scratch that, I added a 2s delay and now it seems to work. Edit: it still happens. Not sure what else to try. |
Still can't pin down the issue here. Two more observations
core/homeassistant/components/unifiprotect/views.py Lines 58 to 63 in 2117e35
With this in mind, I think this narrows down the issue to one of two potential root causes: I no longer think the issue lies in |
Do you think there will be a fix on the UniFi Protect integration, or it is something we need to figure out on our own? |
I've spent more time debugging this -- but can't seem to figure out exactly what the issue is. I've submitted a PR to the As I mentioned above, today I still believe the two potential causes I wrote in my last comment are the best guesses, but I am unable to reliably reproduce the issue: #132524 (comment) For anyone else who has this issue: the first step to fixing is to find a reliable way to reproduce the issue. Any help in this area is appreciated! |
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. |
The Problem
Using 2024.12, I have an automation setup using the suggested implementation in the docs. About ~20% of the time, this integration fails to generate a video for the notification, and instead returns this error:

Things I've Tried
A. I've tried pausing the automation 30s prior to the notification sent, testing if this was some kind of issue with the
event_id
not being ready to generate a video. This did not work.B. I've tried implementing a cool down, only allowing one notification to be sent every 60s, testing if this was some kind of concurrent request issue. This did not work.
Current Hypothesises
uiprotect
library that fails to generate the videoOther observations
video
and successfully download the video, which is what made me initially think this might be some kind of race issue.event_id
is always successfully obtained, so I believe this is not related to issue UniFi Protect - No Longer Consistently Providing {event_id} as attribute from detection sensor for thumbnails #130577core/homeassistant/components/unifiprotect/views.py
Lines 248 to 249 in 16484dc
I recognize this is probably not enough information. Any help on how I can better debug this issue would be great! Thank you for reading this issue.
What version of Home Assistant Core has the issue?
core-2024.12.0
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
unifiprotect
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
The text was updated successfully, but these errors were encountered: