[RELEASE] Unifi Presence Sensor

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.

5 Likes

ill try this out!, looks awesome. ill install it tomorrow. how fast does this update compared to other options? life360, smarthings native phone, ect

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 :wink:. 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 :frowning:. 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 :slight_smile:

2 Likes

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!

1 Like

Does this work with the newer SmartThings App? Or just the Classic?

@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.

1 Like

@xtreme22886 Thanks, thats too bad.

All working :slightly_smiling_face:

Is it possible to do add wired devices too? as this seems a more reliable way than host pinger on a few wired devices make it a virtual switch DH

@tmleafs sweet! Glad it’s working now :slight_smile:. 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.

1 Like

I don’t seem to be seeing all WiFi devices my wifes mobile isnt on there but a friends who hasnt been round for months is :frowning_face:

@tmleafs hmm. I’ve seen very old devices appear but I haven’t experienced currently active wireless devices from not appearing in the list.

Try pruning old data on your Unifi Controller: https://help.ubnt.com/hc/en-us/articles/204911424-UniFi-How-to-Remove-Prune-Older-Data-and-Adjust-Mongo-Database-Size

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).

Unifi is doing that annoying bug when its clearly a wireless device but it thinks its a wired :rage:

2 Likes

@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.

Unifi presence sensor repeat out and return home like the attached photo.

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:

  1. Delete existing Docker container
  2. Delete existing Docker image
  3. Re-download Docker image
  4. Create new container using new image
  5. 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.

© 2019 SmartThings, Inc. All Rights Reserved. Terms of Use | Privacy Policy

SmartThings; SmartApps®; Physical Graph; Hello, Home; and Hello, Smart Home are all trademarks of the SmartThings, Inc.