Ubiquiti Unifi Binding Feature Discussion

Yes, I’m running it on my openhab 3.0 system. I can report that the presence part works which is the only part I use.
I will push the code to the repo and then maybe people can improve if it has any fundamental problems or code-breaking rules. Then we might raise a pull request and get the changes approved and included in the official repo. So this is just a POC to make it work and should be improved so the binding still supports the traditional Unifi controller as the Protect, based on config.

1 Like

Great! I will try it and give you a feedback soon. Thanks again!

1 Like

Hi @pagm,

Thank you for taking a stab at this, unfortunately it is still not working on my system…
This is my system: Raspberry Pi 4, OH3.0.1 Release, Unifi controller 6.0.43 on CKG2+.

This is the log I’m seeing:

2021-02-01 18:47:21.946 [DEBUG] [.handler.UniFiControllerThingHandler] - Initializing the UniFi Controller Handler with config = UniFiControllerConfig{host = 192.168.xxx.xxx, port = 8443, username = xxxxxx, password = *****, refresh = 10}
2021-02-01 18:47:22.059 [TRACE] [nal.api.model.UniFiControllerRequest] - >> GET https://192.168.xxx.xxx:8443/api/auth/login
2021-02-01 18:47:22.234 [DEBUG] [nal.api.model.UniFiControllerRequest] - Key: X-CSRF-Token, value:
2021-02-01 18:47:22.322 [TRACE] [nal.api.model.UniFiControllerRequest] - >> POST https://192.168.xxx.xxx:8443/api/auth/login
2021-02-01 18:47:22.355 [DEBUG] [.handler.UniFiControllerThingHandler] - Scheduling refresh job every 10s
2021-02-01 18:47:22.372 [TRACE] [.handler.UniFiControllerThingHandler] - Executing refresh job
2021-02-01 18:47:22.380 [DEBUG] [.handler.UniFiControllerThingHandler] - Refreshing the UniFi Controller unifi:controller:home
2021-02-01 18:47:22.440 [DEBUG] [nal.api.model.UniFiControllerRequest] - Key: X-CSRF-Token, value:
2021-02-01 18:47:22.450 [TRACE] [nal.api.model.UniFiControllerRequest] - >> GET https://192.168.xxx.xxx:8443/proxy/network/api/self/sites

The debug log suggests that the binding is still attempting to connect with port 8443, whereas in @Seaside’s binding the debug log simply says:

2021-02-01 18:57:20.532 [DEBUG] [al.model.request.UniFiProtectRequest] - >> GET https://192.168.xxx.xxx/api/auth/login

I tried both using the mainUI and .things file to create the controller thing but neither made any difference…

On a side note, I noticed my Raspberry Pi was running at 100% for a while after OH reboots… Not sure if it’s this binding or other things causing it but it seems better after I removed it from the addons folder.

I saw I missed mentioning that the port needs to be configured to 443. The default value is 8443 which is the default port when running Unifi Controller standalone.
I have updated the Readme file and here is the example

Bridge unifi:controller:home "UniFi Protect Controller" [ host="...", port=443, username="...", password="...", refresh=60  ] {
  Thing wirelessClient iPhone "My iPhone" [ cid="xx:xx:xx:xx:xx:xx", site="default", considerHome=180 ]

Thank you! I must have overlooked the port number. Are you accessing Unifi with a different port (egress?)?
It’s working for me now, I’ll keep trying different features and let you know if I run into any issues again.

Thank you so much for making the binding work again.

Hey guys!

I’m so sorry I’ve been MIA, I had some major life changes happen over the last 6 months. I got a new job that required me to move which meant I lost access to all my UniFi equipment. Since then, I have not even had the time to get my OH back up and running :frowning:

Hopefully this weekend I’ll finally have some free time to get myself bootstraped. I feel like I’ve abandoned this project (and you guys), and I don’t like that :wink:

Be back soon!


Welcome back!

If there’s anything I can do to help debug the buffer issue I’ll gladly help.

Good to have you back @mgbowman. Hope things continue to settle down for you.

@lolodomo and I were trying to sort out this buffer capacity issue, but we were unclear about how to handle the HttpResponseException.

Thats called a life! :wink:

Nice to have you back with us again anyway. Hopefully things will start settle down for you.

@pagm It took a while to find some time for my feedback.
The setup was easy and everything works without any issue instantly.
Mainly I also use the binding for presence detection, but the other channels are working properly as well. Since you are using presence only, this might be a helpful info for you :slight_smile:

Once again, thanks for working on this binding! :+1:

I added a new config parameter called cloudkey for the Unifi controller thing. The purpose of this is to configure if the binding should be run in original mode or use the new authentication with the API paths for Cloudkey Gen 2. True means Cloudkey Gen 2 mode and false(default value) run as before.

The code is available here that can be used to improve change before we hopefully can get it in the right Openhab code repo.

I also created a new build with the new configuration parameter, the built binding works on Openhab 3 and can be downloaded here

Thanks to Mattew for the Unifi binding and Seaside for the authentication part for CK gen2


Unifi Binding works again on Cloudkey Gen 2. Thanks a lot

Seems like all Unifi Controllers have moved over to the new authentication and API paths, any chance that those of us still using OpenHab 2.x will get an update to this binding?


Hi all.
I am using the Unifi controller in a Docker container on my NAS. Currently on 5.10.23 but looking to upgrade.

Does the version created by @pagm allow me to upgrade to 6.* and still work?

Thanks in advance!

I like this idea! Did someone do something about that?

The API can do it. In php it’s like UniFi-API-client/Client.php at master · Art-of-WiFi/UniFi-API-client · GitHub

Are there some news to this point?

1 Like

Is the Binding which is possible to install with the OH3 UI already compatible with the unifi Cloudkey 2+, or still is needed to install extra?

I am on OH 3.1.0-SNAPSHOT.
With UDM PRO 1.9.0 using a local user (read only rights, to circumvent 2FA) i can connect manually.

Via OH i cannot connect with port 8443 and unifios = true.

Unknown HTTP status code 404 returned by the controller"

Am i missing something or is it currently not possible at all?

Configuration done via UI.

Port should be 443.

Regards s

From all the discussion I am kind of confused. Is this supposed to work now? With the Ubiquiti Cloud Key Gen2+ an newest firmware?

Bridge unifi:controller:home3 "UniFi Controller" [ host="", port=443, cloudkey="true", username="openhab", password="secret", refresh=30 ] {
	Thing wirelessClient danielsiPhone "iPhone1" [ cid="f0xx", site="default", considerHome=180 ]
    Thing wirelessClient MaysiPhone "iPhone2" [ cid="90:axxx", site="default", considerHome=180 ]    

Well because this sadly does not…

2021-03-23 20:10:53.163 [WARN ] [.handler.UniFiControllerThingHandler] - Unhandled exception while refreshing the UniFi Controller unifi:controller:home3 - com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 2 column 12 path $