Custom Component: Unifi Protect

I’m new to HA, so sorry in advance but I’m trying to make a notification sent on my phone including a snapshot of the even to my iPhone/AppleWatch (only on “Person” notification and nothing else)

- id: '11111111111111'
  alias: New Automation
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.motion_uvc_g4_pro
    to: person
    attribute: event_object
  condition:
  - condition: time
    after: '21:00'
    before: '10:00'
  action:
  - service: notify.mobile_app_kevins_iphone
    data:
      message: Person detected
      title: Person
  mode: single

This seems to work fine but

  • I’m getting a lot of notifications, for one even / notification with UniFi Protect, I’m getting like 7 notifications, is there a way to limit the notification? perhaps add a 30s delay in between notification?

  • I can’t find a way to add the snapshot to the notification

Thanks All, I really appreciate the support :pray:

Version 0.8.4

Another minor update with a few fixes and a change in the Services UI.

  • FIXED: Issues when activating Services that required an Integer as value, and using a Template to supply that value. Services Schemas have now been converted to use vol.Coerce(int) instead of just int.
  • CHANGED: All Services definitions have now been rewritten to use the new format introduced with the March 2021 Home Assistant release. NOTE: You might need to do a Hard Refresh of your browser to see the new Services UI.
  • FIXED: When using the switches or service to change recording mode for a camera, the recording settings where reset to default values. This is now fixed, so the settings you do in the App are not modfied by activating the Service or Recording mode switches.
1 Like

Hey, Sorry missed your post. Here’s my automation, I think it’s the same thing @kentoe posted, but mine is using the doorbell as a trigger, not motion.

alias: doorbell thumbnail
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.doorbell_doorbell
    from: 'off'
    to: 'on'
condition: []
action:
  - service: notify.staff
    data:
      message: Someone rang the doorbell
      title: Office Doorbell
      data:
        image: /api/camera_proxy/camera.doorbell
        actions:
          - action: URI
            title: View in HA
            uri: lovelace/cameras
          - action: URI
            title: View in Protect
            uri: 'app://com.ubnt.unifi.protect'
mode: parallel
max: 10
1 Like

First of all kudos @briis for making a great custom component. Thank you!

Secondly, have anyone found a solution or a work around to the super annoying delayed live stream? I have a delay of around 20 seconds. As far as I see:

Anyone else have some insight into the issue? Thanks again to @briis and anyone who have any input.

I am running a UNVR with six cameras (g3 pro, flex, micro and g3 dome). I run HA supervised on Ubuntu on an Intel 7700.

This addin has almost no delay and there is an accompanying Lovelace card now. Maybe useful but not ‘integrated’ in UniFi Protect as such.

Thank you for your answer. As far as I understand, RTSP2WebRTC gives you page/view in Home assistant where you may view your streams near real time. This works very well. It does not however provide you with a stream that you may recast real time to a chrome cast. I an at least unable to find any, but please correct me if I am wrong.

I was already am able to view the streams real time using the Frigate component (strongly recommended). I am however, not able to cast them to a chrome cast.

Since I found no other solution, I have set them up in Blue Iris again and cast the mjpg-stream from BI. This works without delay at all. I do still want to find a better solution than that, so all tips are appreciated.

Hi, new to this component as of yesterday… So, is there a way to differentiate between smart detections and actual motion events in Home Assistant? I have some motion zones set up so that my Unifi app doesn’t nag me too much, but if I wanted to have Home Assistant notify me instead, it seems that it would be all motion/detections regardless of the zones I have set up…

Check the attribute ‘event_object’ of the motion binary_sensor for your camera(s)
It shows either the smart detection type - person etc - or ‘None Identified’ for motion events.

e.g. Motion

is_state_attr('binary_sensor.motion_driveway', 'event_object', 'None Identified')

e.g. Smart

not is_state_attr('binary_sensor.motion_driveway', 'event_object', 'None Identified')

Thanks for the tip. I was able to use event_object right in a condition of an automation.

Great it works for you now.
To complement what @TazUk wrote, you can also set the recording_mode so that it only triggers when there is a smart event. Just set the recording_mode to smart (Switch or Service). This requires you to have G4 series cameras.

Has anyone tried this with a cloud key/UDM/DVR on another network over the internet?

So I recently updated some of my automations with this event_score value. But things weren’t working as I’d hoped. Then I realized last night that the event_score, as well as the length of time only fills in AFTER the motion event occurs.

I was hoping to trigger lights with this, but it seems like these attributes may only help for after-the-fact processing?

Would I be incorrect in this thinking?

No. event_score and event_length attributes are populated at the end of the motion event when the binary_sensor returns to ‘off’.

I moved to post-event notifications to take advantage of this additional filtering and the thumbnail generation by Protect (which can take ~5 seconds on my UCK-G2+) because it gives me some enhanced notification filtering required because of the areas covered by several of our cameras. Also this resolves HA’s camera stream latency issues.

I am considering breaking out smart detections from this approach for our G4 bullet though, but it’s not high on my todo list.

Thanks, appreciate the insight.

Was hoping this would resolve immediate false-positives, but like you said it’s definitely more for “post / after” events

my notifications stopped including a thumbnail. Anyone can think of why that would be?

alias: doorbell thumbnail
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.doorbell_doorbell
    from: 'off'
    to: 'on'
condition: []
action:
  - service: notify.staff
    data:
      message: Someone rang the doorbell
      title: Office Doorbell
      data:
        image: /api/camera_proxy/camera.doorbell
        actions:
          - action: URI
            title: View in HA
            uri: lovelace/cameras
          - action: URI
            title: View in Protect
            uri: 'app://com.ubnt.unifi.protect'
mode: parallel
max: 10

Has one got the G4 doorbell working on wall mounted tablet with a display pop-up card when the someone rings the doorbell. How bad is video delay?

I’m not sure about others, but my video delay is significant. I can see upwards of 15-20 second delay.

Is that using the RTSP stream or the built in steam function ?

Because this integration is pulling a proxied feed from the NVR there will be a delay. There is no RSTP available directly from Unifi cameras so the stream is being created from the NVR, however the other elements like doorbell press or motion sensors work great and nearly real time. Personally I leverage the ipad app for protect for cameras more than the integration if I want real time access to a stream. But for general access to cameras this solution has been really solid and consistent.

1 Like