Custom Component: Unifi Protect

I have not looked into the Geofence features at all. I have no idea how they work. They definitely require the UniFi Protect app though.

Personally, I just use WiFi for if a person is actually “home” or not and then room level presence detection with a bunch of sensors in the house.

I understand. Maybe after the next big update when you get bored lol.

Has anybody succeeded in making a binary_sensor template for person detection?
My attempt doesn’t seem to be working:

binary_sensor:
  - platform: template
    sensors:
      front_door_person:
        friendly_name: Front Door Person Detected
        device_class: "motion"
        value_template: "{{ is_state_attr('binary_sensor.motion_front_door' ,'event_object' ,'Person') }}"

Homekit’s little picture in picture feature is nice, but I need a binary sensor to feed it.

This is mine:

{{ (is_state('binary_sensor.motion_front_doorbell', 'on') and is_state('sensor.front_doorbell_detected_object', 'person')) }}

1 Like

Thanks, I’ll try it.

You can just use is_state('sensor.front_doorbell_detected_object', 'person')).

By nature of how motion/smart detect events work in UniFi Protect (smart detect is a “sub-event” of motion, they have a reference to each other), Motion will always be true if the detected object is not none.

Also, event_object is deprecated and no longer exists on 0.12 or the HA core version.

1 Like

OK thanks I’ll remove the motion part. I’m on the latest beta, do you mean detected object sensor is deprecated ?

No, the event_object attribute (on the motion sensor) was replaced by the Detected Object sensor.

Ah ok I see thanks

Ok what @Holdestmade did actually work, but I prefer simplicity, so I’ll try your suggestion.
After all of this you’re going to bake a binary sensor into the integration and I’ll… at least have learned something lol.

Edit: Works as well. Thanks to both.

I rma’d my G4 Doorbell and would like to delete the old instance that’s there but I don’t have the option to remove it. I also replaced my UDM Pro with an SE model and would like to delete the old UDMPro device from the integration. Also no option to delete.

Anyone know the correct process to remove stale devices?

Remove the whole integration and re-add it

I was really hoping that wouldn’t be the answer. Thanks for the response.
I’ll wait and see if anyone has a workaround that is less “nuclear” but my gut tells me you’re 100% right. Total remove and re-add or edit the config registries. Neither would be preferred.

I have removed and re-added many times through all the beta testing. Everything comes back as the way it was when you removed it. If your customizing entity names in HA then you’re doing it wrong. Customize the names in protect and through the unifi dashboard. So that way when you re-add it, all of the names for all of your devices get re-added. It’s the complete opposite of nuclear it’s actually a really smooth and easy process…

1 Like

Yeah, I have stopped customizing names in HA for my entities. I prefer to edit them upstream (in this case in Protect). Then I can just freely add/remove the integration whenever without breaking anything.

And yeah, device cleanup is not something we really do. It is annoying that HA does not provide a way to delete orphaned devices like orphaned entities. You can disable them though.

image

2 Likes

Sigh. Thank you both for the responses. I’ve been using this integration since it was first released and unfortunately I have customized all my entity names. I have them in many automations and referenced in many frontend cards. They are also built out in my inlfuxdb and referenced in multiple grafana dashboards. I have done the nuclear option before but I didn’t have many devices at the time, so simply renamed the entities to what they were before … I guess I should bite the bullet now and just edit my automations, frontend cards and grafana dashboards now to use the default names.

This will be a PITA. C’est la vie. Thanks again for confirming.

1 Like

Version 0.12.0


:warning: :warning: WARNING ABOUT Home Assistant v2022.2

The unifiprotect integration will be in Home Assistant core v2022.2. If you are running 0.10.x or older of the HACS integration, do not install v2022.2.x of Home Assistant core.

If you are running 0.11.x or the 0.12.0, you should be safe to delete the HACS version as part of your upgrade. The 0.11.x branch is designed to be compatible with the 0.12.0-beta and the HA core version. The latest version of 0.12.0-beta will be the version of unifiprotect in HA core in v2022.0.

The HACS will be deprecated in favor of the Home Assistant core version after the 2022.0 release. This repo will be archived and removed from HACS after the 2022.4 release of Home Assistant.

Migration to HA Core Version Steps

If you have Smart Sensor devices and you are not running 0.12.0-beta10 or newer, it is recommended you just delete your UniFi Protect integration config and re-add it. If you do not have Smart Sensor devices, you can migrate to the Home Assistant core version by following the steps below:

  1. Upgrade to the 0.12.0 version for the HACS unifiprotect integration and restart Home Assistant.
  2. Remove your HACS unifiprotect integration from HACS (do not remove your unifiprotect config entry). It is safe to ignore the warning about needing to remove your config first.
  3. Do not restart HA yet.
  4. Upgrade to Home Assistant 2022.2.x

You must remove the HACS integration efore upgrading to 2022.2.0 first to prevent a conflicting version of pyunifiprotect from being installed.


0.12.0 was originally planned as a beta only release, but after giving it more thought, I figured it would be be great to mark it as stable for the folks that cannot upgrade to the HA core version in 2022.2.

This release is primarily fixes from the HA core process. There is also full support added for the G4 Doorbell Pro, the UP Sense.

This will be the last HACS release. After this point, the HACS repo is considered deprecated. We will still take issues in the repo as if people prefer to make them here instead of the HA core repo. But after a month or 2 we plan to archive the repo and have the integration removed from HACS.

Differences between HACS version 0.12.0 and HA 2022.2.0b1 version:

HACS Only

  • Migration code for updating from 0.10.x or older still exists; this code has been removed in the HA core version

HA Core Only

  • Full language support. All of the languages HA core supports via Lokalise has been added to the ingration.

  • Auto-discovery. If you have a Dream machine or a Cloud Key/UNVR on the same VLAN, the UniFi Protect integration will automatically be discovered and prompted for setup.

  • UP Doorlock support. The HA core version has full support for the newly release EA UP Doorlock.

Changes

  • CHANGE: BREAKING CHANGE Removes all deprecations outlined in the 0.11.x release.

  • CHANGE: BREAKING CHANGE The “Chime Duration” number entity has been replaced with a “Chime Type” select entity. This makes Home Assistant work the same way as UniFi Protect. (https://github.com/briis/unifiprotect/issues/451)

  • CHANGE: BREAKING CHANGE Smart Sensor support has been overhauled and improved. If you have Smart Sensors, it is highly recommended to delete your UniFi Protect integration config and re-add it. Some of the categories for the sensors have changed and it is not easy to change those without re-adding the integration. The sensors for the Smart Sensor are may also appear unavaiable if that sensor is not configured to be abled. For example, if your have motion disabled on your Sensor in UniFi Protect, the motion sensor will be unavaiable in Home Assistnat. Full list of new Smart Sensor entites:

    • Alarm Sound and Tampering binary sensors
    • Motion Sensitivity number
    • Mount Type and Paired Camera selects
    • Status Light switch
    • Configuration switches for various sensors:
      • Motion Detection switch
      • Temperature Sensor switch
      • Humidity Sensor switch
      • Light Sensor switch
      • Alarm Sound Detection switch
  • CHANGE: BREAKING CHANGE Removes profile_ws debug service. Core plans to add a more centralized way of getting debug information from an integration. This will be back in some form after that feature is added (estimate: 1-2 major core releases).

  • CHANGE: BREAKING CHANGE Removes event_thumbnail attribute and associated ThumbnailProxyView. After a lot of discussion, core does not want to add more attributes with access tokens inside of attributes. We plan to add back event thumbnails in some form again. If you would like to follow along with the dicussion, checkout the architecure dicussion for it.

  • CHANGE: Switches Doorbell binary_sensor to use is_ringing attr, should great improve relaiability of the sensor

  • CHANGE: Dynamic select options for Doorbell Text

  • CHANGE: Improves names for a number of entities

  • CHANGE: Adds a bunch of extra debug logging for entity updates

  • NEW: Adds full support for the package camera for the G4 Doorbell Pro. It should now always be enabled by default (if you are upgrading from an older version, it will still be disabled). The snapshot for the Package Camera has also been fixed. Since the camera if only 2 FPS, streaming is disabled to prevent buffering.

  • FIX: Overhaul of the Websocket code. Websocket reconnects should be drastically improved. Hopefully all reconnnect issues should be gone now.

  • FIX: Fixes NVR memory sensor if no data is reported

  • FIX: Fixes spelling typo with Recording Capacity sensor (https://github.com/briis/unifiprotect/issues/440)

  • FIX: Fixes is_connected check for cameras

  • FIX: Adds back last_trip_time attribute to camera motion entity

  • FIX: Fixes NVR memory sensor if no data is reported

  • FIX: Fixes spelling typo with Recording Capacity sensor (https://github.com/briis/unifiprotect/issues/440)

  • FIX: Further improves relibility of Doorbell binary_sensor

  • FIX: Fixes voltage unit for doorbell voltage sensor

  • FIX: Fixes connection_host for Cameras so it can have DNS hosts in addition to IPs.

  • FIX: Improves relibility of entities when UniFi Protect goes offline and/or a device goes offline. Everything recovery seemlessly when UniFi Protect upgrades or firmware updates are applied (fixes https://github.com/briis/unifiprotect/issues/432).

  • FIX: Improves relibility of media_player entities so they should report state better and be able to play longer audio clips.

  • FIX: Fixes stopping in progress audio for media_player entities.

  • FIX: Allows DNS hosts in addition to IP addresses (fixes https://github.com/briis/unifiprotect/issues/431).

  • FIX: Fixes selection of default camera entity for when it is not the High Quality channel.

  • FIX: Fixes https://github.com/briis/unifiprotect/issues/428. All string enums are now case insensitive.

  • FIX: Fixes https://github.com/briis/unifiprotect/issues/427, affected cameras will automatically be converted to Detections recording mode.

1 Like

## About Migating to the HA Core version

Unfortunately, the HA core team has decided that we need to change the domain of the integration from unifiprotect to unifi_protect to match the most up to date standards for HA. This means upgrading to the HA core version is is a major breaking change and we are deeply sorry about this. We made our best effort to avoid this.

Steps to migrate (will remove all of your existing UniFi Protect entities):

1. Remove the HACS version of UniFi Protect including your config entry for the integration.
2. Upgrade to Home Assistant 2022.2.x
3. Set back up the UniFi Protect integration.
4. Fix all of your entity name references and replace any usage of unifiprotect with unifi_protect (for service calls and the like).

EDIT: You may be able to migrate using the following below instructions without losing your entities. Very much “use at your own risk”. If it works, you can just delete the HACS integration after updating. If you can just delete the config entry and we add it, we really recommend doing that.

> Not recommended but this is how I migrated my setup.
>
> 1. Made a backup
> 2. Stop Home Assistant if possible (I didn’t)
> 3. docker exec -it homeassistant /bin/bash -c 'sed -i 's/"unifiprotect"/"unifi_protect"/g' .storage/core.entity_registry .storage/core.device_registry .storage/core.config_entries'
> 4. Restart Home Assistant

(from: Change unifiprotect domain to confirm to standards by bdraco · Pull Request #64978 · home-assistant/core · GitHub)

1 Like

That is unfortunate, but then again, without your work nothing of this would be possible. So small ‘price’ to pay for people using this. Thanks for all the documentation regarding upgrading/migrating.

It actually might not be final yet. Apparently, there is a lot of discussion going on about it.