Ubiquiti Unifi Binding throws exception

Hi,

@mgbowman

after an upgrade to OH 2.5 (M5) (with a few intermediate steps in which I did not check on the bindings working) I run into an error with the Ubiquity Unifi binding.
I ran a 5.7.X version of the unifi network controller until earlier today, ran into the below observed problem and upgraded to 5.12.35 (current version).

Item and thing configuration used to work under OH 2.2 with a version of the binding org.openhab.binding.unifi-2.2.0-SNAPSHOT.jar and the 5.7 version of the controller. With the new version of OH the old binding loads, does not throw an error but stays in PaperUI in an “initializing” state.

The 2.5.M5 binding loaded through PaperUI shows a state of “offline - configuration error”, the things config shows in PaperUI, and openhab.log shows the attached stack trace.

The unifi.things config:

Bridge unifi:controller:home "UniFi" [ host="192.168.1.56", port=8443, username="XXXX", password="YYYYYYYYYYYY", refresh=10, considerHome=180 ] {
        Thing client clemensPhone "Clemenss iPhone" [ mac="AB:CD:EF:01:02:03", contactType="NO" ]
        .... 
        .....
}

(MAC / USER / PASSWD) changed. User PW combo works to log into the Unifi admin interface.

Here is the stack trace.

org.openhab.binding.unifi.internal.api.UniFiException: Unknown HTTP status code 404 returned by the controller
        at org.openhab.binding.unifi.internal.api.model.UniFiControllerRequest.getContent(UniFiControllerRequest.java:147) ~[bundleFile:?]
        at org.openhab.binding.unifi.internal.api.model.UniFiControllerRequest.execute(UniFiControllerRequest.java:116) ~[bundleFile:?]
        at org.openhab.binding.unifi.internal.api.model.UniFiController.executeRequest(UniFiController.java:198) ~[bundleFile:?]
        at org.openhab.binding.unifi.internal.api.model.UniFiController.login(UniFiController.java:106) ~[bundleFile:?]
        at org.openhab.binding.unifi.internal.api.model.UniFiController.start(UniFiController.java:91) ~[bundleFile:?]
        at org.openhab.binding.unifi.internal.handler.UniFiControllerThingHandler.initialize(UniFiControllerThingHandler.java:92) [bundleFile:?]
        at sun.reflect.GeneratedMethodAccessor74.invoke(Unknown Source) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_40]
        at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_40]
        at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:152) [bundleFile:?]
        at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_40]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_40]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_40]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_40]

I also see a few unusual lines in the “server.log” of the ubiquiti controller:

[2019-12-01T21:34:55,871] <launcher-ui> INFO  launcher - UniFi Controller (5.12.35) started.
[2019-12-01T22:20:55,496] <webapi-10> WARN  sanitize - Invalid key exists in Setting payload, key=analytics_disapproved_for
[2019-12-01T22:20:55,497] <webapi-10> WARN  sanitize - Invalid key exists in Setting payload, key=storeEnabled
[2019-12-01T22:20:55,497] <webapi-10> WARN  sanitize - Invalid key exists in Setting payload, key=storeAdminsEnabled

Any ideas or suggestions how to fix this?

Thanx
Clemens

2.5M6 came out today
Try udpadting and report in this thread:

1 Like

Check your controller settings - status code 404 means it couldn’t find the API at 192.168.1.56:8443

You also need to change the above Thing definition to this:

Thing wirelessClient clemensPhone "Clemenss iPhone" [ cid="AB:CD:EF:01:02:03" ]

We now wirelessClient instead of client, cid (client identifier) instead of mac and the use of contactType has been deprecated.

Let me know if you can’t manage to get it working.

Matthew

Edit: Forgot the change from client to wirelessClient

@mgbowman thanks for the quick reply:

I got a bit further:
I had the UI port for Unifi changed to 8043 to avoid conflict with an OH component but did not correct that in the config file. My bad. (suggestion: This could be a common error for people running OH and the unifi controller on the same box, you could point to this conflict in the install docs and have the error message refer to that).

I also updated the syntax of the things config file, thanks for pointing out the changes.

I also updated to M6, in order to avoid any bugs fixed in the meantime.

No exceptions in the openhab.log any more.

So far so good.

Now communication with the controller works, but my phone(s) are still not detected:
I switched on debugging and find the following in openhab.log

2019-12-02 09:39:03.711 [DEBUG] [.handler.UniFiControllerThingHandler] - Refreshing the UniFi Controller unifi:controller:home
2019-12-02 09:39:03.713 [DEBUG] [i.internal.api.model.UniFiController] - Found 2 UniFi Site(s):
 - UniFiSite{name: 'default', desc: 'Default'}
 - UniFiSite{name: '8s5cv7t4', desc: 'myName'}
2019-12-02 09:39:03.724 [DEBUG] [i.internal.api.model.UniFiController] - Found 4 UniFi Device(s):
 - UniFiDevice{mac: 'xxxxxxxxx', name: 'Ubiquiti_myName_OG', model: 'U7PG2', site: UniFiSite{name: '8s5cv7t4', desc: 'myName'}}
 - UniFiDevice{mac: 'xxxxxxxxi', name: 'Ubiquiti_myName_GG', model: 'U7PG2', site: UniFiSite{name: '8s5cv7t4', desc: 'myName'}}
 - UniFiDevice{mac: 'xx:xx:xx:xx:xx:xa', name: 'Ubiquiti_myName_EG', model: 'U7HD', site: UniFiSite{name: '8s5cv7t4', desc: 'myName'}}
 - UniFiDevice{mac: 'xxxxxxxxxv', name: 'Ubiquiti_myName_DG', model: 'U7PG2', site: UniFiSite{name: '8s5cv7t4', desc: 'myName'}}
2019-12-02 09:39:03.726 [DEBUG] [i.internal.api.model.UniFiController] - Found 0 UniFi Device(s):
2019-12-02 09:39:03.730 [DEBUG] [i.internal.api.model.UniFiController] - Found 25 UniFi Client(s):
.....[devices deleted]
 - UniFiClient{mac: '12:34:56:aa:bb:cc', ip: '192.168.1.141', hostname: 'clemensiphonexi', alias: 'null', wired: false, blocked: false, device: UniFiDevice{mac: 'xx:xx:xx:xx:xx:xa', name: 'Ubiquiti_myName_EG', model: 'U7HD', site: UniFiSite{name: '8s5cv7t4', desc: 'myName'}}}
..... [other devices deleted]
2019-12-02 09:39:03.726 [DEBUG] [i.internal.api.model.UniFiController] - Found 0 UniFi Device(s):
2019-12-02 09:39:03.730 [DEBUG] [i.internal.api.model.UniFiController] - Found 25 UniFi Client(s):
...... [bunch of devices deleted]
 - UniFiClient{mac: '12:34:56:aa:bb:cc', ip: 'null', hostname: 'clemensiphonexi', alias: 'null', wired: false, blocked: false, device: null}
...... [more  devices deleted]

2019-12-02 09:39:03.737 [DEBUG] [i.internal.api.model.UniFiController] - Found 0 UniFi Insights(s):
2019-12-02 09:39:03.737 [DEBUG] [i.internal.api.model.UniFiController] - Could not find a matching client for id = 12:34:56:AA:BB:CC

I hope, I haven’t left out anything relevant. I have four access points, they seem to be detected, also a whole bunch of devices attached to some of them (amongst them my phone, that I left in the logs).
Note that my phone’s MAC shows up in “couldn’t find a matching client id”. I assume that is the address picked from the cid in the things config file.
The same MAC appears a couple of times, in the log excerpt it looks like being associated with a device (i.e. AP?), in the same log (looping over a second AP maybe) without the device association.

I don´t see any events in the event.log thus none of the items attached to the thing channels get changed.

Again: Further help appreciated.

Clemens

What version of the binding are you running?

I believe it got updated automatically with my update to M6
from Karaf console list

234 │ Active │  80 │ 2.5.0.M6                │ openHAB Add-ons :: Bundles :: UniFi Binding

I think the version in master is “case sensitive” to the clients id (this have been fixed in the latest development version).

In your wirelessClient config, make sure the cid="aa:bb:cc:11:22:33" is all lower case and see if that fixes it!

Matthew

I suspected as much earlier and had tried that already.

All my MACS in the .things file are lowercase, but they are reported in the logs as uppercase.
Here are the definitions:

.things:

Bridge unifi:controller:home "UniFi" [ host="192.168.1.56", port=8043, username="byname", password="XXXXXX", refresh=10, considerHome=180 ] {
        Thing wirelessClient clemensPhone "Clemenss iPhone XI" [ cid="74:42:8b:dc:58:8b" ]

oh.log:

...
 - UniFiClient{mac: '74:42:8b:dc:58:8b', ip: 'null', hostname: 'clemensiphonexi', alias: 'null', wired: false, blocked: false, device: null}
.....
2019-12-02 10:52:19.481 [DEBUG] [i.internal.api.model.UniFiController] - Could not find a matching client for id = 74:42:8B:DC:58:8B

I am afraid that´s not it (or it is converted to UC by the binding but shouldn’t because the controller returns LC).
Name of thing and hostname of client don’t have to match, do they?

C.

One more thing: I reported a two crashes of M6 earlier today and removed the binding upon a suggestion of a board member. A closer look into openhab.log show 76000 lines of debug information - most of them from the unifi binding repeating the detection cycle I reported earlier over and over again in 10 sec intervals.

Clemens

Naturally this only happens if you have DEBUG enabled for the UniFi binding - otherwise these log messages would not show.

So looking over you log messages again, I think I see the problem…

- UniFiClient{mac: '74:42:8b:dc:58:8b', ..., device: null}

The device should not be null. Did you copy this log message from the binding’s “Clients” output or the “Insights” outputs? Could you maybe run it again and send me a PM with all the UniFi output from when it refreshes the controller?

Matthew