Custom Component: Unifi Protect

I’ll let you know when there is something to test :smile:

1 Like

Ah right. When i choose “Limited Admin” there is a local option. Did not see that. Thanks for the screenshots.

Version 0.3.2

NOTE When upgrading Home Assistant to +0.110 you will receive warnings during startup about deprecated BinaryDevice and SwitchDevice. There has been a change to SwitchEntity and BinaryEntity in HA 0.110. For now this will not be changed, as not everybody is on 0.110 and if changing it, this Component will break for users not on that version as it is not backwards compatible.
It is only warning you get a startup, so just ignore it.

With this release the following items are new or have been fixed:

  • BREAKING Attribute last_motion has been replaced with last_tripped_time and attribute motion_score has been replaced with event_score. So if you use any of these attributes in an automation you will need to change the automation.
  • NEW There is now support for the Unifi Doorbell. If a Doorbell is discovered there will be an extra Binary Sensor created for each Doorbell, so a Doorbell Device will have both a Motion Binary Sensor and a Ring Binary Sensor. The later, turns True if the doorbell is pressed.
    BIG thanks to @thegame3202 for helping me testing this, and even for providing some of the code :+1: The Ubiquiti Doorbel is still not public available, but according to @thegame3202 it is a great product, which I will look forward to aquire

    BREAKING As part of this implementation, it is no longer possible to define which binary sensors to load - all motion and doorbell binary sensors found are loaded. So the monitored_condition parameter is removed from the configuration for binary_sensor and needs to be removed from your configuration.yaml file if present.
  • FIX The Switch Integration was missing a Unique_ID
2 Likes

hello,
I can only find Unifi Ubiquiti in the HACS integration and not unifi protect. I’m using Home Assistant 0.109.6.
Am i missing something?
thanks

You can make a beta release in hacs with a dependency for ha version 0.110.0b0 that’s way only users with viewing betas enabled in hacs can see it they would also need to be on that version of ha for hacs to show it. That way beta testers can have the fix and stable users will be none the wiser.

okk… i just started to us HA few days ago, and don’t realy get what you mean. is there any documentation to follow for the dependency to the 0.110 version? ok i’ve now upgraded by joining the beta. i’m also updrgading the OS. will keep posted
thanks in advance for your help
or how could i "manually"install unifi protect if easier?
thansk

That reply was for Briis, it’s not something you can do…

I don’t think this component is in the hacs store you have to add it manually. I do know Briis has everything well documented on his GitHub repo, go there and follow the steps.

Should be under “integrations” tab. Just search for Unifi, and you should see this:

Unifi Protect Integration for Home Assistant
Control and monitor your Unifi Protect Cameras from Home Assistant

I’m running into this same thing with my Circadian Lighting integration. I was going to try just wrapping the import in a try and basically try SwitchEntity first and if there’s an exception then import SwitchDevice. I don’t normally code in Python and I haven’t had a chance to test this so no idea if it’ll work but it might be a good solution if it does.

Wrapping it a try/except is probably the easiest way to support both versions and avoid having the warning.

try:
    from homeassistant.components.binary_sensor import BinarySensorEntity as BinarySensorDevice
except ImportError:
    # Prior to HA v0.110
    from homeassistant.components.binary_sensor import BinarySensorDevice

Brilliant Aaron, sometimes the world is simple :+1: This will do the trick. Thanks.

NEED TESTERS for next release of Unifi Protect for Home Assistant

Home Assistant is moving away from Custom Components and towards Integrations and has been doing so for a while. The main purpose of that is most likely to ready the whole eco system for V1.0 of Home Assistant. One main goal to be reached for V1.0 is that you should not need to edit Yaml files to get your system up and running.

So to apply to this, I have now converted the unifiprotect Custom Component to an Integration. This means that everything is now setup using a Form from the Integrations page in Home Assistant. And as I don’t want to maintain more complexity than necessary, I have decided to remove the Yaml configuration completely.
I know some people have strong feelings about ‘to Yaml or not to Yaml’ but looking at the number of Configuration Options we need for this Integration, it makes perfectly sense to me, to remove the Yaml option.

Disclaimer Even though the core of the system has not changed from V0.3.3 for this version, and as such should be production ready, I strongly advise that that this test version is installed on a non-critical HA Instance. During the test, basic things may change, and then you will need to de-install and install again, loosing your current setup.

Whats new?

There are not that many new things in here, but the ones that are will make the old setup break.

  • The setup is changed from adding settings to configuration.yaml and other yaml files, to using the Integration Page from the Settings Menu. It should be clear enough what you need to enter, but that is part of the testing.
  • Previously there was a module called unifi_protect_server.py distributed with the Custom Component. This has now been moved to PyPi.org as a separate module called pyunifiprotect. So if anyone wants to change or develop on the core API logic, you need to Fork that module now.
  • It should now be possible to add more than one instance of this Integration to Home Assistant. So if you have more that one UDMP or CloudKey+ you should be able to add them all. I have only one CloudKey+, so I have not been able to test this.
  • Due to the support of more Instances, the naming of the Cameras, Sensors, Binary Sensors and Switches have changed. So if you would install this on an existing system, you would have to change automations etc.

What needs to be tested?

For everyone that wants to try this out, I would like you test one or more of the following:

  • General stability of the system
  • The setup process using the Form - Is it logical, anything you miss to be able to specify?
  • Does it support more than ONE instance? So hopefully, someone with more HW than me, could test this.
  • If anyone wants to translate the form text to something else than English and Danish, you can go to the translation directory and copy the en.json file to your own language code, and submit the file to Github.

Please don’t use the Home Assistant Forum for feedback, but instead use the Issue Page on Github for feedback and bug reporting.

Setup Instructions

I have not made this available in HACS, so it will require a manual installation while testing.

The source of this new version (Called 0.4) can be found here

  1. If you already have an earlier version of unifiprotect installed, you must remove that from your configuration files, delete the files in the custom_components/unifiprotect directory (or deinstall via HACS) and restart HA.
  2. Copy all the files from the directory given about to custom_components/unifiprotect in your Home Assistant installation and restart HA.
  3. Go to Settings and then Integration and search for Unifi Protect
  4. Select the Integration, fill out the form and press Save. Once this is done, you should now have all Entities of Unifi Protect present in Home Assistance.

Have fun.
/B

1 Like

Here is what i see when i type Unif

Ah, that’s not HACS - That’s just the integrations page. Are you running HASS.IO? Or normal HomeAssistant?

Quick edit: unless you’re doing the new fancy version that @briis posted today :wink:

Second edit: Also forgot that it’s “Core HomeAssistant” (What I called “normal”) and “HomeAssistant Operating System” now (Not HASS.IO as I mentioned).

i’m not sure tbh! i used the image for Raspberry Pi 4 Model B 32bit
is this what you call HASS.IO ?
i will give a try to install HACS.
i’ve now removed the previous version of protect, and will (try to) install the 0.4.0 version

Sounds good! Yeah, that looks like “hass.io” (That’s what it used to be called, sorry).

If you need help, I’m happy to help! Should probably private message me though. Let me know!

I deleted my last post because I thought it might’ve been me… But it seems that ADDING the integration works fine. It adds all the entities, names them right, etc. But once you restart HASS, it never comes back up. The first error in my hass.log is this:

2020-05-15 15:06:19 ERROR (MainThread) [custom_components.unifiprotect] Unexpected error fetching unifiprotect data: module 'jwt' has no attribute 'ExpiredSignatureError'
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pyunifiprotect/unifi_protect_server.py", line 130, in is_authenticated
    jwt.decode(
AttributeError: module 'jwt' has no attribute 'decode'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 136, in async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 124, in _async_update_data
    return await self.update_method()
  File "/usr/local/lib/python3.7/site-packages/pyunifiprotect/unifi_protect_server.py", line 73, in update
    await self._get_events(10)
  File "/usr/local/lib/python3.7/site-packages/pyunifiprotect/unifi_protect_server.py", line 283, in _get_events
    await self.ensureAuthenticated()
  File "/usr/local/lib/python3.7/site-packages/pyunifiprotect/unifi_protect_server.py", line 95, in ensureAuthenticated
    if self.is_authenticated() is False:
  File "/usr/local/lib/python3.7/site-packages/pyunifiprotect/unifi_protect_server.py", line 134, in is_authenticated
    except jwt.ExpiredSignatureError:
AttributeError: module 'jwt' has no attribute 'ExpiredSignatureError'
2020-05-15 15:06:23 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/report_state.py", line 48, in async_entity_state_listener
    if entity_data == old_entity.query_serialize():
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/helpers.py", line 474, in query_serialize
    deep_update(attrs, trt.query_attributes())
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/trait.py", line 1300, in query_attributes
    ERR_NOT_SUPPORTED, "Querying state is not supported"
homeassistant.components.google_assistant.error.SmartHomeError: Querying state is not supported
2020-05-15 15:06:26 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.23433590691984] Unexpected error inside websocket API
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/auth/__init__.py", line 458, in async_validate_access_token
    unverif_claims = jwt.decode(token, verify=False)
AttributeError: module 'jwt' has no attribute 'decode'

Any ideas? Thanks!

Hi
Are you by any chance running 0.111? Because I got the same error in that branch. It seems that both jwt and PyJwt are installed as of HA version 0.111 - You need to uninstall both and then install PyJWT - pip3 uninstall jwt and pip3 uninstall pyjwt - and then pip3 install pyjwt. That fixes the problem. I will need to report that in the HA dev branch.

If you run in Docker you need to enter the docker container to do that.
Hope this helps.
/B

Actually no - 109.6

It is in docker though. Not sure I want to go mess around with prerequisites though. Maybe I’ll sit this one out:-) thanks!