Ubiquiti UniFi Video and Protect NVR Integration

This is a really great project! Thanks so much for adding this. I realize I am late to the party, but I just wanted to say thank you as I am using this now as well.

Also, is there github integration for this? I would like to add it is possible unless it really isn’t something you plan on keeping updated any further.

Regardless, great effort and very much appreciated. I would like to try and get this working in actiontiles to see the video feed rather than a picture on motion is possible. Im sure that is a much different situation though as they ONLY support mjpeg.

Any thoughts on a way around it other than blue iris?

Thanks again!

Is there any chance this integration could be updated to show properly in the new app? It works great in the classic app, but in the new app it never shows any of the images.

I haven’t migrated to the new app yet. I also took down my NVR since switching to Protect so its unlikely that I’ll get to testing that configuration any time soon. If someone provides a patch (or a GitHub PR) before I get around to it, I’ll integrate it into the mainline.

Great work cvincent. Just implemented UNIFI protect myself and found this thread looking to integrate with SmartThings. Are you intending to replicate for Protect what you created for the NVR solution previously ? Is the current lack of an API a showstopper for seeing the cameras in SmartThings, even if it is just as a motion sensor ? Thanks in advance.

1 Like

I finally have an instance of Protect running with some cameras. I took a quick look at whats going on and there does appear to be an HTTP-based API for a few things but the majority of what is going on is WebRTC, which isn’t supported for Device Handlers. I’m not holding my breath for providing Protect support, unfortunately. I’ll try and reverse engineer some things and go from there.

1 Like

I have been wanting to write a Protect driver for Hubitat, I got started following this code and made some progress but have been to busy to get any results yet.

Well, what do you know, the API does exist! Fantastic! I just logged in with a quick test based on that code so it turns out this might lead to something. I’ll work on it.

Awesome! Keep me posted because I want to get this running on Hubitat

Ok @ArstenA, @stoutm, @Cory_Booth, @RobStanley I have released a version for Protect. I broke it out into a new Smart App and Device Handler since there was enough different that its probably time to deprecate NVR integration and run a new one for Protect. I don’t have the NVR to test against any changes so I couldn’t risk breaking it.

Let me know if it works. I briefly tested the same functionality that the NVR version had so hopefully its good to go.

2 Likes

Which port do the devices speak on?

My devices are on seperate VLANs and I got it to detect my cameras and add them to Hubitat. But not for each camera I get this error:

dev:9482020-04-19 07:49:20.112 pm errornvr_cameraPoll() - Back Yard (UVC G3 Flex) failed to return API call to NVR

dev:9482020-04-19 07:49:15.193 pm warnnvr_cameraPollCallback: Back Yard (UVC G3 Flex) camera disconnected or motion not enabled

dev:9482020-04-19 07:49:02.833 pm warnnvr_cameraPollCallback: Back Yard (UVC G3 Flex) camera disconnected or motion not enabled

I setup motion triggers and the one warning has gone away. I still get

failed to return API call to NVR

periodically. I have 4 cameras I don’t know if that could be the problem? They take longer to complete? Also maybe the VLANs are a bit slower too since it goes through a firewall?

That warning is pretty regular. Its been that way for years and is the reason I put in that watchdog. The send hub action sometimes just doesn’t execute or return and I’m not sure if that is due to rate limiting, random error or ? If it clogs up the logging, just comment out the line that creates the log.

Got it installed and running… Doesn’t appear to detect motion, however.
Still looking…

From what I can tell, it appears motion is detected by the OEM UniFi Protect registering motion. thus if I have a specific schedule around my camera, then motion via SmartThings would follow the same - correct?

And, since alerts/motion are alerted by schedule determined by the user - it would also matter which account is logged in as well - correct?

Yes, it is based on whatever Protect returns and not the camera itself. If Protect follows a schedule and that schedule is user-based then all those factors will apply to this integration.

Thank you! I am looking at these for now…
Despite the logs, everything appears to be fine - minus motion thus far.

Thank you cvincent, device handler and smartapp installed and cameras now appearing in ST.

Only issue looks to be same as Cory with motion alerts being created by UniFi Protect but not registering in ST Hub.

Alerts are being created by UniFi Protect

image

Camera is connected and I can grab a snapshot but motion not registering in ST

Thanks again for your work on this

This may have already been said, but it looks like motion detection is based off of new recordings being present. You would need to have recording activated by motion and not have recording set to always. I could be wrong, but this is whats spelled out in the handler.

EDIT: If you want to leave recording set to always, comment out the motion recording requirement on line 280 in the device handler. Then, motion detection works. This seems like too simple of a workaround. I’m sure this will have unintended consequences. Tell me why this is a bad idea.

EDIT2: I get these errors for cameras that have detected motion, but everything still seems to work.

Screenshot_2020-05-23 10.59.41_JNg9NW
Screenshot_2020-05-23 11.08.25_83DVCY

Thanks Dagger969, I found the same by changing the setting in the Recording/Motion Events menu for each camera from ‘Always’ to ‘Motion Detection’ it would then function as a motion sensor to trigger other actions. Given that 'motion ’ is detected and listed in the ‘Events’ tab by UniFi protect with a camera set to ‘Always’ record I had hoped making this change would not be necessary but will try your fix above and see if it works for me too.
I believe that the first error in your log above is known and happens on all cameras as per below for me but will look out for the second once I make this change.
image

That change to line 280 is the correct change and I have updated the device handler in master to reflect that. It was a carryover from NVR where it didn’t report motion times unless the camera was configured to record on motion. Protect does a better job where it tracks motion events even when set to always record.

The errors about failing API calls and watchdog expiration are real but due to retry mechanisms they are mostly benign.