Custom Component: Unifi Protect

Great idea, that was new to me also :smile: As @TazUk says there is no live stream available in the API except for the RTSP, and honestly I would not know how to link directly to the IOS App. I am poking around to see if I can find a way to link directly to the recording that has been done on the server, so that you can attach that link - but as you know, the API is not documented, so it is a lot of trial and error.

Thanks for posting that example! Why only notify when the sun is up? Do you set a different threshold for a night notification? And I imagine you tune the 6 second trigger to filter motion events that are too short?

I canā€™t take credit for the idea - I saw it mentioned somewhere in these forums.

Camera overlooks a driveway adjoining a pavement in an area with a lot of foot traffic etc. and is set to always record in Protect as weā€™ve had issues with vehicles damaging the property.

Most inconsequential passers-by generate motion events of less than 6 seconds during the day - I use longer events with a lower motion_score after sundown.

The camera notifications are controlled by an input_boolean that is toggled off around 8:30pm and back on at / after sunrise once someone in the house is awake. This prevents lots of notifications from passing vehicle headlights / security lighting from other properties.

So here is my action sequence I am using:

action:
  - service: notify.telegram
    data:
      title: Send Unifi image
      message: "Unifi motion detected"
      data:
        photo:
          - file: /config/tmp/driveway.jpg
            caption: Driveway motion detected
            actions:
              - action: "URI"
                title: "View Live Feed"
                uri: "/lovelace/driveway"

While I receive the JPG in my telegram message, I get nothing else. Any idea what is wrong and why I donā€™t receive the URI prompt? Thanks

The actions are for use with the official HomeAssistant companion apps for iOS and Android, not Telegram.

Sorry, bad example. This doesnā€™t seem to do much either

action:
  - service: notify.notify
    data:
      title: Send Unifi image
      message: "Unifi motion detected"
      data:
        photo:
          - file: /config/tmp/driveway.jpg
            caption: Driveway motion detected
            actions:
              - action: "URI"
                title: "View Live Feed"
                uri: "/lovelace/driveway"

Are you using iOS?

Does

mean no notification, no image attachment, no action link shown or?

Android and iOS mobile app notifications are built differently, and the Companion App documentation reflect that.

One thing to note is that you could simply use the camera proxy rather than storing an image (unless that is a requirement) using /api/camera_proxy/camera.<cameraname>

I believe you also (with iOS) can send a live stream - thatā€™s covered in the documents as well.
I havenā€™t used iOS with HA as weā€™re an all-Android household.

OK I have got the following.

action:
  - service: notify.mobile_app_graham_iphone
    data:
      message: "Motion detected"
      data:
        image: "/api/camera_proxy/camera.driveway"
        push:
          category: camera
        entity_id: camera.driveway
        actions:
          - action: "URI"
            title: "View Live Feed"
            uri: "/lovelace/driveway" 

I get the image in my message, but donā€™t get the ability view the live stream using the URI.

Had a look at Dynamic attachments | Home Assistant Companion Docs and it mentions getting live streams, so used

action:
  - service: notify.mobile_app_graham_iphone
    data:
      message: Motion Detected on Driveway
      data:
        attachment:
          content-type: jpeg
        push:
        category: camera
      entity_id: camera.driveway

But this produces nothing at all. Will keep digging.

Just configured this component and everything appears to work and pull correctly, except for one thing - I canā€™t get livestreaming to work right.

I had the camera working live with a generic camera beforehand, and now it seems to show 10-15 seconds prior to the feed. If I click on the video that is set to ā€œliveā€, it brings up something like the below (With a scrollable timeline). Am I doing something wrong?

Thank you!

Thatā€™s pretty much what I have - with the sames sort of time delay.

It seems to be the ā€œstreamā€ component from what i can tell. I went back to my setup, removed the ā€œstreamā€ component, set the generic camera to ā€œliveā€, and the delay is gone again.

Thank for this work Bjarne! I just set it up and most everything seems to work great. I have one minor problem. I donā€™t seem to get audio in the live view, how does that work for others? (Iā€™m using a chromium based browser, Brave)

The current camera implementation does not support audio.

Multiple Warnings when upgrading to 0.109

If you read the release notes for 0.109 there is a section on Detecting Blocking I/O. Unfortunately, the way I have written this Component gets affected by this.

It is great that this is now implemented, as it shows that my component is consuming too much cpu power. However, I donā€™t have a quick fix for this, but I am working on it.
Currently I have rewritten some parts of the component, and have the Camera part supporting 0.109 without any errors and warnings. But it will take some time before I have everything rewritten.

So please donā€™t spam this thread or the issues in Github, as I am aware of the problem, and I am working on.

You will most likely see warnings like the below in your logfile and there will be many of them.

Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for unifiprotect doing I/O at custom_components/unifiprotect/unifi_protect_server.py, line 109: verify=self._verify_ssl,
Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for unifiprotect doing I/O at custom_components/unifiprotect/unifi_protect_server.py, line 210: verify=self._verify_ssl,

Currently the only thing you can do, is to remove the component from your configuration.yaml or live with the warnings. (The effect on performance is the same as was with 0.108)

I will update this thread, once I have something to test. Sorry for any inconvenience.

6 Likes

Thank you for your time and support you are very appreciated!

1 Like

Thanks for updating, this is the first place I came to check!

The logs pinged my papertrail limits :wink:

1 Like

Thank you.

Thanks! Same issue here :slight_smile:

For the new doorbell, it looks like lastRing is now an attribute in the API. I played around a bit, but have no idea what Iā€™m doing :-X

How would we add one of these sensors to also pull that as an attribute? Or make a new sensorā€¦

Thank you!

EDIT: There also seems to be a ā€œringā€ type in the event history that this parses to get motion events.

V0.2.0 is released which supports HA +0.109

Hi all,
During the weekend Aaron Godfrey, with the help of Juan J. Collas worked hard to convert this integration to Async and fixing the bug that prevented it from working with HA 0.109. And I am happy to announce that it now works. There is a new release available on Github and in HACS. So it is now safe to upgrade your HA instance.

A BIG thank you to both of them for all the hard work. This really shows the power of a community supporting each other.
/B

EDIT: It seems that there are issues on this new release with people who run Unifi Protect on the UDMP - I hope this can be fixed soon.

3 Likes