Ubiquiti Unifi Binding Feature Discussion

Just for reference, here are my Unifi.things, Unifi.items & Unifi.sitemap contents:

Bridge	unifi:controller:Unifi_HomeR	"Unifi Controller: HomeR" @ "Unifi" [host="172.16.13.100", username="username", password="password", site="default", port=8443, refresh=10]
{
	Thing	client	Angelos_S6	"Angelos_S6" @ "Unifi"	[mac="ec:1f:72:17:XX:XX"]
	Thing	client	Simona_I6	"Simona_I6" @ "Unifi"	[mac="a8:66:7f:e3:XX:XX"]
}
Switch	Angelos_S6_PRES	"Angelos S6 Presence"	<present>	(gUnifi)	{channel="unifi:client:Unifi_HomeR:Angelos_S6:online"}
Number	Angelos_S6_RSSI	"Angelos S6 RSSI [%s]"	<signal>	(gUnifi)	{channel="unifi:client:Unifi_HomeR:Angelos_S6:rssi"}

Switch	Simona_I6_PRES	"Simonas I6 Presence"	<present>	(gUnifi)	{channel="unifi:client:Unifi_HomeR:Simona_I6:online"}
Number	Simona_I6_RSSI	"Simonas I6 RSSI [%s]"	<signal>	(gUnifi)	{channel="unifi:client:Unifi_HomeR:Simona_I6:rssi"}
Frame {
		Group item=gUnifi label="Unifi Clients" icon="network"
	}

I am on OH 2.1 Snapshot Build #896 and all work fine !

Glad to hear everything is working.

Just an FYI, the site configuration parameter on the Bridge item was moved to the Thing item to be more flexible. You can read more about this in the UniFi Binding Readme - Bridge Configuration

1 Like

@mgbowman I just installed the latest OH2 build #904 ( I was on #885).

Running this version of the Unifi binding.

2017-04-30 17:33:48.776 [INFO ] [unifi.handler.UniFiControllerHandler] - UniFi Binding v2.1.0.201704270844

I’m seeing this exception on the port number every refresh interval.

2017-04-30 17:33:49.580 [ERROR] [nding.unifi.internal.UniFiController] - Error trying to authenticate to UniFi Controller
java.net.MalformedURLException: For input string: "8443.0"
	at java.net.URL.<init>(URL.java:627)[:1.8.0_121]
	at java.net.URL.<init>(URL.java:490)[:1.8.0_121]
	at java.net.URL.<init>(URL.java:439)[:1.8.0_121]
	at org.openhab.binding.unifi.internal.UniFiController.openConnection(UniFiController.java:103)[10:org.openhab.binding.unifi:2.1.0.201704270844]
	at org.openhab.binding.unifi.internal.UniFiController.get(UniFiController.java:129)[10:org.openhab.binding.unifi:2.1.0.201704270844]
	at org.openhab.binding.unifi.internal.UniFiController.get(UniFiController.java:155)[10:org.openhab.binding.unifi:2.1.0.201704270844]
	at org.openhab.binding.unifi.internal.UniFiController.login(UniFiController.java:192)[10:org.openhab.binding.unifi:2.1.0.201704270844]
	at org.openhab.binding.unifi.handler.UniFiControllerHandler.refresh(UniFiControllerHandler.java:130)[10:org.openhab.binding.unifi:2.1.0.201704270844]
	at org.openhab.binding.unifi.handler.UniFiControllerHandler.run(UniFiControllerHandler.java:177)[10:org.openhab.binding.unifi:2.1.0.201704270844]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_121]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)[:1.8.0_121]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)[:1.8.0_121]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)[:1.8.0_121]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_121]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_121]
	at java.lang.Thread.run(Thread.java:745)[:1.8.0_121]
Caused by: java.lang.NumberFormatException: For input string: "8443.0"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)[:1.8.0_121]
	at java.lang.Integer.parseInt(Integer.java:580)[:1.8.0_121]
	at java.lang.Integer.parseInt(Integer.java:615)[:1.8.0_121]
	at java.net.URLStreamHandler.parseURL(URLStreamHandler.java:222)[:1.8.0_121]
	at java.net.URL.<init>(URL.java:622)[:1.8.0_121]
	... 15 more

I’m not sure why this started all of a sudden. I don’t recall seeing any PRs dealing with how ESH deals with integer config items. But, obviously something is different with this latest build.

Looking in the Thing json DB, it looks like the config item is being stored with one decimal place (i.e. 8443.0)

org.eclipse.smarthome.core.thing.Thing.json:          "port": 8443.0,

Anybody else on the latest build seeing this?

Nope…
I upgraded yesterday to build #904 and my unifi binding logs are clean.

On the other hand… I use a unifi.thing flat file.
I didn’t add the things via PaperUI discovery, so I don’t have any unifi entries in my jsonDB to properly compare.
I will try this on my test-bed OH2 system and let you know.

Update: Tested the Unifi Binding v2.1.0.201704270844 on 2 snapshots (#889 & #905)

In both cases, the jsonDB is populated correctly with the following entries:

{
  "unifi:controller:1c8ca854": {
    "class": "org.eclipse.smarthome.core.thing.internal.BridgeImpl",
    "value": {
      "label": "UniFi Controller",
      "channels": [],
      "configuration": {
        "properties": {
          "host": "172.16.13.100",
          "refresh": 10,
          "password": "password",
          "port": 8443,
          "username": "username"
        }
      },
      "properties": {},
      "uid": {
        "segments": [
          "unifi",
          "controller",
          "1c8ca854"
        ]
      },
      "thingTypeUID": {
        "segments": [
          "unifi",
          "controller"
        ]
      }
    }
  }
}

So: I can’t reproduce this error :frowning:

@mhilbush I pushed an update that adds an intValue() conversion to the port number. Now if for some odd reason the port gets stored as a string, everything should work fine.


UniFi Binding v2.1.0.201705010628 : org.openhab.binding.unifi-2.1.0-SNAPSHOT.jar

1 Like

Thanks, @mgbowman.

FWIW, I reinstalled the build (#904), as well as deleted and readded the controller and client things, and the problem no longer occurs. No idea why that was occurring, but it’s better now. :+1:

How did I not notice this binding before! Great work @mgbowman All working well on the latest 2.1 snapshot.

Happy to report that I just updated my Unifi Controller from v5.4.14 to v5.4.15 and the Unifi Binding from v2.1.0.201704270844 to v2.1.0.201705010628 and all work fine !

Wanted to report that after a couple weeks of runtime, I’ve not had a single issue with the controller bridge going offline due to a comm issue. And that includes the OH instance that’s on the other end of an IPSEC tunnel from the Unifi controller. That OH instance had been having an issue every few days due to sporadic loss of the tunnel.

Nice work, @mgbowman

Just upgraded the Unifi controller software from 5.4.15 to 5.4.16 and all work fine!
Great binding @mgbowman :thumbsup:

Hello @mgbowman I was wondering wether you were already planning on creating a pull request so we can include the binding in the master in between already in the marketplace

What is your idea about this?

5 Likes

Hi @martinvw

I’ve always planned to get my binding into master but wanted the development / testing to settle down before I created a PR.

My last build was 28 days ago and so far everybody in this thread who helped test has reported everything is in working order. I think it’s stable enough to pull.

However, I’m leaving for vacation and my hands are full these next few days. Once I return, I’ll do a rebase and squash to create a nice clean PR and hopefully get this into the next release.

Cheers!

7 Likes

Great, thanks for the update! And have a nice holiday!

Very nice work with the binding, working fine for me with the latest version of everything (openhab2, binding, unifi).

Have any of you worked out a simple rule to debounce presence detection when certain devices just disconnect from wifi every few minutes due to power saving?

Hi! I just update to version from 1st of May… The mac addresses seems to be case sensitive.

.... (my mobile phone)
2017-06-07 18:47:19.981 [DEBUG] [nding.unifi.internal.UniFiController] -   UniFiClient{mac: '**ec:9b:f3:5e:78:1a**', hostname: 'android-66f7051423a9c68d', wired: false, device: UniFiDevice{mac: '80:2a:a8:83:1a:94', name: 'Dachboden', model: 'U7PG2', site: Site{name: 'mySite', path: 'default'}}}

.... more clients

2017-06-07 18:47:20.024 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Could not find a matching client: mac = 8c:f5:a3:af:4b:80, site = null
2017-06-07 18:47:20.030 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:513ad07b:site
... some other refreshings
2017-06-07 18:47:20.054 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Could not find a matching client: mac = **EC:9B:F3:5E:78:1A**, site = null

Volker

Hi @volkerrichert

This is odd as I do a StringUtils.lowerCase(StringUtils.trim(...)) on both the client config and the json deserialization so the comparison shoud be case-insensitive.

I’ll double check tonight that both of these are actually getting called and report back.

I converted the MACs to lowercase and it’s working now. I can support you by staring a debug session, if you like.

Volker

So it turns out the built-in getConfig().as(...) calls access the fields directly via reflection instead of calling the setters. As a result, the setter in my client config class was never getting called.

I’ve pushed an update to the binding to make use of a tidy() function to clean the config values and hence make MAC address comparisons case-insensitive.

If you don’t mind, please update your binding and try again with your original MAC addresses and report back if this fixed your issue.

Thanks!


UniFi Binding v2.1.0.201706081307 : org.openhab.binding.unifi-2.1.0-SNAPSHOT.jar

3 Likes

@mgbowman One thing I noticed, and this is pretty minor… I had my cable modem disconnected for a few minutes in order to reroute some cables. Noticed these log messages.

Note that this is the configuration where the Unifi Controller is on the other end of an IPSEC tunnel from the openHAB instance.

Wondering why it switched from the WARN to the ERROR level log message. Possibly the connection attempt failed on the WARN, and the DNS lookup failed (UnknownHostException) on the ERROR. Not sure if it was your intention to log a stack trace on this type of problem.

Again, pretty minor in the whole scheme of things.

2017-06-09 07:32:36.879 [WARN ] [unifi.handler.UniFiControllerHandler] - Error refreshing the UniFi Controller unifi:controller:7036b81d - Could not communicate with the UniFi Controller
2017-06-09 07:32:46.867 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:32:56.869 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:33:06.866 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:33:16.865 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:33:26.864 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:33:36.926 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:33:46.865 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:33:56.866 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:34:06.865 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:34:16.869 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:34:26.862 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:34:36.866 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:34:46.865 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:34:56.869 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:35:06.864 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:35:16.865 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:35:26.866 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:35:36.868 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:35:46.865 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:35:56.861 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:36:06.864 [WARN ] [nding.unifi.internal.UniFiController] - Could not connect to the UniFi Controller
2017-06-09 07:36:31.881 [ERROR] [nding.unifi.internal.UniFiController] - Error trying to authenticate to UniFi Controller
java.net.UnknownHostException: unifi
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)[:1.8.0_131]
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)[:1.8.0_131]
	at java.net.Socket.connect(Socket.java:589)[:1.8.0_131]
	at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)[:1.8.0_131]
	at sun.net.NetworkClient.doConnect(NetworkClient.java:175)[:1.8.0_131]
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)[:1.8.0_131]
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)[:1.8.0_131]
	at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)[:1.8.0_131]
	at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)[:1.8.0_131]
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)[:1.8.0_131]
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1138)[:1.8.0_131]
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1032)[:1.8.0_131]
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)[:1.8.0_131]
	at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1316)[:1.8.0_131]
	at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1291)[:1.8.0_131]
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)[:1.8.0_131]
	at org.openhab.binding.unifi.internal.UniFiController.get(UniFiController.java:132)[10:org.openhab.binding.unifi:2.1.0.201705010628]
	at org.openhab.binding.unifi.internal.UniFiController.get(UniFiController.java:155)[10:org.openhab.binding.unifi:2.1.0.201705010628]
	at org.openhab.binding.unifi.internal.UniFiController.login(UniFiController.java:192)[10:org.openhab.binding.unifi:2.1.0.201705010628]
	at org.openhab.binding.unifi.handler.UniFiControllerHandler.refresh(UniFiControllerHandler.java:130)[10:org.openhab.binding.unifi:2.1.0.201705010628]
	at org.openhab.binding.unifi.handler.UniFiControllerHandler.run(UniFiControllerHandler.java:177)[10:org.openhab.binding.unifi:2.1.0.201705010628]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_131]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)[:1.8.0_131]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)[:1.8.0_131]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)[:1.8.0_131]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_131]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_131]
	at java.lang.Thread.run(Thread.java:748)[:1.8.0_131]
2017-06-09 07:36:31.884 [ERROR] [nding.unifi.internal.UniFiController] - Error trying to authenticate to UniFi Controller
java.net.UnknownHostException: unifi
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)[:1.8.0_131]
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)[:1.8.0_131]
	at java.net.Socket.connect(Socket.java:589)[:1.8.0_131]
	at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)[:1.8.0_131]
	at sun.net.NetworkClient.doConnect(NetworkClient.java:175)[:1.8.0_131]
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)[:1.8.0_131]
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)[:1.8.0_131]
	at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)[:1.8.0_131]
	at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)[:1.8.0_131]
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)[:1.8.0_131]
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1138)[:1.8.0_131]
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1032)[:1.8.0_131]
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)[:1.8.0_131]
	at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1316)[:1.8.0_131]
	at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1291)[:1.8.0_131]
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)[:1.8.0_131]
	at org.openhab.binding.unifi.internal.UniFiController.get(UniFiController.java:132)[10:org.openhab.binding.unifi:2.1.0.201705010628]
	at org.openhab.binding.unifi.internal.UniFiController.get(UniFiController.java:155)[10:org.openhab.binding.unifi:2.1.0.201705010628]
	at org.openhab.binding.unifi.internal.UniFiController.login(UniFiController.java:192)[10:org.openhab.binding.unifi:2.1.0.201705010628]
	at org.openhab.binding.unifi.handler.UniFiControllerHandler.refresh(UniFiControllerHandler.java:130)[10:org.openhab.binding.unifi:2.1.0.201705010628]
	at org.openhab.binding.unifi.handler.UniFiControllerHandler.run(UniFiControllerHandler.java:177)[10:org.openhab.binding.unifi:2.1.0.201705010628]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_131]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)[:1.8.0_131]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)[:1.8.0_131]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)[:1.8.0_131]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_131]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_131]
	at java.lang.Thread.run(Thread.java:748)[:1.8.0_131]