Custom Component: Unifi Protect

Ah ok, I’ve not used it as I use the UNIFI Protect motion detection sensor to trigger snapshots and plate recognition in HA automation. This keeps one image as the latest and keeps all the others with datestamp

- alias: Drive Camera Vehicle Motion
  max_exceeded: silent
  trigger:
    - platform: state
      entity_id: binary_sensor.motion_drive_camera
      attribute: event_object
      to: 'vehicle'
  action:
    - service: camera.snapshot
      data:
        filename: /config/www/snapshots/drive_camera_latest.png
      target:
        entity_id: camera.drive_camera
    - service: camera.snapshot
      data:
        filename: /media/motion/drive_camera_snapshot_{{ now().strftime("%d%m%Y - %H-%M-%S") }}.png
      target:
        entity_id: camera.drive_camera
    - delay: '00:00:03'
    - service: image_processing.scan
      target:
        entity_id: image_processing.platerecognizer_drive_last_motion
1 Like

Version 0.10.0 Beta 4 released

REMINDER This version is only valid for V1.20.0-beta.2 or higher of UniFi Protect. If you are not on that version, stick with V0.9.1.

Upgrade Instructions

Due to the many changes and entities that have been removed and replaced, we recommend the following process to upgrade from an earlier Beta or from an earlier release:

  • Upgrade the Integration files, either through HACS (Recommended) or by copying the files manually to your custom_components/unifiprotect directory.
  • Restart Home Assistant
  • Remove the UniFi Protect Integration by going to the Integrations page, click the 3 dots in the lower right corner of the UniFi Protect Integration and select Delete
  • While still on this page, click the + ADD INTEGRATION button in the lower right corner, search for UnFi Protect, and start the installation, supplying your credentials.

Changes in this release

This will be the last beta with functional changes, so after this release it will only be bug fixes. The final release will come out when 1.20 of UniFi Protect is officially launched. Everything from Beta 1, 2 and 3 is included here, plus the following:

  • NEW: Device Configuration URL’s are introduced in Home Assistant 2021.11. In this release we add URL Link to allow the user to visit the device for configuration or diagnostics from the Devices page. If you are not on HA 2021.11+ then this will not have any effect on your installation.

  • NEW: BREAKING CHANGE Also as part of Home Assistant 2021.11 a new Entity Category is introduced. This makes it possible to classify an entity as either config or diagnostic. A config entity is used for entities that can change the configuration of a device and a diagnostic entity is used for devices that report status, but does not allow changes. These two entity categories have been applied to selected entities in this Integration. If you are not on HA 2021.11+ then this will not have any effect on your installation.

    We would like to have feedback from people on this choice. Have we categorized too many entities, should we not use this at all. Please come with the feedback.

    Entities which have the entity_category set:

    • Are not included in a service call targetting a whole device or area.
    • Are, by default, not exposed to Google Assistant or Alexa. If entities are already exposed, there will be no change.
    • Are shown on a separate card on the device configuration page.
    • Do not show up on the automatically generated Lovelace Dashboards.
  • NEW: A switch is being created to turn on and off the Privacy Mode for each Camera. This makes it possible to set the Privacy mode for a Camera directly from the UI. This is a supplement to the already existing service unifiprotect.set_privacy_mode

  • NEW: Restarted the work on implementing the UFP Sense device. We don’t have physical access to this device, but @Madbeefer is kindly enough to do all the testing.

    • The following new sensors will be created for each UFP Sense device: Battery %, Ambient Light, Humidity, Temperature and BLE Signal Strength.
    • The following binary sensors will be created for each UFP Sense device: Motion, Open/Close and Battery Low. Note as of this beta, these sensors are not working correctly, this is still work in progress.
1 Like

Is it possible to use TTS with the UniFi Doorbell? Ie that HA can speak via the doorbell instead of just displaying a message?

I’m not sure how many people actually take note of that little screen…

As of right now, no. But it is a planned feature. It will likely come in 0.11 or 0.12 (which 0.12 might be in HA core since we plan to merge into core).

4 Likes

I’m planning on making the move across to Protect v1.20.0 and v0.10.x of the Protect component this weekend.
In the meantime I’ve been reading up on the new LL-HLS option for Stream and wondered whether anyone here has given it a whirl with Protect. Any hints / tips?

We had a bit of discussion about it in the feature request I made right around the same time it was added.

The tldr; is that it works great and decreases the latency from ~15 seconds to ~3, but if you use it, you need to set up a HTTP/2 or HTTP/3 proxy in front of your HA instance (the official nginx add-on works great). If you do not do that, you can only have a max of like ~2-3 cameras streaming at any given time (across all sessions).

Thanks for responding (and so quickly).

I’m running with HA Container in docker on Ubuntu, Nabu Casa for external access and have 4 Unifi cameras.

Based on a quick read of the linked discussion my current setup may not be suitable but I might have a play once I’ve completed the move to the latest Protect and the reworked Integration.

What happens if you have more than 3. I have 6 cameras and all are working fine but I haven’t yet setup my “camera dashboard” with all the cams at once. Curious to know what to expect when I do. I’m using Nabucasa so no reverse proxy.

I do not use Nabu Casa so I do not know if it already provides a HTTP/2 proxy, but I assume it does. So you may already be set. If you also want it for internal as well, that means you will likely need to set up your own Nginx proxy for internal access since you do not have the add-on store. I am sure you can find plenty of guides for how to create Nginx proxies. I know Nginx Proxy Manager is a pretty popular option.

You get a “waiting for Websocket…” message and the browser just hangs until one of the other connections are closed.

3 is an estimate. I do not know what the actual limit is. I have 6 cameras as well too and I was running into the issue. Just remember that it is across all browsers connected to Home Assistant. So if more than one person accessing your HA instance and you both access it at once, it will be doubled (6 connections per user).

1 Like

Thanks for the details. I’m familiar with NPM. I use it for other purposes outside of Home Assistant.

I use the custom frigate-card on the front-end for my Unifi cameras, since upgrading to Protect v1.20.0 and v0.10.x I receive an error when trying to view live video:

Error: Support only RTSP-Stream

I’m wondering if this is being caused by the switch to RTSPS. Is there any way to force RTSP?

From the Protect changelog:

  • Web UI: Generate only RTSPS links for better security. (RTSP streams are still available by removing S from RTSPS and by changing port 7441 to 7447)

Thx @stephack , I can’t see that part in the release notes. Does the document you see tell you where to make that change? :confused:

No. Not in the HA integration. RTSP links were removed from the WebUI in Unifi Protect. That could be an indication it will be removed in a future release. RTSPS works completely with Home Assistant as it uses ffmpeg to stream.

Frigate is also a third party integration and is largely in conflict with UFP for functionality. If you would like RTSPS to work in your Frigate card, I recommend asking the Frigate devs to support cameras with RTSPS.

1 Like

Just in case anyone else runs into the issue with the frigate-card looks like the issue is not with frigate or indeed that card, rather the WebRTC custom component. I’ll open a request there for it to support RTSPS.

This Unifi Protect upgrade from 1.19.x to 1.20 complete messed up all of my camera feeds.

Further more having WebRTC installed messed it up even further. So I had to uninstall it for now.

I’m unable to start the unifi protect integration I get the follow error:

Error setting up entry UDMPRO for unifiprotect
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 304, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/config/custom_components/unifiprotect/__init__.py", line 108, in async_setup_entry
    await _async_get_or_create_nvr_device_in_registry(hass, entry, nvr_info)
  File "/config/custom_components/unifiprotect/__init__.py", line 124, in _async_get_or_create_nvr_device_in_registry
    device_registry.async_get_or_create(
TypeError: async_get_or_create() got an unexpected keyword argument 'configuration_url'

Is anybody having the same issue?

My current work around for this is to use RTSP streams for my cameras.

  1. Copy the RTSPS link from unifi protect. Example: rtsps://192.168.25.1:7441/labcdefgh?enableSrtp

  2. Remove the s in rtsps and change the port from 7441 to 7447

  3. Add to configuration.yaml

 - platform: ffmpeg
    input: rtsp://192.168.25.1:7447/abcdefgh?enableSrtp
    name: Garage

The 0.10 version of the integration requires Protect 1.20+ to use. In turn, 0.10 of the integration also requires Home Assistant 2021.11+ to use. This was unfortunate timing that both HA and Protect introduced non-backwards compatible changes at the same time.

If you cannot upgrade your HA instance to 2021.11, I recommend downgrading your Protect instance back to 1.19 and then using 0.9.1 of the integration.

Also, the WebRTC component will no longer work with the Protect integration as it does use the RTSPS links from Protect now. Protect 1.20 removed the non-secure links from the UI. We suspect that Ubiquiti will remove the non-secure links in a future version so we are using the secure links since they work great in HA. I recommend bugging the author of the WebRTC component to support RTSPS if you would like to keep using it. Otherwise, you can enable LL-HLS on your HA instance (you can see more conversation about LL-HLS right above your post).

If you cannot get the extension author to support RTSPS and you really need WebRTC, I recommend going to go vote for this feature request: WebRTC support for Camera (stream) Components

We pushed out a hotfix for 0.10 just now. We temporarily removed the “High FPS Mode” switch as it was being incorrectly added to cameras that did not support High FPS mode, which could lead the device being bricked. If you are running 0.10.0, please update ASAP. The High FPS mode switch will be added back in a future version once we ensure it does not get added to cameras that do not have the mode.

Apologizes if changelogs in HACS are wrong and not displaying correctly. We had to push it out in a hurry.

1 Like

After discussing it, we decided to add back the RTSP Camera entities. In 0.11, there will be up to 6 camera entities (if RTSP is enabled for all 3 of your camera channels):

  • High (RTSPS)
  • High Insecure (RTSP)
  • Medium (RTSPS)
  • Medium Insecure (RTSP)
  • Low (RTSPS)
  • Low Insecure (RTSP)

Only the high resolution RTSPS camera entity will be enabled by default, but you will be free to enable any of the other 5. If you have RTSP disabled on your High channel and only enabled on your Medium channel, that will be your default enabled one.

EDIT: Discourse does not like me replying to our own integration thread.

Turned my personal notification automations into blueprints and posted them if anyone else is interested or wants to contribute.

Version 0.11.0-beta.1 is released

@AngellusMortis and @bdraco have spend a significant amount of hours in the last weeks to add a whole bunch of new features to this Integration and to prepare it for getting added to Home Assistant Core.

As you can see from below, there are quite a significant number of changes and new features also in this release, so please read these release notes carefully before you upgrade.

Deprecations

0.11 is last major release planned before we merge the unifiprotect integration into core. As a result, a number of features are being removed when we merged into core.

The following services will be removed in the next version:

  • unifiprotect.set_recording_mode – use the select introduced in 0.10 instead
  • unifiprotect.set_ir_mode – use the select entity introduced in 0.10 instead
  • unifiprotect.set_status_light – use the switch entity on the camera device instead
  • unifiprotect.set_hdr_mode – use the switch entity on the camera device instead
  • unifiprotect.set_highfps_video_mode – use the switch entity on the camera device instead
  • unifiprotect.set_doorbell_lcd_message – use the select entity introduced in 0.10 instead
  • unifiprotect.set_mic_volume – use the number entity introduced in 0.10 instead
  • unifiprotect.set_privacy_mode – use the switch entity introduced in 0.10 instead
  • unifiprotect.set_zoom_position – use the number entity introduced in 0.10 instead
  • unifiprotect.set_wdr_value – use the number entity introduced in 0.10 instead
  • unifiprotect.light_settings – use the select entity introduced in 0.10 instead
  • unifiprotect.set_viewport_view – use the select entity introduced in 0.10 instead

The following events will be removed in the next version:

  • unifiprotect_doorbell – use a State Changed event on “Doorbell” binary sensor on the device instead
  • unifiprotect_motion – use a State Changed event on the “Motion” binary sensor on the device instead

The following entities will be removed in the next version:

  • The “Motion Recording” sensor for cameras (in favor of the “Recording Mode” select)
  • The “Light Turn On” sensor for flood lights (in favor of the “Lighting” select)

All of following attributes should be duplicated data that can be gotten from other devices/entities and as such, they will be removed in the next version.

  • device_model will be removed from all entities – provided in the UI as part of the “Device Info”
  • last_tripped_time will be removed from binary sensor entities – use the last_changed value provided by the HA state instead
  • up_since will be removed from camera and light entities – now has its own sensor. The sensor is disabled by default so you will need to enable it if you want to use it.
  • enabled_at will be removed from light entities – now has its own sensor
  • camera_id will be removed from camera entities – no services need the camera ID anymore so it does not need to be exposed as an attribute. You can still get device IDs for testing/debugging from the Configuration URL in the “Device Info” section
  • chime_duration, is_dark, mic_sensitivity, privacy_mode, wdr_value, and zoom_position will be removed from camera entities – all of them have now have their own sensors

Breaking Changes in this release

  • CHANGE: BREAKING CHANGE The internal name of the Privacy Zone controlled by the “Privacy Mode” switch has been changed. Make sure you turn off all of your privacy mode switches before upgrading. If you do not, you will need to manually delete the old Privacy Zone from your UniFi Protect app.

  • CHANGE: BREAKING CHANGE WDR number entity has been removed from Cameras that have HDR. This is inline with changes made to Protect as you can no longer control WDR for cameras with HDR.

  • CHANGE: BREAKING CHANGE the event_length attribute has been removed from the motion and door binary sensors. The value was previously calculated in memory and not reliable between restarts.

  • CHANGE: BREAKING CHANGE the event_object attribute for binary motion sensors has changed the value for no object detected from “None Identified” (string) to “None” (NoneType/null)

  • CHANGE: BREAKING CHANGE The Doorbell Text select entity for Doorbells has been overhauled. The Config Flow option for Doorbell Messages has been removed. You now can use the the unifiprotect.add_doorbell_text and unifiprotect.remove_doorbell_text services to add/remove Doorbell messages. This will persist the messages in UniFi Protect and the choices will now be the same ones that appear in the UniFi Protect iOS/Android app. NOTE: After running one of these services, you must restart Home Assistant for the updated options to appear.

Other Changes in this release

  • CHANGE: Migrates UpvServer to new ProtectApiClient from pyunifiprotect.

    • This should lead to a number of behind-the-scenes reliability improvements.
      • Should fix/close the following issues: #248, #255, #297, #317, #341, and #360 (TODO: Verify)
  • CHANGE: Overhaul Config Flow

    • Adds Reauthentication support
    • Adds “Verify SSL”
    • Updates Setup / Reauth / Options flows to pre-populate forms from existing settings
    • Removes changing username/password as part of the options flow as it is redundant with Reauthentication support
    • Removes Doorbell Text option since it is handled directly by UniFi Protect now
    • Adds new config option to update all metrics (storage stat usage, uptimes, CPU usage, etc.) in realtime. WARNING: Enabling this option will greatly increase your CPU usage. ~2x is what we were seeing in our testing. It is recommended to leave it disabled for now as we do not have a lot of diagnostic sensors using this data yet.
  • CHANGE: The state of the camera entities now reflects on whether the camera is actually recording. If you set your Recording Mode to “Detections”, your camera will switch back and forth between “Idle” and “Recording” based on if the camera is actually recording.

    • Closes #337
  • CHANGE: Configuration URLs for UFP devices will now take you directly to the device in the UFP Web UI.

  • CHANGE: Default names for all entities have been updated from entity_name device_name to device_name entity_name to match how Home Assistant expects them in 2021.11+

  • CHANGE: The Bluetooth strength sensor for the UP Sense is now disabled by default (will not effect anyone that already has the sensor).

  • NEW: Adds all of the possible enabled UFP Camera channels as different camera entities; only the highest resolution secure (RTSPS) one is enabled by default. If you need RTSP camera entities, you can enable one of the given insecure camera entities.

  • NEW: Added the following attributes to Camera entity: width, height, fps, bitrate and channel_id

  • NEW: Added status light switch for Flood Light devices

  • NEW: Added “On Motion - When Dark” option for Flood Light Lighting switch

  • NEW: Added “Auto-Shutoff Timer” number entity for Flood Lights

  • NEW: Added “Motion Sensitivity” number entity for Flood Lights

  • NEW: Added “Chime Duration” number entity for Doorbells

  • NEW: Added “Uptime” sensor entity for all UniFi Protect adoptable devices. This is disabled by default.

  • NEW: Added unifiprotect.set_default_doorbell_text service to allow you to set your default Doorbell message text. NOTE: After running this service, you must restart Home Assistant for the default to be reflected in the options.

  • NEW: Added “SSH Enabled” switch for all adoptable UniFi Protect devices. This switch is disabled by default.

  • NEW: (requires 2021.12+) Added “Reboot Device” button for all adoptable UniFi Protect devices. This button is disabled by default. Use with caution as there is no confirm. “Pressing” it instantly reboots your device.

  • NEW: Added media player entity for cameras with speaker. Speaker will accept any ffmpeg playable audio file URI (URI must be accessible from Home Assistant, not your Camera). TTS works great!

    • TODO: Investigate for final release. This may not work as expected on G4 Doorbells. Not sure yet if it is because of the recent Doorbell issues or because Doorbells are different.
    • Implements #304
6 Likes