Custom Component: Unifi Protect

I have some G3 Flexs (no media_player), G3 Instants,G4 domes and a G4 Doorbell have media _player and work fine

I have G4 Pros and G4 Bullets (all of which have speaker ‘unavailable’) and the G4 Doorbell (which has the Speaker working), so different cameras from your G3 Flexs and G4 Domes - I wonder if that is why.

Just checked again and the G3 Flex have no media_player

Sounds about right to me. Only the doorbell actually has a speaker. For example. My G4 pro has CO and smoke unavailable. This is expected since it doesn’t have those features.

All my G4 Pros have CO/smoke detection:
image

Can i ask if this integration supports the smart sensors yet ?

Protect Sensor

I am thinking about getting these but only if my HA can see them

Can confirm that the protect sensor works with HA

Oh…wow. When was this added?

I think it’s been there a while (a year perhaps), I looked quite some time ago and saw they were supported and hence got one for my front door.

Trying to understand how to pull smart detection thumbnails from media source into notify service. Does anyone have an example of code or just a pointer to where to get event_id in media source?

Is there any hope on the horizon about the delay in video stream when using HomeAssistant dashboards? Over time, my delay grows to be minutes. Completely unworkable. I was previously using Node Red Dashboards, and it’s flawless with the video stream. HA dash is more flexible though.

2 Likes

If you are asking to capture an image from Protect and then send a notification to the HA app on your phone, you need capture the image then send it as an image.
Here is an example I use for when everyone is away. Its simple, but you can get the idea. Its works on Android. Have not tried on iPhone as I do not own one.

alias: Camera Person Backyard 1 (All Away)
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.backyard_1_person_detected
    to: "on"
condition:
  - condition: state
    entity_id: group.track_all_persons
    state: not_home
action:
  - service: camera.snapshot
    data:
      filename: /config/www/snapshots/backyard_camera-1_person.png
    target:
      device_id: 5556471c03cfb4db15xxxxxxxxxxxxxx
  - service: notify.mobile_app_pixel
    data:
      message: Motion - Cam 1
      title: Backyard
      data:
        priority: high
        ttl: 0
        image: /local/snapshots/backyard_camera-1_person.png
mode: single

Does any one know why the snapshots are now taken in low resolution of 480x360 instead of the higher quality as before?

@WedHumpDay
am trying to find where do event_id come from in this part of the component docs? Is there an event that fires on smart_notifiaction?

They are in the trigger data you get when an event is fired - in the to_state (for triggers when detection started) or from_state (for triggers when detection ended). Set up an automation to trigger from those events, walk in front of the camera, and then look at the traces from the automation and the changed variables, you’ll see something like this (in this case trigger.from_state.attributes.event_id):

trigger:
  id: Person
  idx: '0'
  alias: null
  platform: device
  entity_id: binary_sensor.house_front_person_detected
  from_state:
    entity_id: binary_sensor.house_front_person_detected
    state: 'on'
    attributes:
      event_id: 63da750401c10b03870172d7-61364b1601e45f0387000fc6
      event_score: 83
      attribution: Powered by UniFi Protect Server
      icon: mdi:walk
      friendly_name: House-Front Person Detected
    last_changed: '2023-02-01T14:19:48.475959+00:00'
    last_updated: '2023-02-01T14:19:48.475959+00:00'
    context:
      id: 01GR6NJ6BVK1Y9AMAR0M8HKCMF
      parent_id: null
      user_id: null
  to_state:
    entity_id: binary_sensor.house_front_person_detected
    state: 'off'
    attributes:
      attribution: Powered by UniFi Protect Server
      icon: mdi:walk
      friendly_name: House-Front Person Detected
    last_changed: '2023-02-01T14:20:00.352970+00:00'
    last_updated: '2023-02-01T14:20:00.352970+00:00'
    context:
      id: 01GR6NJHZ0CNDGA42R8QQZHQHW
      parent_id: null
      user_id: null

Thanks - exactly what i was looking for. Do you have a code snippet for retrieving an image from protect media source - say to pass to notify service or otherwise

I use this in the automation to grab the relevant variables from the trigger data (in this case from), working (right now) on getting the video start and end dates right for the api call:

variables:
  entity_id: >-
    {{ (device_entities(device_id(trigger.entity_id)) | select('match','camera')
    | list) | last }}
  nvr_id: "{{ config_entry_id(entity_id) }}"
  event_id: "{{ trigger.from_state.attributes.event_id }}"
  friendly_name: "{{ state_attr(entity_id, 'friendly_name') }}"

the video start and end I want to use something like this:

  video_start: "{{ (trigger.from_state.last_changed | string).isoformat() }}"
  video_end: "{{ (trigger.to_state.last_changed | string).isoformat() }}"

but it needs some mangling of types to get it working - on it right now :wink:

No - thats the holy grail :slight_smile: I wish I could :slight_smile:
I cant get the media_source to work - but am playing - I’m trying to get the notifications data in the right place so the video and image clips work on the notify.xxx calls - the last bit of that jigsaw is mangling those video start and end dates - they just dont seem to want to work for me reliably at the moment (types wrong and IoS doesnt seem to want to play nicely) - and its a pain to test - keep having to get up and walk in front of the camera :slight_smile:

I’ll post here an updated variables extraction if I get it working

Do not use snapshots. The thumbnail directly from Protect can be retrieved.

alias: Camera Person Backyard 1 (All Away)
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.backyard_1_person_detected
    to: "on"
condition:
  - condition: state
    entity_id: group.track_all_persons
    state: not_home
action:
  - service: notify.mobile_app_pixel
    data:
      message: Motion - Cam 1
      title: Backyard
      data:
        priority: high
        ttl: 0
        image: "/api/unifiprotect/thumbnail/{{ config_entry_id(trigger.entity_id) }}/{{ state_attr(trigger.entity_id, 'event_id') }}"
mode: single

You can also add the entity for video if you are on iOS.

2 Likes

Yes been digging into those blueprints - very very helpful - struggling with the logic around the video start and end times - in the blueprints you are snapping states[trigger.entity_id].last_changed.isoformat() for the start, and later on the same thing for the end parameter in the video_url - which doesn’t seem to work when I throw it at the IoS device - or am I missing something?