Custom Component: Unifi Protect

I thought I would try the below in order to see if I could get the Kitchen Camera to display the Kitchen Alex Display when motion is detected. Here is the code:

- id: 'cast_when_motion'
  alias: Unifi Protect - Cast on Motion
  description: ''
  trigger:
  - entity_id: binary_sensor.motion_kitchen
    from: 'on'
    platform: state
    to: 'off'
  condition: []
  action:
  - data:
      entity_id: camera.kitchen
      media_player: media_player.kitchen_display
    service: camera.play_stream
  - delay: 00:01:00
  - entity_id: media_player.kitchen_display
    service: media_player.turn_off

And I seem to get this error:

2021-03-14 11:06:17 WARNING (MainThread) [homeassistant.components.automation.unifi_protect_cast_on_motion] Unifi Protect - Cast on Motion: Already running

Nothing happens on the Alexa screen and no other information in the logs, i am new to this and would appreciate the support :pray:

The warning is because your automation defaults to single mode per Automation modes - Home Assistant

I canā€™t comment on the Alexa side of things because I donā€™t use it.

@anixan, I think you are asking for help in the wrong place. The Unifi component simply creates camera entities that you can stream. As far as HA is concerns itā€™s just another camera. You would probably get MUCH better feedback asking the question in an Alexa related thread (especially one that deals with streaming cameras).

I would help if I could, but like a lot of others in this thread, I do not use Alexa.

@anixan, there is currently no clear way to do what you want. Many of us are looking for the same thing. consider the monoclecam.com skill in alexa. I have been using monocle with voice commands to launch the camera on a show device for a couple of years and it works great. Please remember that there is limited local exposure to the alexa show, so integrating with an alexa skill is your best bet.

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