Unifi Online Detection does not work


I’m on version 2.5.9 with the 2.5.9 unifi binding. Unifi Controller is 6.0.23.
The poll-time for the controller in the binding is set to 2 seconds, the Consider Home Interval is set to 30 seconds.

As long as I’m online everything is fine. The device is detected and the LastSeen time gets updated every few seconds.

Once I take a device offline, the LastSeen time holds, but the Online indicator doesn’t change. The last line related the the item in events.log indicates a change in LastSeen:

2020-09-28 23:42:42.862 [vent.ItemStateChangedEvent] - Dev1_Uptime changed from 2456 to 2478
2020-09-28 23:42:42.862 [vent.ItemStateChangedEvent] - Dev1_LastSeen changed from 2020-09-28T23:42:20.000+0200 to 2020-09-28T23:42:42.000+0200

nothing more. 20 minutes later the device still shows as online, even though last seen time is very old now.

Do you have any Idea what I might be doing wrong?

Thanks for any help

What device? Do you mean the Thing? Thing online/offline status does not necessarily track any real device status. So far as openHAB is concerned, the Thing is still available to try and communicate with your device.

Last time this happened to me I went into Insights on the Unifi Controller, then did a Forget on the device. It started working again after that.

Sorry, I meant the “Online”-Item in the Wireless Client Thing.

Thanks. I tried this, but unfortunately no improvement.

Do you have any output from the binding in the log?

I have rewritten the unifi binding to work with Ruckus, so I have looked at it indepth.
The online channel works as following:

private synchronized boolean isClientHome(UniFiClient client) {
        boolean online = false;
        if (client != null) {
            Calendar lastSeen = client.getLastSeen();
            if (lastSeen == null) {
                logger.warn("Could not determine if client is online: cid = {}, lastSeen = null", config.getClientID());
            } else {
                Calendar considerHome = (Calendar) lastSeen.clone();
                considerHome.add(Calendar.SECOND, config.getConsiderHome());
                Calendar now = Calendar.getInstance();
                online = (now.compareTo(considerHome) < 0);
        return online;

Which means it’s looking at lastSeen. If lastSeens is updated correctly online should work too, unlesss there are exceptions or warnings.

You can however “fix” this with you own rule that looks at last seen rather than online as a last resort if no developer is around to take a look.
You could also add your own debug logging in the binding and build it yourself and test (requires some knowledge, but is not rocket science).


Thanks. No output in openhab.log from unifi binding. Ok, I’ll write my own rule for now, thanks for the input :slight_smile: I want to write a rule to react to this state anyway, so I can just instead react to lastseen

I’ve gone Seaside-described custom code leveraging getLastSeen, but after some trials managed to get built-in functionality working very reliably. Here is my config as a sample:

.things file

Bridge unifi:controller:home "Home UniFi Controller" [ host="192.168.x.y", port=8443, username="xxxxxx", password="yyyyyy", refresh=10 ] {
    Thing wirelessClient myPhone "My Cellphone" [ cid="xx:xx:xx:xx:xx:xx", site="home", considerHome=60 ]

.items file

Group gPeople_Presence <presence>
Switch Presence_myCellphone "My Cellphone [MAP(unifi.map):%s]" (gPeople_Presence) {channel="unifi:wirelessClient:home:myPhone:online"}

unifi.map file


Note that the Item has to be a Switch.
I’ve created special read-only user for unifi interface with OH2.