Unifi Binding doesn't turn off device online status

I have an issue with 2.5.10 version of the Unifi binding. It seems that it doesn’t detect that a device is offline.

I’ve turned off wifi on my Oneplus 7T and the item connected to the appropriate channel does not go offline and the “lastSeen” still updates, even after 20 minutes. I’ve tested this repeatedly.

I’ve tried to restart the binding, but the problem persists.

I have openHAB 2.5.10 and the latest Unifi binding. My Unfi controller is 5.12.72 (yes, I need to get it updated).

Any suggestions as to where to look?

Thanks!

I did some additional testing and only when restarting openhab or the server does the binding correctly detect the status of a device.

this topic pops up every seconds month, e.g.

and the conclusion until now was that it is unifi fault and we have no way to detect the status correctly.
but now, if you say, openhab restart solves the issue, then potentially it could openhab binding issue

Well, I can do one better. :wink: I have an older OH install that works just fine.

My Unifi controller is on 5.12.72 and has been for a while. I just finished moving from OH 2.5.7. on an old RPI 3+ to a new RPI4 with OH 2.5.10.

The old OH 2.5.7 had an older Unifi binding and the on that the online/offline detection worked. On the new 2.5.10, I converted the Things configuration to reflect the new binding.

To me that suggests that there’s a bug in the binding, not in Unifi.

I’ll happily drag the old OH install out and give you all the details, just let me know what to look for.

So, I did some testing to try to help getting closer to where the problem lies.

The background is that I migrated my 2.5.7. OH setup on an overworked Raspberry pi 3+ over to a new 2.5.10 setup on a brand new Raspberry PI 4 (2GB). As part of that transition, I also changed over to the new 2.5.10 Unifi binding and things configuration.

Unifi Setup
I’m on a Unifi controller v.5.12.72.

2.5.7 Configuration
bundle:

270 │ Active │  80 │ 2.5.9                   │ openHAB Add-ons :: Bundles :: UniFi Binding

Things:

Bridge unifi:controller:home "UniFi Controller" [ host="192.xxx.xxx.xxx", port=8443, username="someuser", password="somepassword", refresh=10 ] 
{
	Thing client BjarnesPhone "Bjarne's 1Plus7T" [ mac="xx:xx:xx:xx:xx:xx", considerHome=180 ]
} 

2.5.10 Configuration
Bundle:

278 │ Active │  80 │ 2.5.10                  │ openHAB Add-ons :: Bundles :: UniFi Binding 

Things:

{
	Thing wirelessClient bjarnesPhone "Bjarne's 1Plus7T" [ cid="xx:xx:xx:xx:xx:xx", considerHome=180 ]	
} 

2.5.7. Logs

Log:
Startup
2020-11-03 10:41:50.551 [vent.ItemStateChangedEvent] - BjarnesPhone changed from NULL to ON

Turned off wifi
2020-11-03 10:51:25.490 [vent.ItemStateChangedEvent] - BjarnesPhone changed from ON to OFF

Turned on wifi
2020-11-03 10:52:08.421 [vent.ItemStateChangedEvent] - BjarnesPhone changed from OFF to ON

2.5.10 Logs

Log
Left house (i.e. turned wifi off )
2020-11-02 17:20:44.045 [vent.ItemStateChangedEvent] - Shellydw2_Entrance_Door changed from OPEN to CLOSED

Unifi wificlient turned off
2020-11-02 17:55:52.933 [vent.ItemStateChangedEvent] - BjarnesPhone changed from ON to OFF

Came back to house (i.e. turned wifi on)
2020-11-02 18:00:08.047 [vent.ItemStateChangedEvent] - BjarnesPhone changed from OFF to ON

Left house (i.e. turned wifi off )
2020-11-03 08:45:38.354 [vent.ItemStateChangedEvent] - Shellydw2_Entrance_Door changed from OPEN to CLOSED

Unifi wificlient turned off
2020-11-03 09:28:17.786 [vent.ItemStateChangedEvent] - LisetsPhone changed from ON to OFF

2.5.7 Summary of Logs
The old logs don’t show an indicator of when I “left” the wifi, but OH received an “offline” within seconds ad likewise showed me online, almost as soon as I turned wifi back on again.

2.5.10 Summary of Logs
The Shellydw2_Entrance_Door changed from OPEN to CLOSED event shows when I left the wifi network and the BjarnesPhone changed from ON to OFF indicates when OH believes me offline.

I ran the above test on the 2.5.10 setup twice (my Android phone and my wife’s iPhone) and in both cases there’s a 30-45 minutes “gap” between Unifi showing me offline and OH showing me offline.

In both cases, there’s little time between my phones showing up in the Unifi console and the OH log.

From the above tests using the same controller and the same phone, I would tend to suspect something in the new binding.

I’ve kept the old server/boot disk, so let me know if you need me to do more testing.

Regards,
Bjarne

1 Like

@mgbowman Did you have a chance to check the data in my post?

Just a follow-up on my previous post.

I decided to try out the https://jenkins.otr.mx/job/openhab2-unifi-binding/lastSuccessfulBuild/artifact/bundles/org.openhab.binding.unifi/target/org.openhab.binding.unifi-2.5.5-SNAPSHOT.jar provided by @mgbowman. It completely solved my issues with Unifi, now my wireless devices show up correctly and leave within the time-out set in the thing configuration.

the SNAPSHOT binding also introduces some nifty things including the number of clients and the ability to track wired clients.

you can read more about the new features here: https://github.com/mgbowman/openhab-addons/blob/unifi-binding/bundles/org.openhab.binding.unifi/README.md

Kudos to @mgbowman

1 Like

Had the same issue, installing this package solved my issue as well! Thanks for sharing

Using unifi controller 6, openhab 2.5.2

Glad to hear and the pleasure is all mine…

How did you find out the Jenkins link? I have the same issue in 3.0 (stable) and 3.1 (snapshot) and the 2.5.5-binding doesn’t work in OH3.

Thank you!

I found them in the Unifi bindings topic. To the best of my knowledge, @mgbowman actually posted the link himself.

I had a check to on the unifi binding. Currently installed 3.1.0 on openhab 3.1.0 snapshot.
The binding doesn’t work well. All devices are shown online. My own shell script which also gathers information from unifi controller is working fine and providing the correct status for each device.

What’s the issue with the unifi binding? Why is it working sometimes and why not?!?

I can also confirm that the channels “last seen” and “Online” don’t work as expected.
I set the binding to “TRACE” and I can see all the device’s info coming in with the right time stamps, so I would say that the binding doesn’t update the channels correctly.

here is an excerpt for one of my clients

{
      "site_id": "5c67d520619d710297524d32",
      "assoc_time": 1614894631,
      "latest_assoc_time": 1614894790,
      "oui": "",
      "user_id": "5ffe07b6619d71021e755c41",
      "_id": "5ffe07b6619d71021e755c41",
      "mac": "4e:1a:e3:45:ff:ff",
      "is_guest": false,
      "first_seen": 1610483638,
      "last_seen": 1614895305,

if you convert these times first seen = 21:33:58 and last seen = 23:01:45 which is about the time of my writing, though the channels are “away” and “null”.

I looked into the code and I would expect that the channels are updated in UnifiClientThingHandler.refreshChannel which itself is either called by handleCommand or refresh. For the latter I do see the debug log “Refreshing the UniFi Controller” but even though the channels are not updated.

@mgbowman would you mind having a look at it? As I am maintainer I can also compile the latest binding or add logs to it if you want.

cheers
Stefan

I finally can confirm that the binding indeed works. 2 of 3 of my phones “all of a sudden” started to work after I deleted the binding and reinstalled it.

The third one basically was my own mistaked. I configured the MAC address and it started receiving for some time and then it stopped. Eventually I found out that the MAC address on my android phone was configured to use a “Random” Mac-Address (which is a security feature), so it changed now and then, which of course makes no sense if you want to detect a device reliantly.

Hope that helps anyone who has similar problems.

Stefan

Hi and thanks for the info, however, this did not work for me. The unifi binding does not detect absence, either in textual configuration mode nor in UI mode. Also reinstallation did not help. I’m on OH3.1 with the corresponding binding. Under OH2.5 I did downgrade to the binding version which was functional, but this is not working anymore with 3.1
Any other hint on a possible solution for the problem?
Thanks,
Ben

I have also the problem that my mobile is not turning offline.