Custom Component: Unifi Protect

0.8.0

Released: January 9th, 2021

This release adds support for the new Ubiquiti Floodlight device. If found on your Protect Server, it will add a new entity type light, that will expose the Floodlight as a light entity and add support for turning on and off, plus adjustment of brightness.

There will also be support for the PIR motion sensor built-in to the Floodlight, and you will be able to adjust PIR settings and when to detect motion.

You must have UniFi Protect V1.17.0-beta.10+ installed for Floodlight Support. Below that version, you cannot add the Floodlight as a device to UniFi Protect.

THANK YOU again to @bdraco for helping with some of the code and for extensive code review. Without you, a lot of this would not have been possible.

  • ADDED: New light entity for each Floodlight found. You can use the normal light services to turn on and off. Be aware that brightness in the Protect App only accepts a number from 1-6, so when you adjust brightness from Lovelace or the Service, the number here will be converted to a number between 1 and 6.

  • ADDED: A Motion Sensor is created for each Floodlight attached. It will trigger motion despite the state of the Light. It will however not re-trigger until the time set in the Auto Shutoff Timer has passed.

  • ADDED: New service unifiprotect.light_settings. Please see the README file for details on this Service.

  • FIXED: Missing " in the Services description, prevented message to be displayed to the user. Thank you to @MarcJenningsUK for spotting and fixing this.

  • CHANGED: Bumped pyunifiprotect to 0.28.8

IMPORTANT: With the official FW 2.0.24 for the CloudKey+ all UniFi Protect Servers are now migrated to UniFiOS. So as of this release, there will be no more development on the Non UniFiOS features. What is there will still be working, but new features will only be tested on UniFiOS. We only have access to very limited HW to test on, so it is not possible to maintain HW for backwards compatability testing.

This release is tested on:

Tested means that either new features work on the below versions or they don’t introduce breaking changes.

  • CloudKey+ G2: FW Version 2.0.24 with Unifi Protect V1.17.0-beta.13

  • UDMP: FW Version 1.18.5 with Unifi Protect V1.17.0-beta.13

1 Like

@briis : Since this issue is seen by others (autoplay no longer working within Lovelace on iPads, possibly due to audio stream), could you recheck if it really works for you?
No autoplay of camera streams in lovelace anymore with unifi protect devices · Issue #8041 · home-assistant/frontend (github.com)
Thanks!

Hey.

I’ve been looking around for some projects to help out on and are waiting for some more Protect gear to arrive then i’ll be happy to help test (and develop once i get the hang of the process involved in HA dev).

My setup to arrive within a week that i can help out with the testing should be something like this:

  • 4 Bay Protect NVR (NVR-EU)
  • 1 pc UVC-G3-BULLET
  • 1 pc UVC-G3-FLEX
  • 1 pc UVC-G3-MICRO
    (more cameras will be added in time, first out the doorbell when available in Sweden)

I’m currently starting to get involved in some other projects so my time will be somewhat limited but happy to help out in any way I can when all the hardware has arrived, if interested?

Best Regards
Simon

I rechecked, and I now get the same behavior BUT only on my G3 series CAM’s. The G4’s all do livestreams in Lovelace. Again, all we do in the Integration is supply an RTSP address, so it must be the stream component in HA.
I am not the expert on streams, but I would assume that there must be a difference in how the RTSP stream is constructed in the G3’s vs. the G4’s since it work with the later.

The difference also shows when clicking on the image. The G4’s start playing immediately, where the G3’s need me to click on the play button.

Sounds great Simon. When you have your equipment setup, let me know where you would like to help out. Always love to get help.

Hey briis,
With the new Ubiquiti breach I have setup 2fa on my Ubiquiti account. Do you have any way of getting your integration to work with 2-factor authentication enabled on a Ubiquiti account?

This integration is purely local, so it is not using the Ubiquiti SSO. You create a local user that can only be used within your local network (or a VPN connection).

So 2FA is not supported, but also not needed.

2 Likes

Yeah, don’t know what happened but as soon as I changed my password for my Ubiquiti account and setup 2fa my integration stopped working. You are 100% right, I was able to get it working again just by adding the local user that I forgot I had setup. Not sure what happened but I am back up and working! Thanks

1 Like

I have had another user reporting this, so it seems that if you activate 2FA after you have created local users, the permissions for these users are reset to Non Admin mode, and you need to re-active the Admin permissions in the UniFi Protect App or Web.

@briis Would you be so kind and enter your experience in the bug report for Home Assistant as well? That way, the developers get a chance to fix the problem: https://github.com/home-assistant/frontend/issues/8041

Thanks!

Done - made a comment in the bug.
And btw it is not only on iPads. I can reproduce it on my Mac in both Google and Safari browsers. As said earlier, G4 cameras work fine, but G3 cameras won’t live stream until you press the play button.
Just to ensure this has nothing to do with the Protect Integration, I set up one of the Cameras as this:

camera:
  - platform: generic
    name: Test Camera
    still_image_url: http://192.168.1.xx/snap.jpeg
    stream_source: rtsp://192.168.1.1:7447/MY_TOKEN

and this gives the same result.

Protect 1.17.1 GA official released this morning.

1 Like

Release notes

Looks like I’ll have to have a play at the weekend:
* G4 cameras: Add vehicle detection.

1 Like

Hey, really stupid question I’m sure - Brand new user here.
I have a UDMP and with HA installed (.ovf image installed onto QNAP as a VM) as per the instructions.

Instructions say that this is only available via the integrations page. Yet I can’t see the Protect integration available.

Where am I being stupid please?

You need to add HACs to HA and then install the component files using HACs.
This will then enable you to add the integration to HA.

For HACs installation: https://hacs.xyz/docs/installation/prerequisites

1 Like

Hi – awesome integration, works great for me. I created a binary sensor so I can only be alerted by smart detections of people (g4 cameras). It is able to pick up the motion sensors, however, the binary sensor stays “on” for hours afterwards and only periodically is reset to off (and I’m not sure what triggers the “off”. Below is my template configuration, any thoughts? I thought putting the delay_off would trigger it to go off after 5 minutes. Thanks

binary_sensor:
  - platform: template
    sensors:
      person_doorbell:
        friendly_name: "Person Detection - Doorbell"
        device_class: motion
        delay_off: "00:05:00"
        value_template: "{{ is_state_attr('binary_sensor.motion_doorbell', 'event_object', 'person') }}"
      person_backyard:
        friendly_name: "Person Detection - Backyard"
        device_class: motion
        delay_off: "00:05:00"
        value_template: "{{ is_state_attr('binary_sensor.motion_back_porch', 'event_object', 'person') }}" 

The easiest way to detect if person or vehicle in an automation is to watch for the event_object attribute. The G4 cameras will update this, when Smart Detection is triggered.
So you don’t need to create a Template sensor, just add the below to an Automation Trigger (Change Entity to your own Entity)

trigger:
  - platform: state
    entity_id: binary_sensor.motion_doorbell
    to: person
    attribute: event_object

It still works very well with CK FW 2.0.26 and UniFi Protect 1.17.2 :slight_smile:

However, I don’t know why the video are not “live” on my iPad’s Lovelace dashboard.
I need to click on the image and then to click on Play to start the video stream (and there is still a few seconds of delay). Is this a normal behavior? Or is it necessary to do something special on the card to really have the live stream of the camera (G3 Flex)? Thanks.

I don’t have any issue when using the same dashboard on my Mac. The video is live for all my camera.

Here is the code I’m currently using.

  - type: picture-entity
    entity: camera.g3_flex_maelie_2
    show_name: false
    show_state: false
    camera_view: live

Oups. Should have read the previous posts before, sorry.
I see that it is a known-issue on iPad for G3 UniFi camera.

You are right for Safari, G3 cameras are not live.
But I have no issue on my Mac (Mac Mini M1) with Firefox browser. It works well.

I’ll give a try using Firefox on my iPad.

EDIT: No, unfortunately it doesn’t work better with FireFox on the iPad.