Custom Component: Unifi Protect

Long time HA user here. Recently upgraded from USG to UDM Pro and installed my first Unifi Protect camera today (G3 flex).

What a joy to bump into this integration! :slight_smile:

Kuddoā€™s to @briis

Going to experiment with the alarm panel using the motion triggers from this integration. Should be good.

4 Likes

Could you provide a little more detail on where to go to configure this, screen shots maybe? I have it installed but the instructions say to

To add Unifi Protect to your Home Assistant installation, go to the Integrations page inside the configuration panel and add a CloudKey+ or UDMP by providing the Host IP, Port Number, Username and Password.

And no where can I find a configuration panel to add the needed info to connect. I was not asked for any of this info when I installed it and there appears to not be a button to use to configure it after install.

Figures, right after I post this I find the issue and fix my own problem.

The problem was/is that when I searched for Unifi it was not being found but when I scrolled down to the Uā€™s it was there and I was able to install it and have it working now.

Wondering if anyone can helpā€¦ I have an automation that sends a push notification to my phone on when binary_sensor.motion_front changes to off for 3 sec. It works ok, but now Iā€™m trying to limit it to only alert once every 10 mins with the following:

condition: template
value_template: >-
  {{ (as_timestamp(now())-as_timestamp(state_attr('camera.front',
  'last_tripped_time')))|int > 600 }}

If I drop the template into the dev tools, it evaluates as True, but my automation never triggers. Iā€™ve also tried using binary_sensor.motion_front in my template, but I get the same issueā€¦ Any ideas?

@TazUk - I spotted you were doing similarā€¦ Does it work ok for you?

Iā€™m actually now only using last_tripped_time as part of the notification message, eg:

    - service: notify.all_mobile
      data_template:
        title: "Driveway Alert"
        message: >
           Motion at {{ as_timestamp(state_attr('binary_sensor.motion_driveway', 'last_tripped_time')) | timestamp_custom('%H:%M') }}.
           Score: {{ state_attr('binary_sensor.motion_driveway', 'event_score') }}. 
           {% set time = (state_attr('binary_sensor.motion_driveway', 'event_length') | int) %}
           {% set mins = ((time % 3600) / 60) | int %}
           {% set secs = time - (mins * 60) %}
           {% if time < 60 %}Length: {{ secs }}s
           {% else %}Length: {{ mins }}m {{ secs }}s
           {% endif %}

Iā€™m just using a standard delay of 5 seconds
- delay: "00:00:05"
to try and ensure that the Cloud Key has generated the thumbnail to attach to the notification.

You may find that the 0.113.x introduction of a cooldown through the combining of the single run mode (the default) with a delay of 10 minutes at the end of the automation would be a more straightforward way of achieving the same end.
Iā€™ve literally spent last weekend refactoring my automations (reducing from 133 to 77 with the use of the chooser etc.) but havenā€™t yet looked at my camera notifications with 0.113.x eyes, aside from adding a run mode (I favour explicit declarations rather than implied).

Legend! Just reading the docs nowā€¦ I just add a 10min delay for a cooldown. I like it.

Thanks :slight_smile:

1 Like

Is there any way to set a timeout or similar when unifi data is requested? Iā€™ve seen the following happen twice todayā€¦ In the logbook all my unifi stuff moves to Unavailable for 3 seconds before returning to correct statusā€¦ Makes a few of my automations do some funky stuff as wellā€¦

2020-07-29 13:18:47 ERROR (MainThread) [custom_components.unifiprotect] Error requesting unifiprotect data: None
2020-07-29 13:18:50 INFO (MainThread) [custom_components.unifiprotect] Fetching unifiprotect data recovered

Has anyone played around with automations for the G4 Doorbell? Iā€™ve got a Node Red flow going to 1) make an announcement on my Echo Show and 2) take a camera snapshot and send as a push notification to iOS upon button press.

I did try to send the live video stream within the push notification, which worked, but the video was almost 15 seconds behind ā€œreal timeā€ which isnā€™t too useful for a doorbell use case.

Really interested in any other creative things people are thinking about doing with their G4 doorbells!

Yup! If my office Hue lights are on, they flash red five times when the doorbell is rang, then go back to the previous setting.

1 Like

I found this component a few weeks ago and it is awesome! It opens up so many possibilities. Thank you all for posting your automations! I was able to add the push notification with thumbnails and some other nice features. I do have a few things I canā€™t figure out.

  1. Thumbnails on my phone are super small. Iā€™ve tried to play with sizing but nothing changes. What am I missing.

  2. I only get the thumbnail from in home. I have Nabu Casa enabled, but still never get them from away.

  3. Sometimes I get the thumbnail on my apple watch and other times not. Itā€™s about 1 of 3 times. Any ideas?

I can not for the life of me get my RTSP streams from any of my Unifi Protect Cameras to be a real-time stream with this custom component.

Using the picture entity card it loads 15 seconds in the future even with the mode set to Live. Not very helpful for a security system. I have tried the preload checkbox but doesnā€™t seem to make any difference.

Everything else in this integration works great.

This issue has been mentioned a few times, and unfortunately, there is nothing I can do about it. Other cameras supply a different stream type, so you can tweak the buffers etc. But Unifi Protect currently only supplies live streams as an RTSP feed, where you cannot tweak anything. I have the same experience on my system.
If anyone with more video stream experience than me, has some clues how we could fix this, I would be happy to hear from them.

I donā€™t think itā€™s a great solution, but what I found is if you install the MotionEye add-on to bring the video in from the UniFi cameras via the RTSP feed, and then use the MotionEye feed and create mjpeg cameras in HA you get a live feed. Overhead doesnā€™t seem too bad as Iā€™ve turned off motion detection in MotionEye.

Yeah, I donā€™t use this for camera feeds. I just setup a generic camera with the rtsp address through homeassistant. Donā€™t enable the ā€œstreamā€ feature, and it should stay live. Not sure why stream breaks that currently.

Unifi protect does not show up

Hello Bjarne.
I love the work you have done here, but this trick does not help on my instalation.
You got any tips?
I do find the Ubiquiti UniFi addon.
Home Assistant 0.114.2
SkƄl fra Norge!!!

Hej
How did you install it? Through HACS? Try to clear the Cache of the Browser.

Hi.
It is in a docker container on a NAS.
Yeah did clear cache, and also two different browsers.
Thank you for your effort.
Regards

Strangeā€¦
Just to make absolutely sure (and you might have done this already):

  1. You have installed the Unifi Protect Integration through HACS, and if you browse the custom_components directory you have a unifi_protect directory with files in it, and one of them is config_flow.py
  2. Click the Settings Tab on the left side
  3. Click Integrations
  4. When on THIS page, force refresh your browser
  5. Click the + Sign in the bottom right, and search for Unifi Protect

With this, is the Integration still not showing?

Aha, sorry. thought it was native included in the distro.
So i missed out on the need to add it manualy before enabeling it. Sorry about that.
Il look into tonight.

1 Like

I have not come to the point of making this an official component yet. But hopefully one day, I will figure out how to setup tests and such, and then make a PR.

2 Likes