[PROJECT] Driver for Unifi Protect Controllers

It should be possible for it to be recognized although I am not sure what additional functions would be available. I would have thought it would get added in as a child device with the UnifiProtectChild driver right now (I have not made a specific child driver for NVR devices because of the limited functions presented in the Protect API for them).

Is it not showing up?

If not, or if you want me to better recognize it in general, you can message me with a Trace log recording from when you do a GetProtectInfo command. That data would let me look over the devices reported and see where/how it got assigned. My UDMP gets tossed into the NVR category by the Protect API so it might be interesting to see if it gets any relevant differences. Of course if you do message me with the log (do not post it here) you can feel free to edit out any information you do not want me to see.

pinged you. It dosen't appear to be able to login to the NVR at all.

Ah. That is something different. This driver connects to the Unifi console (UDM, Cloud Key, PC, whatever) that is running the Unifi Protect app. It does not connect to the devices themselves, but through the API that Protect has.

I have a virtualized controller for manageing my AP's but as far as I am aware it dosen't talk to protect. Also haven't heard of a 'protect' app for PC since unifi video was discontinuted.

Hmm... I do not know enough about them to know the capability of a virtualized controller.

Sorry if I am going to seem dumb, but I want to try to understand how it all works better.

How do you access your cameras?

I dont think it would be nessasary here anyways since the two systems don't talk to each-other.
To access my cameras I would go to https://hostname/protect/dashboard for local access or via unifi.ui.com

@snell: Would you possibly be able to add PowerCycle PoE for individual ports to the USW Flex like exists for the other USW PoE swithes? Your driver is recognizing mine as a USF5P, which I think is correct, but the functionality isn't there .

image

Edit: It was easy enough for me to just copy the code from the 48 port driver, so I don't need you to do this for me, but it is still something that you might want to add to all PoE distribution switches.

I think this is meant over in the Unifi Network project... :slight_smile: but I can certainly do it. Sometimes I remember to do this stuff when adding in new devices (I actually have one myself) and sometimes I totally forget about it. Thanks for pointing it out! Obviously it would only be for ports 2-5 because we would not want it trying to do it to itself (not that I am sure the API would allow it) since who knows what would happen.

Changes done. I will post about the change in the main project thread.

1 Like

Yeah, sorry, I admit that I stopped reading at 'Unifi' in the title.

1 Like

Hey @snell , I just started playing around with UniFi Protect and got a G5 Bullet to start. First thing I did on Hubitat side was to install your drivers...wow! Nice work!

One question - I am looking into Motion Zones on the UniFi side to see if there is anything cool I can do on the Hubitat side with it (e.g. walk up my driveway after dusk and the entryway lights brighten; approach my windows after 10pm and you get the floodlights/sprinklers, etc.) Is there any support in your drivers for this, or is it even possible to get that granular from the API? I'm happy to provide logs if it will help!

Either way, much appreciated for the work so far!

There is not anything in there now but if it is something you can do through the web interface of the controller it is likely something that CAN be added to the driver (with some limitations). I do not have a Unifi camera with motion zones (my G3 Instant does not appear to show anything) so I have no easy way to check it myself.

What types of features are you looking to control?

If you are willing to try some things out, shoot me a private message and I can give you some instructions on how to capture commands or other useful information from the driver AND Unifi controller. Then we can see about getting more features in!

1 Like

Updated Version(s):

  • UnifiProtectAPI.groovy = 0.2.23
  • UnifiProtectChild-Sensor.groovy = 0.1.1

Change(s):

  • Added recognition of additional data, particularly around the sensor device, which required changes to the Sensor child driver as it added a couple capabilities and a number of new attributes.
  • Adds ability to force child events to be isChanged, matching some of my other drivers.
  • Including CSRF in Login even if null.

OK I installed the drivers for Unifi Protect. I am mainly interested in getting events for the Smart Sensor (I am using it as a door contact sensor for now). I can see the child device created for the sensor, but I don't see any status reported for contact (open/closed) in the device page. I do see the last motion reported though, but since the parent driver can only be configured to poll the stats every 5 mins at the minimum, it's not very real time. Any way to poll the smart sensor events more frequently (specifically for motion and contact)?

Thank you again for making the drivers!

You need to enable the WebSocket capability to get "live" responses from the API.

On a different note:
It has been a while since I checked anything in these drivers for the API and it appears Ubiquiti has made changes. I am posting updated drivers for just about every part of it and will try to do some more checks in the near future.

Updated Version(s):

  • UnifiProtectAPI.groovy = 0.2.25
  • UnifiProtectChild-Bridge.groovy = 0.1.4
  • UnifiProtectChild-Camera.groovy = 0.1.8
  • UnifiProtectChild-Doorbell.groovy = 0.1.7
  • UnifiProtectChild-Light.groovy = 0.1.6
  • UnifiProtectChild-Sensor.groovy = 0.1.3

Change(s):

  • Overhaul of how GetChildStatus and SendSettings commands work as they are no longer as generic as they used to be and must be more specifically structured per type of child.
  • Change to how illuminance/temperature/humidity are handled for Sensors as the data was now coming back as the value AND a status
  • Additional preferences added for Sensor to allow enabling/disabling various parts of the sensor as well as setting thresholds.
  • Additional attributes added for Sensor to accommodate Alert status returned
  • Addition of Locate command to Sensor

Known Issue(s):

  • When Temperature Low/High Thresholds are set via the Preferences for a Sensor child device the actual values set on Unifi Protect may be very slightly different if the Hubitat uses Fahrenheit (F). This is because the API handles temperatures in Celsius (C) and the Thresholds are being converted. Should not impact people with their Hubitat using Celsius as that should not be converted.

Thank you for the quick update! I got the new drivers installed and now can see the contact status.
However, I still cannot see live updates from the sensor. I have WebSocket enabled and can see that when I walk in front of my G5 camera, the motion status changed to active instantly. However, if I open the door in which I have the sensor installed, the contact status doesn't change. I have to either click refresh or wait 5 minutes for the polling to check in order for the status to change. Is there anything I need to do for the sensor?

I will have to look into it with my sensor. There might have been a change to how the contact data is being reported so maybe it is not recognizing it anymore.

UPDATE:
Just to check for yours, in the Events to Capture section of the Sensor within Unifi Protect, what do you have selected for the Placement? I found that the contact sensor does not report the contact with the setting of None, but will with the rest. However, I definitely need to make changes to have it recognized properly. Working it right now.

I selected Door for the Placement (I presume that's how I would make it a contact sensor). I also selected Motion under Detect section. Everything else is not selected. BTW I can see logs of Door opened/closed as well as motion detected under the Activities section of Unifi Protect, so the device is definitely sensing things.

Updated Version(s):

  • UnifiProtectAPI.groovy = 0.2.26
  • UnifiProtectChild-Sensor.groovy = 0.1.4

Change(s):

  • New handling for Sensor to properly identify when websocket indicates contact open/closed.
  • Handling for Sensor motion detection, although the sensor does not report when motion STOPS, it only indicates when motion is first detected. So the handling makes motion "active", waits a second, then makes motion "inactive".
  • Sensor child now has a Preference for Mounting Type/Placement. I was not aware this impacted reporting for the contact sensor until I tried more things.

Unifi Protect Driver version: 0.2.26

I'm currently see the following error in my Hubitat logs emitted pretty frequently.

java.lang.NullPointerException: Cannot get property 'text' on null object on line 211 (method parse)

Let me know what additional info you need.