UniFi Protect Binding (Cloudkey gen2+, Dream Machine Pro, NVR)

I’ve added your manual config to the documentation. Thanks.

1 Like

First of all thank you very much @Seaside!
I was updating my system to Protect (Cloud Key Gen2+) due to EOL of Unifi Video a few days ago. It took me a while to notice that there seems to be no possibility to get the cameras integrated via http binding anymore. I was so happy to see that there is a Unifi Protect binding! :slight_smile:

So, the binding is running, also the bridge is working well in OH3. All linked channels of the bridge are showing the correct information in GUI. But I did not get any of my cameras running… So the Camera-Thing is shown as online, but to be honest the Thing is also online with some random numbers as MAC-address. So this seems to be not a good indicator :smiley:
When linking any channel, it is shown to be NULL unfortunately. Meanwhile I tried several times, several forms of MAC-addresses (XX:XX, xx:xx, XX-XX, xx-xx). I did not get any response…

I was wondering if I did something wrong? Actually, it is just the name of the camera and the MAC to be setup in OH3 - not much options to do sth wrong. Additionally, there is no camera found by auto-discovery which is also a hint for me that there is sth wrongly defined (maybe in the NVR controller)?

Any idea or hint would be appreciated!

Regards,
Sascha

Pleas post your item definition.
The important thing is not the mac address, it is used out of convenience as a unique id. What matters is the IP of the nvr. The binding will query the bridge/nvr for whatever cameras are attached to it, it’s called a boostrap request.

This is an example of one of my items:

String G3BYName “G3BY Name” (G3BY) { channel=“unifiprotect:camera:e7d2e32c:FCECDA8F041B:name” }

Where FCECDA8F041B is the ID based on the macaddress of the camera.
e7d2e32c is the random generated thing id of the bridge nvr.

I agree if the auto discovery is not working, then something is wrong.
So please post screenshots and textual config if you have any.

Next step after this would be to enable debug when doing auto discovery and see what happens as well as viewing the actual boostrap request and what it returns.
But let’s review that config first and we can see what it looks like before looking at debug logging.

Regards, S

added more explanation to the above answer.
@wosch87
What firmware version do you have btw?

Hi!

Firmware of Cloud Key is 2.0.26, Protect version 1.17.2. Both should be most recent ones.

The bridge is configured in OH3 like following:

UID: unifiprotect:nvr:UnifiProtectNVR
label: UniFi Protect NVR
thingTypeUID: unifiprotect:nvr
configuration:
  host: 192.168.2.XX
  refresh: 60
  password: My-Unifi-OS-pwd
  thumbnailWidth: 640
  eventsTimePeriodLength: 30
  username: My-Unifi-OS-user

As an example one of the linked channels is:
unifiprotect:nvr:UnifiProtectNVR:name

I am pretty sure that there is something not working with the connection of the bridge. The linked channels were working until this Morning. I checked now all of them and it seems the connection was lost on 10:14 am - this is shown in LastSeen Item. I also linked a new one just right now (Uptime) an it is shown as NULL.

I checked the event logs, before that time, the Items were updated correctly every minute (e.g. LastSeen, StroageUsed).

Openhab log shows those warnings:
2021-01-23 10:03:58.554 [WARN ] [internal.UniFiProtectNvrThingHandler] - Stopping refresh since nvr is not online

I am confused about the time, since Items were updated since 10:14…

There’s also a warning rouhly at that time:
2021-01-23 10:15:02.931 [INFO ] [otect.internal.model.UniFiProtectNvr] - Initializing the binding, with config: UniFiProtectNvrThingConfig [host=192.168.2.XX, username=XXX, password=XXX, refresh=60, eventsTimePeriodLength=30, thumbnailWidth=640.0, imageFolder=C:\openHAB\userdata\tmp, g4SnapshotWidth=3840, g4SnapshotHeight=2160, defaultSnapshotWidth=1920, defaultSnapshotHeight=1080, g4SnapshotWidthAsString=3840, g4SnapshotHeightAsString=2160, defaultSnapshotWidthAsString=1920, defaultSnapshotHeightAsString=1080]

Regarding debug during autodiscovery: If this is required it would be great if you can give me some hints how to do that. I’ve never done before :smiley:

Edit: Cloud key is online and everything is working fine within Unifi OS.

Regard,
Sascha

I can confirm that it works for firmware 2.0.26 and unifi protect 1.17.2 at least under openhab 3.
What version of openhab are you using?
I would remove the bridge and readd it using GUI (Paper ui for oh2).
You can set debug log level to debug (this will output a lot of info, so a good idea to turn it off when you aren’t debugging).

See information here:

Basic steps:

  1. Connect to karaf console
  2. run log:set DEBUG org.openhab.binding.unifiprotect to turn on
  3. exit

To turn off

  1. Connect to karaf console
  2. run log:set INFO org.openhab.binding.unifiprotect to turn off
  3. exit

Regards, S

After a few trials with removing / deleting / restarting it seems the bridge is now working again. Autodiscovery found all cameras, and I was able to add them as Things. Also the first channels could be linked, but after some of them the camera channels were again shown as NULL…

Just restarting does not help, but I will try again. Hopefully it is not necessary to remove everything again since adding all channels for 5 cameras took a while in OH3…

I will come back to you whether I will get it running or not. Maybe I need the debuging, it seems there is still some kind of error :frowning:

Please find an update from my side:

First of all: I seems to work now :slight_smile:

I guess the main problem was that the mappings for IR and REC were wrongly setup for OH3. I created the map files as done with OH2.5, transformation according to the initial post and set a MAP profile for each channel with e.g. MAP(unifiprotect_ir.map):%s. Actually this was not working at all (e.g. still 0 instead of Auto) and also lead to tons of errors in the log. So no joke: there were 30 errors mentioning wrong MAP transformation logged within less than one second!
I have no idea if this is bullshit from technical point of view, but I am thinking that this billions of errors within a few minutes crashed everything… That’s why a restart works only for short time and then channels were not updated anymore.

For such dummies as I am: the correct way to setup the mapping in OH3 for this case is to got to each Item > add metadata > state description and place the mapping like 0=Never and so on into Options. @Seaside: maybe it makes sense to add this as OH3 specific in the HowTo-post.

I will now setup the rules for the cameras in OH3 based on what I’ve had in OH2.5 already as next step. In a very quick test with a snapshot, this seems to work perfectly!

Once again - many thanks @Seaside for the binding! Great job! :+1:
P.S.: Hopefully there is somebody who will update Unfi binding accordingly based on what you did. I guess the main steps should be the same.

1 Like

@Seaside: I have a lot of following entries in openhab log:
2021-01-26 18:27:23.726 [INFO ] [el.request.UniFiProtectEventsRequest] - Requesting events start seconds: 30000s end seconds: 10000s

Actually, except for a few entries like Garagedoor is now closed there is nothing else but hundreds of those entries, exactly the same like mentioned above.

Do you know why and what does it mean?

Regards,
Sascha

Hi!

I should change that to debug in the next version.
When looking for events (motions), you have to specify the time interval
where to look for events. Basically you look a some time back from now and a end a couple of seconds ahead from now to be sure you get the most recent events.

When starting Openhab (3.0.1), I get following error:

2021-01-26 21:37:29.762 [INFO ] [otect.internal.model.UniFiProtectNvr] - Initializing the binding, with config: UniFiProtectNvrThingConfig [host=192.168.1.1, username=Openhab, password=*************, refresh=60, eventsTimePeriodLength=30, thumbnailWidth=640.0, imageFolder=/openhab/userdata/tmp, g4SnapshotWidth=3840, g4SnapshotHeight=2160, defaultSnapshotWidth=1920, defaultSnapshotHeight=1080, g4SnapshotWidthAsString=3840, g4SnapshotHeightAsString=2160, defaultSnapshotWidthAsString=1920, defaultSnapshotHeightAsString=1080]
2021-01-26 21:37:31.035 [ERROR] [otect.internal.model.UniFiProtectNvr] - Could not find any valid user. Looking for: Openhab
2021-01-26 21:37:31.054 [WARN ] [mmon.WrappedScheduledExecutorService] - Scheduled runnable ended with an exception:
java.lang.NullPointerException: null
at org.openhab.binding.unifiprotect.internal.UniFiProtectNvrThingHandler.refreshChannel(UniFiProtectNvrThingHandler.java:294) ~[?:?]
at org.openhab.binding.unifiprotect.internal.UniFiProtectNvrThingHandler.refreshNvrChannels(UniFiProtectNvrThingHandler.java:214) ~[?:?]
at org.openhab.binding.unifiprotect.internal.UniFiProtectNvrThingHandler.refresh(UniFiProtectNvrThingHandler.java:192) ~[?:?]
at org.openhab.binding.unifiprotect.internal.UniFiProtectNvrThingHandler.run(UniFiProtectNvrThingHandler.java:163) ~[?:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[?:?]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) ~[?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:834) [?:?]

UDM Pro (1.8.5), Protect 1.17.2

Can you log in with user “Openhab” and the supplied password in the protect GUI?
If so do you have the same local user name as first name?

“A quirk is that there is a bug in firmware 2.0.18 which does not display the local user name
when calling the API. Therefor you need to have the same First Name as user name in order for the binding to pick
up the correct user.”

Regards, S

Yes, I can log in with the user in the GUI. After reading about the first name, I changed that. But it still doesn’t work.
It used to work at the first two days. Maybe I just readd the Bridge.

Thanks for the answer!

Edit: I readded the bridge, but the same error appears in the log.
The user is limited Admin and has admin rights for Protect.

Try and restart openhab to be sure.
I succesfully am using Openhab user.
What version of Openhab are you using?
The next step is to enable debug logging see post #50

You should see a line:
“Could not find any valid user. Looking for: Openhab”
“User in response: xyz”
It will also log the json Response from protect:
"Json response: "

Regards, S

@Joeknx did you get it working? The json response will tell if there is a bug or whats going on.

Regards s

Thanks for the question! I readded everything. The Addon, the bridge and the camera. Now it works!
I did not know how to run the Karaf console.

1 Like

Glad to hear. Well if it works no need for debugging right?

Regards S

Thanks for the great work and the support!

1 Like

I have installed the binding on Openhab 3 Snapshot build. I added a few cameras (things) but nothing more. After a few hours openhab slows down and the following errors appear in the log - [ab.core.internal.events.EventHandler] - Dispatching event to subscriber ‘org.openhab.core.internal.items.ItemUpdater@e3070’ takes more than 5000ms.
I have removed the binding and openhab is now operating normally.
Let me know if you need any further info.

Hi!

I’ll investigate. I’m curios if there are any others using this addon for openhab 3 that are experiencing the same problem?
Also there seems to be an issue with openhab 3 running out of memory:

https://community.openhab.org/t/openhab-3-runs-out-of-memory-java-heap-space-errors-cpu-100-after-a-few-hours/

I’ll post back once I have any findings.
What version of Openhab 3 are you using?

Regards, S