Custom Component: Unifi Protect

Thanks for the piece of advice @briis. I tried setting the polling time to 6s and still notice the unavailability events. See attached image

I cannot seem to find a pattern. I first believed it was happening when the camera was set to never record but it doesn’t appear to be valid. Also, the second camera (Main entrance) is not even connected to the network and also gets these unavailability events.

Edit : I should have mentioned that the green bars are detected motions while the grey ones are the unavailability events.

Quick check: Can you look in the Unifi Protect App or Web interface, and check if the disconnects are also recorded in there? I have had reports on this before, and it turned out to be the cameras disconnecting from Unifi Protect, and thus we will see this disconnect here also.

Anyone know if the API changed recently? I’m getting “Unauthorized” errors and my automations are failing as a result. I tried to re-input the password, just on the off chance that it has somehow been corrupted, but I can’t find a way to change my password after installing the integration. Does anyone know how to do this? Thanks.

Hi Brett,
From an Authorization perspective, the API has not changed. Currently he only way to change your password, is to remove the Integration and re-add it. As it uses UniqueID’s, it should not have any implications on your Lovelace Views and Automations.

Well, I deleted and re-added the integration, but as a result, all my automations had to be set up again. I had to go back to each of them and re-select the device and entity that I wanted to use as the trigger and set the time delays again. But, at least it worked. Is there not a way to make it possible to change details of an integration without having to completely uninstall it?

is there any chance this component could eventually ingest the people detection events that Unifi Protect now has? would love to create HA automations based on detection people, rather than motion

Hi Peter,
What can be done is telling you if a person is detected or not, but currently I cannot send you the footage with the bounding box. If that is what you are looking for, please create a request on Github

Sorry about that. I have done it a few times, without having to change anything afterwards.
I will see what I can do, to give you the possibility to change the NVR settings after the integration has been added.

Thanks @briis. I noticed that I am getting the same behavior with the Shelly, Unifi Protect and Sonos integrations. Probably need to sort that out first :slight_smile:

Release 0.5.8

Object Detection was introduced with 1.14 of Unifi Protect for the UDMP/UNVR with the G4 series of Cameras. (I am unsure about the CloudKey+, but this release should not break on the CloudKey+ even without object detection). This release now adds a new Attribute to the Binary Motion Sensors that will display the object detected. I have currently only seen person being detected, but I am happy to hear if anyone finds other objects. See below on how this could be used.

This release also introduces a few new Services, as per user request. Please note that HDR and High FPS Services will require a version of Unifi Protect greater than 1.13.x. You will still be able to upgrade, but the functions might not work.

  • New feature: Turn HDR mode on or off, asked for in Issue #119. Only selected Cameras support HDR mode, but for those cameras that support it, you can now switch this on or off by calling the service: unifiprotect.set_hdr_mode. Please note that when you use this Service the stream will reset, so expect a drop out in the stream for a little while.

  • New feature: Turn High FPS video mode on or off. The G4 Cameras support High FPS video mode. With this release there is now a service to turn this on or off. Call the service unifiprotect.set_highfps_video_mode.

  • New feature: Set the LCD Message on the G4 Doorbell. There is now a new service called unifiprotect.set_doorbell_lcd_message from where you can set a Custom Text for the LCD. Closing Issue #104

  • New attribute event_object that will add the object detected when Motion occurs to the Binary Sensor binary_sensor.motion_CAMERANAME. It will contain the string None Identified if no specific object is detected. If a human is detected it will return person in this attribute, which you can test for in an automation. (See README.md for an example)

3 Likes

Thanks @briis! Excellent new features :+1:

Do you know if object/person detection is available on all the G4 series cameras, or just the G4 Pro? I haven’t seen a definitive answer other than that it isn’t available on G3 and it’s available on “some” G4-series cameras.

I believe it works on all G4 cameras.
It defintely works on my G4 Bullet and doorbell cams.

1 Like

Yes, this is also what I can read. I have G4 Pro and Doorbell, and it works on all of them. But it does not work on my G3 cameras

Release notes of unifi protect 1.15.0 state very clearly… :

Improvements

  • Cameras: Improved zone detection accuracy with “Enhanced” motion algorithm
  • G4 cameras: Smart Detection
  • G4 cameras: High Frame Rate mode
  • G4 Bullet: Improved image quality with enhanced contrast in HDR night mode

The doorbell is also a G4 series. :slight_smile:

Release 0.6.0

The Integration has now been rewritten to use Websockets for updating events, giving a lot of benefits:

  • Motion and doorbell updates should now happen right away
  • Reduces the amount of entity updates since we now only update cameras that change when we poll instead of them all.
  • Reduce the overall load on Home Assistant.

Unfortunately, Websockets are only available for UnifiOS powered devices (UDMP & UNVR), so this will not apply to people running on the CloudKey. Here we will still need to do polling. Hopefully Ubiquity, will soon move the CloudKey to UnifiOS or add Websockets to this device also.

All Credits for this rewrite goes to:

  • @bdraco, who did the rewrite of both the IO module and the Integration
  • @adrum for the initial work on the Websocket support
  • @hjdhjd for reverse engineering the Websocket API and writing up the description

This could not have been done without all your work.

Other changes

  • When setting the LCD text on the Doorbell, this is now truncated to 30 Characters, as this is the maximum supported on the Doorbell LCD. Thanks to @hjdhjd for documenting this.
  • Fixed an error were sometimes the External IP of the Server was used for the Internal Stream. Thanks to @adrum for fixing this.
  • Added Switch for changing HDR mode from Lovelace (Issue #128). This switch will only be created for Cameras that support HDR mode.
  • Added Switch for changing High FPS mode from Lovelace (Issue #128). This switch will only be created for Cameras that support High FPS mode.
  • Improved error handling when communicating with Unifi Protect.
  • Added German translation for Config Flow. Thank you @SeraphimSerapis
5 Likes

I have been watching this thread and waiting for this rewrite. I can now finally integrate my UDMP with HA. Thank you all for your work on this component.

1 Like

Release 0.6.1 is out

@bdraco strikes again and fixed the following problems:

  • If the system is loaded, we miss events because the time has already passed.
  • If the doorbell is rung at the same time as motion, we don’t see the ring event because the motion event obscures it.
  • If the hass clock and unifi clock are out of sync, we see the wrong events. (Still recommend to ensure that unifi and hass clocks are synchronized.)
  • The Doorbell is now correctly mapped as DEVICE_CLASS_OCCUPANCY.

so when the doorbell is pressed, it becomes occupied? is that the desired outcome?

hmm, my G4 cameras do not appear to write that they identify humans back to HA. I confirmed in the below example that Unifi Protect detected a human (sent me an app alert + its listed in Smart Detections within Unifi Protect)

Home Assistant 0.117.2
Integration 0.6.1

It’s going to be a game changer to only have people identification alerts at certain time ranges!!

Hi Peter,
It does work. Try and make an Automation like the below, and you should get a notification if a person is detected on your camera. The event_object attribute is reset when your motion sensor goes back to clear

What would you have expected to happen?

alias: Send message when person detected
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.motion_garage_porch
    to: person
    attribute: event_object
condition: []
action:
  - service: notify.iphone
    data:
      message: A person has been detected on the Camera
mode: single