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

Yes, no problems with 2.0.0 or 2.0.1 as far as I have seen.

Very cool, thank you.

Built a BETA4 version to prepare for UniFiProtect 2.1.1, as well as fixing a bug that caused
the websocket to close.

1 Like

Currently version 2.1.1 beta3 of UniFi Protect does not work with this binding. It is available in early access. I have a fix for this but it is not yet merged.

A note is to not use the early access releases of UniFi Protect, but to stick to stable releases.

BR S

1 Like

Added a beta5 build

  • Support for UniFi Protect 2.1.1
  • Reworked event api actions
  • Motion detections more robust
  • Ring notification is faster and more robust
  • Removed not needed calls for refreshing Protect
1 Like

that work great thank you !

Can confirm that the latest biding is working on firmware 2.5.8 and UniFi Protect 2.1.1-beta8
Seems to be an intermittent login issue for 2.5.8 so wait with upgrading until I can fix it.

Built an BETA6 release
Fixed login issue for unifiprotect fw 2.5.8
Update to openhab 3.4.x

It would be good if anyone that has not upgraded to fw 2.5.8 could test it and see if it works.
Please let me know if it is not working with previous 1.x.x version.

Hi @Seaside,

I recognized some days ago, that setting the recording mode (Never, always, on motion) from OH is not working anymore. It surely did in the past, but I do not know whether it’s not working anymore for some days or month since I just did not changed the recording mode for a long time.

When changing it in OH I receive a notification (per rule) that item’s state has been changed and after some time (maybe 1min) I will receive again a notification that the recording mode is the original one. Example: set ‘recording mode’ for ‘CamTerrasse’ from ‘on motion’ to ‘never’ in OH ==> notification per rule triggered by item’s state “CamTerrasse … never …” ==> after ~1min: notification per rule triggered by item’s state “CamTerrasse … on motion …”. In the time between those both notifications the recording mode in Unifi App does not change to ‘never’ - it stays ‘on motion’.

When changing the recording mode in Unifi App, the change will be detected by OH (I will get a notification per rule when those items are changing).

I set log level to DEBUG and changed the recording mode for one of the cameras in OH, this is shown in the log:

2022-07-08 11:00:38.778 [INFO ] [del.script.CamTerrasse_RecordingMode] - Cam Terrasse nimmt nicht mehr auf 

[remark: log INFO per rule]

2022-07-08 11:00:38.840 [DEBUG] [otect.internal.model.UniFiProtectNvr] - getCamera cache configMac: XXX
2022-07-08 11:00:38.840 [DEBUG] [otect.internal.model.UniFiProtectNvr] - getCamera CameraInsightCache: UniFiProtectCameraCache [size= 5 macToCamera=]
2022-07-08 11:00:38.840 [DEBUG] [otect.internal.model.UniFiProtectNvr] - getCamera camera: UniFiProtectCamera [name=Terrasse, id=XXX]
2022-07-08 11:00:38.840 [INFO ] [l.thing.UniFiProtectBaseThingHandler] - Setting Recording mode = 0 camera: Terrasse, ip: 192.168.178.31
2022-07-08 11:00:38.903 [DEBUG] [al.model.request.UniFiProtectRequest] - JSONRAW: {"recordingSettings":{"mode":"never"}}
2022-07-08 11:00:38.919 [DEBUG] [al.model.request.UniFiProtectRequest] - Set json RAW: {"recordingSettings":{"mode":"never"}}
2022-07-08 11:00:38.919 [DEBUG] [al.model.request.UniFiProtectRequest] - Key: x-csrf-token, value: XXX
2022-07-08 11:00:38.919 [DEBUG] [al.model.request.UniFiProtectRequest] - Created new request host: 192.168.178.23, scheme: https, path: /proxy/protect/api/cameras/XXX
2022-07-08 11:00:38.919 [DEBUG] [al.model.request.UniFiProtectRequest] - New request: HttpRequest[PATCH /proxy/protect/api/cameras/XXX HTTP/1.1]@XXX
2022-07-08 11:00:38.919 [DEBUG] [al.model.request.UniFiProtectRequest] - >> PATCH https://192.168.178.23/proxy/protect/api/cameras/XXX
2022-07-08 11:00:38.919 [DEBUG] [otect.internal.model.UniFiProtectNvr] - Successfullt sent request
2022-07-08 11:00:38.919 [DEBUG] [otect.internal.model.UniFiProtectNvr] - Set Recording mode on camera Result: {"message":"Invalid CSRF Token"}

remark: I changed any key which could be sensetive information to ‘XXX’
When any of those information is helpfull for you, please let me know whether I should send you the log including those information per PM.

The problem seems to be an invalid CSRF Token - I have no idea what this is or what I need to do to get it back valid?! :smiley:

Thanks for your support!
Regards,
wosch

I’ll test it out. Something could have happened with the new firmware.
What firmware version and unifi protect version are you using? Are you using the latest unifiprotect openhab version as well? It supports 2.5.8 firmware.
If you are using 2.4.10 then unifiprotect-3.x.x-BETA6 might not work and then you should go back to BETA5 or upgrade to 2.5.8.

For me changing recording mode works.
Using UniFi firmware 2.5.9
UniFiProtect version: 2.1.1-beta.8
Openhab UniFiProtect: 3.x.x-beta6

Unifi OS 2.4.8 (Update to 2.4.10 available)
Protect 1.21.6 (Update to 2.0.1 available)
OH 3.3.0.M5 (Update to 3.3 stable or 3.4 snapshot available)
Openhab UnifiProtect 3.x.x-beta5

So I guess I should try to update everything first - I’ve should have try before posting here, sorry! :see_no_evil:

Am I right when staying on beta5 in combination with Unifi stable + OH stable is prefered?

Move to beta6. Something happened between firmware 2.1.x and 2.5.x, authentications is not the same. Previously they provided the csrf token in a regular request, now you first need to be authenticated before you can obtain it, this is implemented in beta6.

Ah, I was talking about beta5 in combination with Unifi OS version 2.4.10 (there is no 2.5.x update shown at my UKCP yet). Then beta5 should be the correct one for me, right?

Try beta6, i Think it will work with 2.4.10 as well.

1 Like

short feedback: beta6 works!
Thanks!

Hello and good day!

Not sure what happened overnight, but I awoke this morning to see thousands of errors in my openhab.log

2022-07-15 07:54:42.929 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:54:44.247 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:54:52.786 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:54:52.979 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:54:54.238 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:55:02.774 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:55:02.833 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:55:02.947 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:55:04.238 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:55:05.933 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:55:05.948 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:55:07.583 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:55:07.594 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:55:07.631 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:55:12.793 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:55:12.939 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:55:14.240 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:55:22.792 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:55:22.942 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:55:24.240 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:55:32.794 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:55:32.940 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json
2022-07-15 07:55:34.241 [ERROR] [websocket.UniFiProtectEventWebSocket] - Failed to parse json

I did an apt update/apt upgrade and saw OpenHAB 3.3 came out so went ahead and upgraded that, also stopped and started the Protect app on my UDM Pro, although the Failed to parse json errors keep flowing in once every few seconds.

I don’t exactly want to change the log level past error, but figured something happened overnight as I otherwise hadn’t done anything. Possible that my UDM Pro had an update to the protect app that changed something maybe? It’s running Protect 2.1.1.

–Edit–

Scrolled up to read UniFi Protect Binding (Cloudkey gen2+, Dream Machine Pro, NVR) - #206 by Seaside

How do I install the beta version of the Binding, and once out of beta, does it automatically update to the release version? I’ve never installed bindings outside of what was available through the Bindings page through OpenHAB.

Hi all, and firstly thanks (especially Seaside) for the time and effort you’ve put into developing and supporting this binding.

I’m hoping for some help though. So far I’ve only managed to get it to work for a short period of time, and it seems to just stop functioning after the first event it sees. Completely removing devices and the binding, and re-installing seems to get it back up and running, but then it just lasts for a single event again, and then is completely non-functional again.

Here’s some output I hope might help. There seems to be some issue with Java, but it’s the recommended version for Openhab I believe, and trying a later version didn’t seem to help (made quite a mess actually).

[openhab.log Note: I’ve de-identified the login credentials]
2022-07-05 10:04:45.773 [INFO ] [otect.internal.model.UniFiProtectNvr] - Initializing the binding, with config: UniFiProtectNvrThingConfig [host=..., username=, password=*******, refresh=60, eventsTimePeriodLength=30, thumbnailWidth=640.0, imageFolder=/var/lib/openhab/tmp, g4SnapshotWidth=3840, g4SnapshotHeight=2160, defaultSnapshotWidth=1920, defaultSnapshotHeight=1080, g4SnapshotWidthAsString=3840, g4SnapshotHeightAsString=2160, defaultSnapshotWidthAsString=1920, defaultSnapshotHeightAsString=1080]
2022-07-05 10:05:46.214 [WARN ] [mmon.WrappedScheduledExecutorService] - Scheduled runnable ended with an exception:
java.lang.NoSuchMethodError: ‘void org.openhab.core.library.types.DecimalType.(java.lang.Number)’
at org.openhab.binding.unifiprotect.internal.thing.UniFiProtectNvrThingHandler.refreshChannel(UniFiProtectNvrThingHandler.java:301) ~[?:?]
at org.openhab.binding.unifiprotect.internal.thing.UniFiProtectNvrThingHandler.refreshNvrChannels(UniFiProtectNvrThingHandler.java:232) ~[?:?]
at org.openhab.binding.unifiprotect.internal.thing.UniFiProtectNvrThingHandler.refresh(UniFiProtectNvrThingHandler.java:210) ~[?:?]
at org.openhab.binding.unifiprotect.internal.thing.UniFiProtectNvrThingHandler.run(UniFiProtectNvrThingHandler.java:172) ~[?:?]
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:829) [?:?]
2022-07-05 10:06:13.009 [INFO ] [g.discovery.internal.PersistentInbox] - Added new thing ‘unifiprotect:g3camera:096b8c1ec5:68D79AE4B6A8’ to inbox.
2022-07-05 10:06:13.009 [INFO ] [g.discovery.internal.PersistentInbox] - Added new thing ‘unifiprotect:g4doorbell:096b8c1ec5:68D79ACF5891’ to inbox.
2022-07-05 10:06:13.010 [INFO ] [g.discovery.internal.PersistentInbox] - Added new thing ‘unifiprotect:g3camera:096b8c1ec5:68D79AE4B21F’ to inbox.
2022-07-05 10:15:02.008 [WARN ] [l.thing.UniFiProtectBaseThingHandler] - Failed to find event fo eventId: 62c40f06026a850387028453 cacheSize: 1
2022-07-05 10:15:02.056 [WARN ] [l.thing.UniFiProtectBaseThingHandler] - Failed to find event fo eventId: 62c40f06026a850387028453 cacheSize: 1

[java --version]
openjdk 11.0.15 2022-04-19 LTS
OpenJDK Runtime Environment Zulu11.56+19-CA (build 11.0.15+10-LTS)
OpenJDK 64-Bit Server VM Zulu11.56+19-CA (build 11.0.15+10-LTS, mixed mode)

[openhab-cli info]
Version: 3.2.0 (Build)

User: openhab (Active Process 183786)
User Groups: openhab tty dialout audio

Directories: Folder Name | Path | User:Group
----------- | ---- | ----------
OPENHAB_HOME | /usr/share/openhab | openhab:openhab
OPENHAB_RUNTIME | /usr/share/openhab/runtime | openhab:openhab
OPENHAB_USERDATA | /var/lib/openhab | openhab:openhab
OPENHAB_CONF | /etc/openhab | openhab:openhab
OPENHAB_LOGDIR | /var/log/openhab | openhab:openhab

[Unifi]

UniFi OS UDM Pro 1.12.22
Protect 2.0.1

Any suggestions much appreciated.

Cheers

Try upgrading both firmware and unifi protect version.
I’m running UCKG2+ firmware 2.5.9 and UniFI protect 2.1.1-beta8.

You can download and install the addon from:

BETA6 - Contains a fix for firmware 2.5.9 and UniFi Protect 2.1.1
BETA5 - Is prior to this.

So in short upgrade UniFi, run BETA6, which should be the one install if you install from marketplace, otherwise you can manually download and install.

If you still have problems you will have to enable debug and provide more logs, make sure you can manually login to protect as well.

Regards, S

Hi!

Sounds like you are out of sync. Upgrade UniFi to latest, and also update OpenHab to 3.3.0 (stable). Otherwise you have to enable debug for the addon and provide me more logs.
Install latest UniFiProtect addon (beta6).

Regards, S