Custom Component: Unifi Protect

I’ve had this integration running great for about a year now, but lost a connection today and can’t seem to get it back. I’ve since tried reinstalling the integration and rebooting my Unifi hardware, but no luck.

I can still access my Unifi Protect services locally, but the integration doesn’t seem to like that IP. I keep getting “Error retrieving data from Unifi Protect.”

Any thoughts?

Check that the local user you have setup for accessing UniFi Protect is still active, and has admin rights. It need to look like the picture below. I have experienced cases where the local users somehow got disabled after a Protect upgrade.

You could also try to enable debug for the Integration and maybe also update to the latest Beta version 09.1-beta1, which improves error logging.

Yeah, verified my local user is setup correctly. I also tried to disable 2FA from my Unifi account, but no luck on that either. How do I get the beta version? I don’t see any beta releases in the HACS control panel.

@briis Thanks for your outstanding work !
Due to stream delay (aprox 18sec) i would like to use the camera snapshot to send a snapshot to my google home devices. Can someone help me out with this ? Kind of a beginner with these automations. I managed it to work with my mobile.

Thanks in advance

There is no stream delay from Unifi Protect. Any snapshots would be taken in real time.

The stream delay comes from Lovelace and how streaming is implemented on the frontend of Home Assistant. HA uses HLS which creates “keyframes” of fixed length. The default preloaded stream loads about 3 keyframes before it starts streaming (~15-20 seconds). If you load the feed and jump ahead, you can get up to 1 keyframe behind (~5 seconds).

There is no really way to fix this unless HA itself adds a different method of streaming for Camera feeds. Either LHLS, WebRTC, etc.

If your Google Home Devices can pull the raw RTSP feed (you have to go into Unifi Protect to get that), that will be without a delay. Or you can also use the WebRTC custom component to make WebRTC cards. It is not implement nearly as well as the out of the box HLS streaming, but it does work for real time.

1 Like

@briis I want to thank you greatly for making this. This is a huge help to fully integrate the Unifi system and truly helps the community. I’m loving the controls that are available

Tack så mycket!

1 Like

Thank you so much for this addon it works great but trying to understand one thing and maybe this is a simple easy question someone can answer or maybe not, sorry still kind of new to all this, when I click enable RTSP it seems to just implement it on my cameras threw home assistant that I enable, does anybody know if it is using the secure RTSPS or is it just pulling from the RTSP link? I didn’t specify so trying to understand this or maybe I missed something :frowning:

It always pulls from the rtsp link, just not the secure one (https://github.com/briis/pyunifiprotect/blob/43e6d86f4033096fef1885be43e5c766309df9c7/pyunifiprotect/unifi_data.py#L388).

@briis, I just set up one of my cameras manually using the rtsps and it does appear to work. Maybe we should use the secure one at some point in the future.

(config I used if interested):

camera:
  - platform: generic
    still_image_url: https://<ip>/snap.jpeg
    # this is also the rtsps URL that Protect shows in the UI
    stream_source: rtsps://<connection_ip>:7441/<rtsp_alias>?enableSrtp
    name: Test
    verify_ssl: false

yep! I was on that boat ready to sail out on using the secure then I jumped over to this addon maybe ill jump back over, for now, I would much prefer the secure link it does indeed work! unless I am missing something…

@briis, it actually looks like they may be deprecating rtsp in the future (in favor of rtsps).

  • 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.

https://community.ui.com/releases/UniFi-Protect-Application-1-20-0-beta-2/63d9c588-c169-45f2-9c08-b74648ae43cd

Looks interesting, and the more secure we can make this the better. Let us do some testing on this, and se if it works.
Could one of you create an issue on Github, to make sure this is added to the list of things to do?

1 Like

Created: https://github.com/briis/unifiprotect/issues/307

1 Like

Is there a way to use my G3 flex camera as a light sensor?
If I for example got the live lux value for each camera that could controll when the lights should turn on in node red.

The Unifi Cameras do not expose the raw Lux value. There is simply a is_dark boolean. I do not have a G3 Flex to test with, but that attribute gets exposed on the G4 as a state attribute of the entity.

Thank you for the respons! The “is_dark” status is is not useful since I wan´t to turn on the light quite long before the nightvison on the camera is activated.

You should be able to use the Sun entity for that. Sun - Home Assistant

I use Node Red + the within-time node (from https://github.com/rdmtc/node-red-contrib-sun-position) for the lights I want to turn on based on the position of the sun (how light it is outside).

I use to try to use Lux sensors, but those are never realtime enough to work “as expected”. Using the sun position is the most “accurate” solution I have found.

UniFi Protect V1.20.0 Beta breaks this Integration

There are some underlying changes in the UniFi Protect API introduced with V1.20.0 Beta, which means that this integration will stop working in some essential areas like changing recording mode etc.

So until there is a release out, that supports these changes I recommend that you do not update to the beta version of 1.20.0. I will post here when this version is supported.

UPDATE:
There is now a Beta 1 of V0.10.0 out, that does support 1.20.0 of UniFi Protect. Please read the CHANGELOG very carefully before upgrading as there are a few Breaking Changes. This release is only for people running UniFi Protect V1.20.0 or later. Do not try to upgrade if you are not on that release or the Integration will not function correctly.
If you have Beta releases enabled in HACS, it should show up there. If beta releases are not enabled, just click Reinstall from the three dots in the lower right corner and then you can enable it. (This is on the UniFi Protect Integration in HACS)

UPDATE 2
Beta 3 has just been released with a lot of changes and new stuff. Please note, quite a few of these changes are Breaking Changes, so make sure to read the release notes before you upgrade. With the introduction of the new Select and Number entities, we can now move f.ex. 3 switches in to 1 Select entity, and we can make a UI Entity where we previously could only use a Service. Making that transition is the biggest reason for the many breaking changes.

5 Likes

Hey folks,
I currently use frigate, but, seeing as there are snapshots of person and car detection for the cameras and a produced recording/snapshot is it possible to pull them in to HA.

I’m guessing there would be a couple of ways to do it?

  1. Create a camera for snapshot, and a camera for recording (camera.name_recording_latest)
  2. Somehow leverage the media browser in HA to pull in all the snapshots/recordings - however this wouldn’t allow there to always be a latest.

I checked the docs, but couldn’t see anything, but would be cool to cast/PiP someone at the doorbell or if a car pulls up after 10PM or if you’re alarm is armed away and a person is detected send snapshot to cell phone.

  1. Create a camera for snapshot, and a camera for recording (camera.name_recording_latest)

You can either use attribute.entity_picture on the camera itself to pull the current view of the camera, or use the camera.snapshot service.

1 Like

Can you use the unifiprotect.save_thumbnail_image service ?
That wouldn’t pull the video though