Ubiquiti Unifi Binding Feature Discussion

Hm pretty sure I did that. I did restart openhab to enable Karaf ssh access and now it’s working.

Maybe it was my fault, maybe there was something stuck. But hey its running thanks! :slight_smile:

Latest binding seems to be working fine for me. My controller seems to keep updating the last seen value for some time, however. I think someone else mentioned theirs behaving similar at some point. The result being that it is no quicker or more consistent than using the online channel.

After first updating the binding I did a test by turning of wifi on my phone. That worked as expected. Shortly after my configured time out it reported offline. In normal use (just leaving the house) that doesn’t seem to be the case though. I’m not sure if the AP and phone are trying to maintain the connection. Maybe the AP sees that the connection slowly faded so it keeps the device “active” in expectation that the device will come back in range. Who knows.

@mgbowman,

any plans to make the status of wired equipment available as well through this binding? Would love to able to trace status of remote servers :yum: without having to go through VPN and such.

kind regards

Han

@mgbowman, pretty infrequently (ones per day or rarely) I got following error:

2017-10-30 11:49:55.365 [WARN ] [nding.unifi.internal.UniFiController] - Empty GET response from URL: https://192.168.1.5:8443/api/s/default/stat/device
2017-10-30 11:49:55.372 [ERROR] [nding.unifi.internal.UniFiController] - Error GET’ing URL: https://192.168.1.5:8443/api/s/default/stat/device
org.openhab.binding.unifi.internal.UniFiException: Could not communicate with the UniFi Controller
at org.openhab.binding.unifi.internal.UniFiController.get(UniFiController.java:174) [21:org.openhab.binding.unifi:2.2.0.201709220819]
at org.openhab.binding.unifi.internal.UniFiController.get(UniFiController.java:192) [21:org.openhab.binding.unifi:2.2.0.201709220819]
at org.openhab.binding.unifi.internal.UniFiController.getDevices(UniFiController.java:227) [21:org.openhab.binding.unifi:2.2.0.201709220819]
at org.openhab.binding.unifi.internal.UniFiController.getDevices(UniFiController.java:243) [21:org.openhab.binding.unifi:2.2.0.201709220819]
at org.openhab.binding.unifi.internal.UniFiController.refresh(UniFiController.java:321) [21:org.openhab.binding.unifi:2.2.0.201709220819]
at org.openhab.binding.unifi.handler.UniFiControllerHandler.refresh(UniFiControllerHandler.java:137) [21:org.openhab.binding.unifi:2.2.0.201709220819]
at org.openhab.binding.unifi.handler.UniFiControllerHandler.run(UniFiControllerHandler.java:166) [21:org.openhab.binding.unifi:2.2.0.201709220819]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
at java.lang.Thread.run(Thread.java:748) [?:?]
2017-10-30 11:49:55.415 [WARN ] [unifi.handler.UniFiControllerHandler] - Error refreshing the UniFi Controller unifi:controller:home - org.openhab.binding.unifi.internal.UniFiException: Could not communicate with the UniFi Controller

I run my UniFi controller in NAS (docker container), so maybe that cause sometimes delay to connection.

I have the same issue on my side, yet I am using the official Unifi Controller Key, so it shouldn’t be a problem :
org.openhab.binding.unifi.internal.UniFiException: Could not communicate with the UniFi Controller

@mgbowman When I lose the Internet and/or VPN connection between my two sites, I get tons of these in openhab.log. Not sure the stack trace is very valuable for the UnknownHostException. Seems like the hostname and exception message in the log statement would be sufficient.

2017-11-08 09:12:16.400 [ERROR] [nding.unifi.internal.UniFiController] - Error trying to authenticate to UniFi Controller
java.net.UnknownHostException: unifi
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184) [?:?]
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) [?:?]
        at java.net.Socket.connect(Socket.java:589) [?:?]
        at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668) [?:?]
        at sun.net.NetworkClient.doConnect(NetworkClient.java:175) [?:?]
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:463) [?:?]
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:558) [?:?]
        at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264) [?:?]
        at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367) [?:?]
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191) [?:?]
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1138) [?:?]
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1032) [?:?]
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177) [?:?]
        at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1316) [?:?]
        at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1291) [?:?]
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250) [?:?]
        at org.openhab.binding.unifi.internal.UniFiController.get(UniFiController.java:138) [10:org.openhab.binding.unifi:2.2.0.201709220819]
        at org.openhab.binding.unifi.internal.UniFiController.get(UniFiController.java:161) [10:org.openhab.binding.unifi:2.2.0.201709220819]
        at org.openhab.binding.unifi.internal.UniFiController.login(UniFiController.java:202) [10:org.openhab.binding.unifi:2.2.0.201709220819]
        at org.openhab.binding.unifi.handler.UniFiControllerHandler.refresh(UniFiControllerHandler.java:124) [10:org.openhab.binding.unifi:2.2.0.201709220819]
        at org.openhab.binding.unifi.handler.UniFiControllerHandler.run(UniFiControllerHandler.java:166) [10:org.openhab.binding.unifi:2.2.0.201709220819]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
        at java.lang.Thread.run(Thread.java:748) [?:?]

After upgrading to latest 2.2.0-SNAPSHOT I am getting the following stack trace:

2017-11-12 13:31:17.211 [ERROR] [nding.unifi.internal.UniFiController] - Error GET'ing URL: https://10.0.0.3:8443/api/s/null/stat/device
org.openhab.binding.unifi.internal.UniFiException: Could not communicate with the UniFi Controller
        at org.openhab.binding.unifi.internal.UniFiController.get(UniFiController.java:174) [10:org.openhab.binding.unifi:2.2.0.201709220819]
        at org.openhab.binding.unifi.internal.UniFiController.get(UniFiController.java:192) [10:org.openhab.binding.unifi:2.2.0.201709220819]
        at org.openhab.binding.unifi.internal.UniFiController.getDevices(UniFiController.java:227) [10:org.openhab.binding.unifi:2.2.0.201709220819]
        at org.openhab.binding.unifi.internal.UniFiController.getDevices(UniFiController.java:243) [10:org.openhab.binding.unifi:2.2.0.201709220819]
        at org.openhab.binding.unifi.internal.UniFiController.refresh(UniFiController.java:321) [10:org.openhab.binding.unifi:2.2.0.201709220819]
        at org.openhab.binding.unifi.handler.UniFiControllerHandler.refresh(UniFiControllerHandler.java:137) [10:org.openhab.binding.unifi:2.2.0.201709220819]
        at org.openhab.binding.unifi.handler.UniFiControllerHandler.run(UniFiControllerHandler.java:166) [10:org.openhab.binding.unifi:2.2.0.201709220819]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
        at java.lang.Thread.run(Thread.java:748) [?:?]

Seems like the value for site has turned into null. Tried setting the site=default in my unifi.things, which setups the Bridge manually, but still getting the same error. Using PaperUI for an automatic discovery results in the same problem.

How about including something to determine the band used for wifi? If 5G and 2.4G use the same ESSID (default), than it is not currently possible to detect wether a device is connect to 2.4G or 5G. In order to provide better in house location, however, this is a necessary information (AP is in 2nd floor, so when moving from second to first floor, rssi is actually getting better, because of the switch to 2.4G).

‘radio’ and/or ‘radio_proto’ could be used for that (otherwise, channel or bssid could also be used).

@mgbowman

I’m having a problem that I’ve been unable to sort out.

My config is a bit unique…

  • In Site A I have an openHAB instance along with the Unifi controller and several Unifi APs. This site is set up as the default site in the Unifi controller…

  • In Site B I have an openHAB instance along with several Unifi APs managed by the controller in Site A

  • Site A and Site B are connected by an IPSEC tunnel

Site A’s openHAB instance has a Unifi Bridge Thing that points to the Unifi controller in Site A, and some Unifi Wireless Client Things used for presence detection. These client Things specify site A in their Thing config.

Site B’s openHAB instance has a Unifi Bridge Thing that points to the Unifi controller in Site A, and some Unifi Wireless Client Things used for presence detection. These client Things specify site B in their Thing config.

When I come and go in site B, I see plenty of these messages in events.log

2017-11-21 07:32:23.847 [vent.ItemStateChangedEvent] - LastSeenMark changed from 2017-11-21T07:31:14.000-0500 to 2017-11-21T07:32:14.000-0500
2017-11-21 07:35:23.775 [vent.ItemStateChangedEvent] - PresenceMark changed from CLOSED to OPEN
2017-11-21 09:06:23.777 [vent.ItemStateChangedEvent] - PresenceMark changed from OPEN to CLOSED
2017-11-21 09:06:23.782 [GroupItemStateChangedEvent] - gPresence changed from OPEN to CLOSED through PresenceMark

When I come and go in site A (default site), I only ever see the LastSeen messages in events.log. However, the state of PresenceMark never changes.

2017-11-20 08:39:45.864 [vent.ItemStateChangedEvent] - LastSeenMark changed from 2017-11-20T08:34:33.000-0500 to 2017-11-20T08:35:34.000-0500
2017-11-20 08:40:45.885 [vent.ItemStateChangedEvent] - LastSeenMark changed from 2017-11-20T08:35:34.000-0500 to 2017-11-20T08:36:37.000-0500
2017-11-20 08:41:45.891 [vent.ItemStateChangedEvent] - LastSeenMark changed from 2017-11-20T08:36:37.000-0500 to 2017-11-20T08:37:37.000-0500

I’m running the same (latest) version of the binding in both sites.

I’ve validated the item definitions in both sites, and everything looks correct.

I’ve validated the Controller and Client Things, and they all look correct.

I’ve verified that the items are bound to the Client Thing channels correctly.

I’ve looked at the debug logs in both sites, and they appear to have all the correct information about the clients. I can provide you the debug logs separately if you want to have a look – don’t want to post here due to the information contained in the logs.

I don’t know if it’s relevant, but in the debug logs for both sites, Site B’s devices, clients, and insights always show up before site A’s devices, clients, and insights.

Site A

2017-11-17 08:41:45.801 [DEBUG] [unifi.handler.UniFiControllerHandler] - Refreshing the UniFi Controller unifi:controller:be865985
2017-11-17 08:41:45.822 [DEBUG] [nding.unifi.internal.UniFiController] - Found 3 UniFi Site(s):
2017-11-17 08:41:45.823 [DEBUG] [nding.unifi.internal.UniFiController] -   Site{name: 'TEST', path: 'XXXXXXX'}
2017-11-17 08:41:45.824 [DEBUG] [nding.unifi.internal.UniFiController] -   Site{name: 'MD House', path: 'YYYYYYYY'}
2017-11-17 08:41:45.824 [DEBUG] [nding.unifi.internal.UniFiController] -   Site{name: 'NJ House', path: 'default'}
2017-11-17 08:41:45.828 [DEBUG] [nding.unifi.internal.UniFiController] - Found 0 UniFi Device(s):
2017-11-17 08:41:45.844 [DEBUG] [nding.unifi.internal.UniFiController] - Found 5 UniFi Device(s):
<<device detail here>>
2017-11-17 08:41:45.856 [DEBUG] [nding.unifi.internal.UniFiController] - Found 4 UniFi Device(s):
<<device detail here>>
2017-11-17 08:41:45.861 [DEBUG] [nding.unifi.internal.UniFiController] - Found 0 UniFi Client(s):
2017-11-17 08:41:45.872 [DEBUG] [nding.unifi.internal.UniFiController] - Found 30 UniFi Client(s):
<<client detail here>>
2017-11-17 08:41:45.897 [DEBUG] [nding.unifi.internal.UniFiController] - Found 13 UniFi Client(s):
<<client detail here>>
2017-11-17 08:41:45.908 [DEBUG] [nding.unifi.internal.UniFiController] - Found 0 UniFi Insights(s):
2017-11-17 08:41:45.911 [DEBUG] [nding.unifi.internal.UniFiController] - Found 0 UniFi Insights(s):
2017-11-17 08:41:45.915 [DEBUG] [nding.unifi.internal.UniFiController] - Found 7 UniFi Insights(s):
<<insights detail here>>
2017-11-17 08:41:45.919 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:mark:online
2017-11-17 08:41:45.920 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:mark:site
2017-11-17 08:41:45.920 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:mark:ap
2017-11-17 08:41:45.921 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:mark:essid
2017-11-17 08:41:45.923 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:mark:rssi
2017-11-17 08:41:45.924 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:mark:uptime
2017-11-17 08:41:45.925 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:mark:lastSeen

Site B

2017-11-22 07:18:42.990 [DEBUG] [unifi.handler.UniFiControllerHandler] - Refreshing the UniFi Controller unifi:controller:5a125155
2017-11-22 07:18:43.100 [DEBUG] [nding.unifi.internal.UniFiController] - Found 3 UniFi Site(s):
2017-11-22 07:18:43.101 [DEBUG] [nding.unifi.internal.UniFiController] -   Site{name: 'TEST', path: 'XXXXXXXX'}
2017-11-22 07:18:43.102 [DEBUG] [nding.unifi.internal.UniFiController] -   Site{name: 'MD House', path: 'YYYYYYYY'}
2017-11-22 07:18:43.102 [DEBUG] [nding.unifi.internal.UniFiController] -   Site{name: 'NJ House', path: 'default'}
2017-11-22 07:18:43.131 [DEBUG] [nding.unifi.internal.UniFiController] - Found 0 UniFi Device(s):
2017-11-22 07:18:43.357 [DEBUG] [nding.unifi.internal.UniFiController] - Found 5 UniFi Device(s):
<<device detail here>>
2017-11-22 07:18:43.485 [DEBUG] [nding.unifi.internal.UniFiController] - Found 4 UniFi Device(s):
<<device detail here>>
2017-11-22 07:18:43.517 [DEBUG] [nding.unifi.internal.UniFiController] - Found 0 UniFi Client(s):
2017-11-22 07:18:43.878 [DEBUG] [nding.unifi.internal.UniFiController] - Found 37 UniFi Client(s):
<<client detail here>>
2017-11-22 07:18:43.939 [DEBUG] [nding.unifi.internal.UniFiController] - Found 8 UniFi Client(s):
<<client detail here>>
2017-11-22 07:18:43.980 [DEBUG] [nding.unifi.internal.UniFiController] - Found 0 UniFi Insights(s):
2017-11-22 07:18:44.018 [DEBUG] [nding.unifi.internal.UniFiController] - Found 10 UniFi Insights(s):
<<insights detail here>>
2017-11-22 07:18:44.068 [DEBUG] [nding.unifi.internal.UniFiController] - Found 0 UniFi Insights(s):
2017-11-22 07:18:44.068 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:a59319bd:online
2017-11-22 07:18:44.070 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:a59319bd:site
2017-11-22 07:18:44.071 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:a59319bd:ap
2017-11-22 07:18:44.071 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:a59319bd:essid
2017-11-22 07:18:44.072 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:a59319bd:rssi
2017-11-22 07:18:44.073 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:a59319bd:uptime
2017-11-22 07:18:44.073 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:a59319bd:lastSeen

Do you have any idea what might be going on?

just another data point:
openHAB 2.3.0 Snapshot build #1151
on Debian 8 x64 host with Oracle’s JVM 1.8.0_151-b12
running UniFi Binding v2.2.0.201709220819

All is working well :slight_smile:

I have to find a way to display the Uptime in a human readable format :stuck_out_tongue: (instead of seconds)

I have been using the binding with no problems. Would it be possible to add a channel “Channel”? I could use it to have devices connect between the 2.4 and 5 when using the same SSID. Great binding and thanks.

Thanks for developing this binding. Looking at everyone’s screenshots and browsing the readme, it seems great.

I am struggling to get the binding running however. I have tried installing the binding by putting the latest build referenced in the thread (build #54) into /usr/share/openhab2/addons and configuring my things and my items. I don’t see any status updates when I do that. I then enabled trace logging for the binding in the karaf console - but I see no log messages.

When I look at the binding list in the karaf console, it says the binding is installed but it is not ‘active’ like all the other bindings.

I removed it by uninstalling it in karaf, then removing the file from the addons directory. I then reinstalled it by doing a bundle:install in karaf and using the URL for build #54. But it still doesn’t move from installed to active. If I do a bundle start in karaf, I get an error: “Unresolved Requirement: Import-Package: com.fasterxml.jackson.core”

Any tips on getting this binding up and running?

I suppose that seaching in this topic with the term Jackson should give you the answer.

Thanks for the tip… I did find it.

Is there a reason the libraries are not being shipped with the binding?

Hello -

Great binding and addition to OH. I had it set up and working in less than 10 minutes.

Quick question in regards to the UPTIME channel. Is it possible to change the display from seconds to minutes? If someone has been home awhile that number could grow…

Any suggestions would be appreciated.

Thanks,

Squid

Had the same problem so I made a rule. Replace the XXX with the name you want and create the formatted item.

rule "Format XXX Phone Uptime"
when
Item XXXPhoneUptime changed
then
var int days = ((XXXPhoneUptime.state as DecimalType).intValue / (86400))
var int hours = (((XXXPhoneUptime.state as DecimalType).intValue / 3600) - (24 * days))
var int minutes = (((XXXPhoneUptime.state as DecimalType).intValue / 60) - ((1440 * days) + (60 * hours)))
var int seconds = (((XXXPhoneUptime.state as DecimalType).intValue) - ((86400 * days) + (3600 * hours) + (60 * minutes)))
var String result = “”
// days
if (days > 0) {
result = result + days + " Day / "
}
// hours
if (hours > 0) {
result = result + hours + " Hours / "
}
// minutes
if (minutes > 0) {
result = result + minutes + " Min / "
}
// seconds
if (seconds > 0) {
result = result + seconds + " Sec "
}
XXXPhoneUptimeFormatted.postUpdate(result)
logInfo(“system.rules”, "Uptime updated to " + XXXPhoneUptimeFormatted.state)
end

I created a rule using your code, and made the appropriate changes…

I’m now seeing the following error in my OH.log file

2018-01-04 00:27:02.786 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'unifi.rules' has errors, therefore ignoring it: [9,21]: no viable alternative at input 'â'
[27,9]: no viable alternative at input 'â'
[27,24]: no viable alternative at input 'â'
[27,72]: extraneous input ')' expecting 'end'

2018-01-04 00:27:02.829 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'unifi.rules' has errors, therefore ignoring it: [9,21]: no viable alternative at input 'â'
[27,9]: no viable alternative at input 'â'
[27,24]: no viable alternative at input 'â'
[27,72]: extraneous input ')' expecting 'end'

2018-01-04 00:27:02.853 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'unifi.rules' has errors, therefore ignoring it: [9,21]: no viable alternative at input 'â'
[27,9]: no viable alternative at input 'â'
[27,24]: no viable alternative at input 'â'
[27,72]: extraneous input ')' expecting 'end'

any ideas?

@jcf6288

Ok, I figured out the error. When you copied and pasted your rule, you did not use code fences so the quotes " " became smart quotes. I have fixed the issue in two places and now I’m getting the following error message"

2018-01-04 00:37:25.212 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert '4 Hours / 50 Min / 47 Sec ' to a state type which item 'xxxPhoneUptime' accepts: [DecimalType, UnDefType].

Do I need to make a change to my item ? It was originally a Number type but I changed it to a String…still can’t get the converted data to display?

Any ideas?

The formatted item will be a string, the channel item is a number.

@jcf6288

Could you post your item for me? I can’t get this to work!

Many thanks,

Squid