UniFi Protect Binding (Cloudkey gen2+, Dream Machine Pro, NVR)

Thx for your fix!
Now it is working and i can add my NVR and the cameras!

1 Like

I do get the following events every 15 minutes:

2023-09-26 23:38:51.431 [INFO ] [ernal.event.UniFiProtectEventManager] - Watch dog Detected no events recieved, reinitializing!
2023-09-26 23:39:01.434 [INFO ] [ernal.event.UniFiProtectEventManager] - Socket failed, reinitializing!

Seems that this does not have any functional impact.

It means that no events are recieved through the websocket in 15 minutes and the binding is restarting. Do you use motion detection in any of your cameras, or ring on doorbell?
Otherwise you can turn the watchdog off in settings for the nvr/bridge

I do see now some OutOfMemory issues. Did not had them before and the only change is the activation of the Protect binding. When looking at netstat of my Raspberry i do see that currently there are 438 open network connections to my Unifi Dream Machine. When restarting the binding are all resources cleared?

To me it sounds like the watchdog is initiating a new connection on your system each 15 minutes, indicating that: The connection to the UniFiProtect websocket event api is not working on your system.
I would: Upgrade to latest version / firmware and UniFiProtect and see if you have the same issue.
Go over your network setup (is the UDM running on the same subnet etc)
You probably get memory issues to do all those connections not being terminated.

If you don’t use motion detection or doorbell ring trigger, you can safely disable the watch dog and your problems should disappear.

/S

Could possibly be related to this:

No i am not using the NEEO binding. Also my DreamMachine as well as the Protect application is up-2-date.

I do checked the code and if I am not misunderstanding anything than you simply create a new WebSocket client all the time when the old fails. That also means that you are not calling stop on the old client and that could explain the resource leaks. I can prepare a pull-request and fix that if you are OK with that?

PR:s are always welcomed.
I have added a dispose in the reinit you can see the commit here:

As far as the memory leak in oh4 goes, it might be tied to multiple bindings, not just neeo.

I still see that it is a problem that the socket get reinitialized in your system, indicating that the event api is broken for you.

BR S

Hi!

Is there any chance to implement geofencing with the binding? That would be a nice additional presence detection feature. On the unifi side the app works quite robust it would eliminate the iPhone sleep issues, etc. It would also require some sort of user management so it might be a huge task to code it down.

Thank you for this great piece of work. I use this since the first version.

What are the “iPhone sleep issues”?

iPhones tend to dissconnect Wifi AP while sleeping so there is a misleading “not connected” state but they’re still at home. There is no battery save options on device to disble it while android has this. There is a workaround pinging them with LAN binding but in this case you need to handle “dual” presence detection (one from unifi binding (not protect!) and one from LAN binding). So it is a bit of hassle.

Maybe use the iCloud binding? Or if the polling of that drains the phone battery, use a home automation on the phone to trigger a switch in openHAB.

Sure, why not. I could try and implement it when I get some spare time (sort of random). How do you intend to use it?
Channel for the nvr with all away? Or map certain users? Do you want to trigger a channel on the specific camera for the notification?

Hi @Seaside!

Thank you for your reply. The main purpose would be to detect each users defined on Unifi UDM that is away or inside the perimeter (I have all users for Doorbell Ringing added already). The app on the mobile works great and can be used with Tasker to intercept Geofence notifications but it would be more convenient to have that inside openHAB and not to install Tasker and setup rules for every phone in family.

Thank you.

Hmm, isn’t it true that geofencing in Unifi Protect does not work reliable at all? At least it is this what I can read in a lot of forums.

I haven’t searched about this as I don’t have an issue. This might be related to phone setups like app battery optimization and permission settings. But I’m just guessing. I’ll search for that. Can you give me some links to these sources?

https://community.ui.com/questions/Unifi-Protect-IOS-App-shows-away-even-though-Im-home-/8a9f0f51-8929-4379-8b0e-15cbe171bb68?page=1
https://www.reddit.com/r/Ubiquiti/comments/ub1416/unifi_protect_onsiteaway_status/

Those are 2-4 years old. I’ve found this on Reddit. It is 1 year old. Since than there are no complains.
This might be useful: link.

1 Like

@Seaside is there a jar available with containing your last commit? Or can you give some hints for building it?

BTW, I got an iPhone on Monday and so far, the standard Unifi Network online detection works fine. Maybe because I fetch IMAP Emails every 15 minutes, the iPhone never goes into super deep sleep. Or UniFi has fixed the network online detection for iPhones.