[RELEASE] Unifi Wifi Presence

@diondp Try updating it one more time, the events were happening but if you just went to the device they did not show up.

Is it visible to rules so i could use it as an extended presence sensor, meaning i could make a rule based on the user connecting to a specific AP...

@diondp yes it should work with rules now.

It seems to be working but it stopped checking one of my phones and I got this in the log

There is something more going on w/ it as unifi has the phone greyed out...but figured the log might be worth something to you.

works fantastic!
do you have a paypal link, i would like to buy you a cup of coffee, this is solid work and very useful to me.

@diondp Thanks, Sure it in the the Update Manager as well.

https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=R6M87FLA29TLS&source=url

1 Like

I just started experimenting with the Unifi integration. This is a wonderful addition and something that I've always wondered for presence detection. Thanks @mike10 for this!

I did run into the same log error as @pltaylor3 and realized that on my Unifi controller devices don't always disappear when they are no longer connected to the wifi. In those cases "status2" is not empty, but the AP Mac is null, so there is no ap data.

I wonder if this is because I have static DHCP assignment for most of my network devices and I know there have been discussions on the Unifi community that devices appear as "wired" ghost devices after dropping off the wireless. I did add a log of status2 and can see it changing from the correct "present" log with is_wired:false to empty and then to a log with is_wired:true and no AP data.

Since the test for present/not present is just based on status2 being empty, it will keep detecting my phone as present unless I also check if AP info is null

Hope this helps for cases where presence seems sticky.

I just started using this and had the same problem. It looks like unifi keeps reporting a ghost status for my phone after it drops off the wifi. Do you have a fixed IP (through DHCP) for that phone. I have that and I wonder if that's the issue.

I do see that the reported status changes from is_wired:false when connected to is_wired:true when disconnected but the phone is obviously never wired to the network.

It's not a fixed IP.

Then I guess that's not the trigger for the "ghost status" .

For now I made a little workaround by adding a check to line 74 locally:
if(apinfo) { sendEvent(name: "ap_name", value: apinfo.data[0].name) state.ap_name = apinfo.data[0].name } else { sendEvent(name: "ap_name", value: "") state.ap_name = null status3 = false }
But I haven't tested enough yet to see if that reliably fixes presence status.
Edit: sorry for the bad formatting of the code part

if(apinfo) { 
    sendEvent(name: "ap_name", value: apinfo.data[0].name)
    state.ap_name = apinfo.data[0].name 
} else {
    sendEvent(name: "ap_name", value: "") 
    state.ap_name = null 
    status3 = false 
}

that code looks perfectly reasonable to me...I'm going to try it as well.

Thats odd I was not experiencing that issue but updated the code with your suggestion thanks.

This snippet seems to have solved my problems in the short time I have been testing it.

Thanks for the work, this works pretty freaking well.

Nice. I pulled the update through package manager so it shows that I'm on the current one. Thanks!

Can someone with a UDMPro test with the latest version and see if they get a valid cookie?

You may need to change the site name to "proxy/network"

Basing this off of the API documentation.
https://ubntwiki.com/products/software/unifi-controller/api


This is the response I got after trying the newest version with UDM Pro running the latest firmware/controller 1.80-rc.16/6.0.13.

Using the default port resulted in an error, but 443 seems to have solved that. I tried both default and "proxy/netwok" same results.

I'm getting the same response as @halfrican.ak :
java.lang.RuntimeException: java.sql.SQLException: Value too long for column "VALUE VARCHAR(255)":

yeah that must be an issue within hubitat my guess is the logging function, because I am not doing any SQL within my code.

So I updated to the latest code and I seem to be making some progress. I have the same result as @halfrican.ak (which I guess is fine), but on my devices I don’t see any logs.

This is what I see on my child device to block when I hit ‘Get ClientID’.

To get this to work for me I had to put the code between "site/" and "/dashboard" in the url of the web GUI into the "Unifi Site, most likely the default.*" field of the parent device.

Example controller url: https://xxx.xxx.xxx.xxx:8443/manage/site/site code/dashboard

Once I did that everything worked.

2 Likes