I wrote a SmartThings SmartApp, SmartThings Device Handler and a REST API server to enable the ability to use wireless clients on an Unifi Controller as presence sensors.
If you have a local Unifi Controller running on your local network, then you can use it’s wireless clients as presence sensors. I wrote this because of unreliable presence sensors. Hoping that by detecting if my phone is connected to my Unifi wireless network it will provide quicker / more reliable presence sensing for my automations.
If you would like to use Unifi wireless clients as presence sensors, give this solution a try and let me know what you think.
Awesome! Well with this option, I have it check every 5 seconds so really it’s 10-15 seconds from when your device connects to the wifi. So the real question is, at what point does your device connect to your wifi . I just finished all this yesterday so I have test presence sensors still on my phone to compare with the SmartThings mobile presence sensor and the Improved Mobile Presence. We’ll see which is quicker.
I’m bit of a docker noob never had any success with the bloody thing
I run the docker on a raspberry pi and the container just seems to be restarting every 8 seconds
Hello world doesn’t appear just get connection refused
@tmleafs I hear you. I’m new to Docker as well and had my fair share of hurdles. With my limited experience with Docker, I’ve only seen a Docker Container get stuck in a reboot loop when the image being used was not designed for the CPU architecture. Since you are running Docker on a Raspberry Pi, can you please make sure you are using the xtreme22886/unifi-presence-rest-arm image (specifically the arm variant).
Also, since new to Docker, I found it at ton easier to use Docker using a Docker manager like Portainer.
EDIT I just tested the ARM Docker image out and it isn’t working . So it isn’t just you. Let me fix this and once it’s fixed, I’ll let you know.
EDIT 2 The ARM Docker image has been fixed. Should work on Raspberry Pi now
Just wanted to say I’ve installed this and it works a treat! I had cobbled together another one in the past by hacking together a few other things, but this is much cleaner and faster! Thanks for the effort!
@spyd4r currently this only works in the Classic app. I’m sure I’ll eventually have to get it working in the newer app when they end support for the Classic app.
@tmleafs sweet! Glad it’s working now . It is very possible to monitor ‘wired’ clients as well. I thought about it while creating this but ended up going with just wireless clients. Let me look at the data I get from the Unifi API again and see how difficult it would be to include both wired and wireless devices.
Pruning the old data may remove your friend’s device and maybe cleaning up the DB will make your wife’s appear. If not, let me know and we can dig further into it. Also, please make sure your wife’s device is currently connected to your Unifi wireless and before tapping to select devices, sit on that screen for like 15 seconds to allow the SmartApp to get an updated list from the Unifi Bridge (you’ll see a spinning wheel on the page letting you know it’s constantly refreshing every 5 seconds).
@tmleafs, yes, that’s a stupid bug. But my Unifi Bridge accounts for this. That’s why I decided to only monitor for ‘wireless’ devices and not ‘wired’ devices. When a ‘wireless’ device disconnects from the network, it is then reported as ‘wired’. So 1) my SmartApp will only show ‘wireless’ clients. Maybe this is why your wife’s phone does not appear? 2) Makes it harder to try to monitor for ‘wired’ clients.
Thanks @sejuni. Another person has reported this to me. I’m looking into it now. I’ll let you know when I’m able to find out more about this issue.
EDIT I just updated the Docker image so hopefully the new image will prevent the device flapping. If you can, can you please test it out and let me know how it goes?
I think these would be the steps:
Delete existing Docker container
Delete existing Docker image
Re-download Docker image
Create new container using new image
Open the ‘Unifi Wireless Presence’ SmartApp and click ‘Save’. By clicking save, it’ll update the new Docker container with information about your Unifi Controller and what to monitor.
That should get things back up and running with the new Docker image and hopefully the issue resolved.
@tmleafs, did you get your wife’s phone sorted out? If you did, do you think I should allow people to select ‘wired’ clients as well from the SmartApp (to prevent the issue where they can’t find their wireless device)? This will allow people to select wireless clients that aren’t currently connected to the network. I wanted to filter out ‘isWired’ = True clients to reduce the list some people would have to sort though (depending on the size of their network).
The new container works very well. I will register all my family members and do some more testing. And I will give you feedback again. Thank you very much for the quick fix.
Thanks for the feedback @sejuni! I just updated the Docker image again. I changed up the logic for the ‘offline’ trigger. Please download the new image and let me know if there are any more issues.