Ubiquiti Unifi Binding Feature Discussion

Hi!
God job. Works awesome! :smiley:
Is there any hack how to implement the HTTP Binding to send the items via JSON or something like this to a webserver?
I will use this to log the presence.

Regards
Roger.

Same here.
If you want to test your openHAB logic, open the unifi controller and force the client to reconnect. That will force it offline.

@Roger_Rehnelt Roger, if the objective is to log presence based on the status changes in OH using persistence is probably a more straightforward and cleaner solution.

You can persist the items you want to track and use a MySQL persistence for those. This way they are stored in a database and are probably more easily to use afterwards. Just a though of course.

Depending on what exactly you’re trying to accomplish, I agree with what @rswennen said: persistence (or possibly MQTT) is what you’re looking for - we don’t like hacks around here! :wink:


Thanks for the tip!

Thinking about this a little more, what do you guys think I should do in the case of the controller reporting the client as offline before this new timeout?

IIRC, there were a few instances where the controller would return an empty response, thereby reporting all clients as offline. On the next refresh they were all back online.

I’m thinking this should be an IFF type timeout. If the timeout is say 120s, once the client is online, it will not be reported as offline until at least 120s has passed - regardless of the controller’s response.

Thank you for your hint. But I will attach the log to an existing user management on our server.
Should I still using “MySQL persistence”? How can I implement this to my configs? Are there some examples? Would be helpful
 Thanks in advance!!

I think this would be an appropriate way to handle these scenarios. I have noticed in my log a few occasions where my devices, including the controller go offline with a Communication Error. In one case it was four minutes before it came back online. My assumption was that the controller stopped responding, although I can’t say why.

Hello Roger,
you will most probably find more helpful answers by posting this question in a new thread with the right title. It’s not really related to the Unifi Binding.
Good luck!

1 Like

I just did. And it worked just as it should. Thx for this tip


I just checked my log. The lastseen is still counting even if the device isn’t seen. Without having it verified it looks like RSSI stops updating imediately after leaving.I see a pattern that RSSI changing a lot when you are leaving (moving around). If it can be distinguised from other things isn’t clear to me.

Thats strange

Here the lastseen stops updating short time after I disconnect the mobilephone, at least in Basic UI.

I don’t see any updates, but if I look at the disconnect event, it has been counting for the last 10 minutes. Therefore I am not sure if you can conclude that a missing update means disconnect. I would have to look deeper into my events.log file for that :slight_smile:

Kim, what latest version are you talking about, of the Jackson jars? or did you use 2.4.5. Reason for asking is I run Openhabian and on my setup the Jackson dependencies are not fetched either but noticed there were more recent versions of those.

I have the JSONpath installed so that does not automatically install them despite what’s said in some other post.

So I’m happy to report I’ve managed to implement this “timeout” we’ve been discussing using the Insights data from the controller. Surprisingly, it was a lot easier that I expected :laughing:

However, I had a long day and currently I’m having a brain fart
 I can’t think of a good name for the configuration parameter :rofl:

First I used timeout but it doesn’t make sense from the logical view of the controller - could be interpreted as the amount of time to wait for a response from the controller.

Then I used expiry but just doesn’t sound right to me :stuck_out_tongue:

Once I nail this down, I can package this up for you guys to do some final testing!

Thoughts?

I downloaded and installed the 2.9.1 version of all the packages from the above link.

How about “pause”, or “waiting”

Latest build: org.openhab.binding.unifi-2.2.0-SNAPSHOT.jar

I chose considerHome as the parameter - see the updated Binding Configuration

Depending on your controller, you may have to tweak the considerHome interval so you don’t get false positives (clients being prematurely marked as away).

For example, the controller at my office was only returning updates approx. every 60 seconds (I’m not exactly sure why - maybe it’s an older version). When I tested with a considerHome window of 60s, my phone was getting marked as away for one or two refresh intervals since the lastSeen channel wasn’t being updated within 60s

In reality, the binding was doing exactly what it was supposed to do.

After you guys have tested this a bit and I fix some documentation in the code, I can open a PR to merge this into the master OH2 branch.

Let me know if you have any issues.

1 Like

@mgbowman

I just installed the latest build, and I’m now seeing these WARNs in the log. Any idea what’s causing this?

2017-09-18 08:22:14.135 [WARN ] [ing.unifi.handler.UniFiClientHandler] - Unable to update channel 'site' : device == null
2017-09-18 08:22:14.136 [WARN ] [ing.unifi.handler.UniFiClientHandler] - Unable to update channel 'ap' : device == null

In debug mode, I’m seeing this.

2017-09-18 08:20:34.251 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:a59319bd:online
2017-09-18 08:20:34.252 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Could not find a matching client: mac = fc:db:b3:XX:XX:XX, site = MD House
2017-09-18 08:20:34.253 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:a59319bd:site
2017-09-18 08:20:34.253 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Could not find a matching client: mac = fc:db:b3:XX:XX:XX, site = MD House
2017-09-18 08:20:34.254 [WARN ] [ing.unifi.handler.UniFiClientHandler] - Unable to update channel 'site' : device == null
2017-09-18 08:20:34.254 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:a59319bd:ap
2017-09-18 08:20:34.255 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Could not find a matching client: mac = fc:db:b3:XX:XX:XX, site = MD House
2017-09-18 08:20:34.255 [WARN ] [ing.unifi.handler.UniFiClientHandler] - Unable to update channel 'ap' : device == null
2017-09-18 08:20:34.256 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:a59319bd:essid
2017-09-18 08:20:34.256 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Could not find a matching client: mac = fc:db:b3:XX:XX:XX, site = MD House
2017-09-18 08:20:34.257 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:a59319bd:rssi
2017-09-18 08:20:34.257 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Could not find a matching client: mac = fc:db:b3:XX:XX:XX, site = MD House
2017-09-18 08:20:34.257 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:a59319bd:uptime
2017-09-18 08:20:34.258 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Could not find a matching client: mac = fc:db:b3:XX:XX:XX, site = MD House
2017-09-18 08:20:34.258 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:a59319bd:lastSeen
2017-09-18 08:20:34.258 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Could not find a matching client: mac = fc:db:b3:XX:XX:XX, site = MD House
2017-09-18 08:20:34.258 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:4dc07647:online
2017-09-18 08:20:34.259 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Could not find a matching client: mac = ac:cf:85:YY:YY:YY, site = MD House
2017-09-18 08:20:34.259 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:4dc07647:site
2017-09-18 08:20:34.260 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Could not find a matching client: mac = ac:cf:85:YY:YY:YY, site = MD House
2017-09-18 08:20:34.260 [WARN ] [ing.unifi.handler.UniFiClientHandler] - Unable to update channel 'site' : device == null
2017-09-18 08:20:34.260 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:4dc07647:ap
2017-09-18 08:20:34.261 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Could not find a matching client: mac = ac:cf:85:YY:YY:YY, site = MD House
2017-09-18 08:20:34.261 [WARN ] [ing.unifi.handler.UniFiClientHandler] - Unable to update channel 'ap' : device == null
2017-09-18 08:20:34.261 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:4dc07647:essid
2017-09-18 08:20:34.261 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Could not find a matching client: mac = ac:cf:85:YY:YY:YY, site = MD House
2017-09-18 08:20:34.262 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:4dc07647:rssi
2017-09-18 08:20:34.262 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Could not find a matching client: mac = ac:cf:85:YY:YY:YY, site = MD House
2017-09-18 08:20:34.262 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:4dc07647:uptime
2017-09-18 08:20:34.263 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Could not find a matching client: mac = ac:cf:85:YY:YY:YY, site = MD House
2017-09-18 08:20:34.263 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Refreshing channel = unifi:client:4dc07647:lastSeen
2017-09-18 08:20:34.263 [DEBUG] [ing.unifi.handler.UniFiClientHandler] - Could not find a matching client: mac = ac:cf:85:YY:YY:YY, site = MD House

I did the update remotely, so neither device represented by the client things is present at the site.

Edit: I was running this version and was not seeing these WARNs.

2017-09-18 08:49:06.247 [INFO ] [unifi.handler.UniFiControllerHandler] - UniFi Binding v2.2.0.201709020839

Edit 2: I went back to this version and all is well again.

Hi Mark,

Those logging statements were mistakenly outside of the if (clientOnline) { ... } checks.

I just pushed an update which should quiet the warnings whenever a client is offline.

Please update and let me know if you have any more issues.

1 Like

Yes, much better now. :+1:

Thanks!!

Found this binding and was hoping it would solve my presence problems once and for all :wink:
but the binding generates an error:

2017-09-19 21:22:11.681 [ERROR] [nding.unifi.internal.UniFiController] - Error GET’ing URL: https://192.168.1.40:8443/api/s/default/stat/alluser
com.fasterxml.jackson.databind.JsonMappingException: Unexpected token (END_OBJECT), expected FIELD_NAME: missing property ‘is_wired’ that is to contain type id (for class org.openhab.binding.unifi.internal.api.UniFiClient) at [Source: { “data” : [ { “_id” : “596704f0cddcb36” , “duration” : 3081941 , “first_seen” : 1499923267 , “hostname” : “AppoPad” , “is_guest” : false , “is_wired” : false , “last_seen” : 1505849431 , “mac” : “xx;xx:xx:xx” , “noted” : false , “oui” : “Apple” , “rx_bytes” : 1634123047 , “rx_packets” : 7745351 , “site_id” : “abcdefg” , “tx_bytes” : 18065290694 , “tx_packets” : 13999876} , { “_id” : “58f123e14f0c16” , “duration” : 10169615 , “first_seen” : 1492198369 , “hostname” : “Thuispad” , “is_guest”

etc


Controller is reported as offline, as are the clients.

I am running OH2.1 and Unifi 5.5.20. UniFi Binding 2.2.0.201709191042

What can I check or change?

kr Han