[OBSOLETE] ASUSWRT Wifi Presence

I have created a pretty solid wifi presence solution for when my phones connect to the wifi network, its very quick to update ST.

I use this alongside the ST app, Life360 & my own Tado presence device type, i use Rule machine to flip a virtual presence sensor when any of the 4 change state, this is a first past the post setup and it works really well, before i put this in presence was really an issue. this however always triggers when all the others fail to update (regularly) but the range of this is not very far, only within the wifi range (obviously!)

ive seen other solutions for DD-WRT, but these don’t work with the Newer Asus routers, RT-AC87U or Newer as the command to list mac addresses with the new 5G hardware no longer uses wl

ok so the first thing i did was install the latest AsusWRT Merlin for my router

then once installed i then logged into the routers web page and went to administration → System

on this page i enabled SSH and set both these options to Yes

then i saved and rebooted the router. once this is restarted you can log into the console via SSH

in the /jffs/scripts folder i created a new file called CheckIfHome with the following contents (this example is the file with the mac addresses and oAuth detail stripped out for my family, it is checking for 4 users, this example should be very easy to follow and customise)

you then need to type the following command to allow execution of the script chmod 777 /jffs/scripts/CheckIfHome

then just create the CheckUser Folder with mkdir /jffs/scripts/CheckUser

I then installed 4 Virtual Presence Sensors one for each family member from my Virtual Presence Sensor Device Handler

and then i installed my SmartApp that ties this together and recieves the http Get from the router (be sure to enable oAuth in the smart app)

I used then used the ST Mobile app to install 4 copies of this smartapp, one for each Virtual presence sensor.

once these have been installed you need to get the Application ID and Access Token for each app, this can be gotten from the location Tab, List Smartapps page in the IDE, just click on each of the smartapps you just created and get the following details. (sorry cant draw with mouse :blush:)

then just update the respective curl request lines in the CheckIfHome Script with these details, remember to change the url to https://graph.api.smartthings.com if you are in the US

last but not least we want to run this script every 15 seconds (well at least i do !)

so the last thing is to create the init-start script in the /jffs/scripts folder using vi with the code from

you then need to run chmod 777 /jffs/scripts/init-start

and now either reboot your router or just run the command ./init-start which will schedule your wifi check to be performed every 15 seconds.

this does work extremely well, you can see for troublehooting purposes at any time on the router who is home or away by just running ls -als /jffs/scripts/CheckUser this will show any users who are currently home as they will have a Home File, if they are away this file will be deleted.

its a bit long winded but i hope this helps someone out, it works great for me, and did i mention it is quick to detect users? :slight_smile:

33 Likes

awww dude! MY ASUSWRT router just dumped on me and I got an airport. This would have been so awesome. Nice work however.

aah well that is a shame :slight_smile: thanks

i’ve just created a new smartapp based on this but will turn on & off a virtual switch rather than a presence sensor, I am just using it to detect if my smart tv’s in the house have been switched on by monitoring for them connecting to the wifi network. I am using this for an extra indicator/check that a room is occupied. the code is on my Github, i wont spam by creating another thread for similar functionality.

2 Likes

I guess I have to update to the latest Merlin, because mine doesn’t have curl included.

Blast! I can’t get the smartapp to actually install on my Android device. No surprise there, really. :frowning:

Yes the latest Marlin is needed to get curl. For the app natal lying, this shouldn’t be an issue. Did you enable oAuth on the smart app? As that’s the only reason I know it would come up with unexpected error.

Try running the live logging in the IDE when trying to install the smart app, this should give you the reason the app install is failing

I’ll double check oauth in a bit here. On another note, how are you triggering your virtual presence sensors via Rule Machines? It can’t handle these like switches. I feel like I’m missing something. There are variants of virtual presence floating around that do work that way, but this didn’t seem to.

this works as a presence sensor. I only use rule machine if I want to do things based on the presence home/away status

Hi Stuart,

Before I try this does it require that the client be logged on by WiFi directly to the Asus router ? I ask because the AC87U is my broadband router but I have some other WiFi access points to which my clients connect and then get a DHCP address from the AC87U - so they appear in the client list on the AC87U but they are not directly connected to it via WiFi ?

yes this script does look directly at the wifi interfaces for the connected clients. Using DHCP leases wont give you the updates as the leases run for a longer time…are the access points that the wireless clients connect to not ddwrt compatible?

No , unfortunately not. There are a couple of Apple products for example.

In the ‘client list’ that the AC87U main Internet router provides I had mistakenly thought that the client entries come and go as they attach and detach from the network. Certainly the number of connected devices varies from minute to minute so I wasn’t sure that it was populated from the acquired DHCP leases. Static IP devices enter and leave that client list too.

So, ever hopeful I had a play to see if my mobiles do appear and disappear in near realtime from the list. However having switched off my phone I notice the client entry is still there a long time later so that’s not going to work. Static or dynamic IP made no difference.

Looking at different approaches I could allocate a fixed IP via DHCP and ping to detect presence although that might impact battery life. There’s the Bluetooth alternative too when/if that interface gets enabled on ST. I can already detect that via a PC. If I move my routers around I could maybe get a ddwrt model in a more useful location that might make your app workable for me.

I’ve looked at the Bluetooth option using a raspberry pi. It works well but the range is not great at all, it detects me as away/home when I am moving around my house.

I don’t think a ping would work either as my phones do not reply to any pings for longish when asleep, I have no idea how it keeps wireless as showing active buy if I continuously ping my phone my phone connects it will respond every couple of minute or so when asleep but only 1 ping, if using that it wouldn’t be a reliable enough indicator IMHO

I played with BT a while back and I agree it wasn’t ideal range wise - hence your app was very interesting.

This morning my phone in the client list is appearing and disappearing within about 30 seconds of the WiFi being turned on/off. It is still connecting via a different AP. Curiously it also has a different IP to the one I was watching last night so I’m thinking it’s possible I was looking at the wrong device. It usually acquires the same address even though it’s using DHCP.

So the client list (if accessible) may be a usable indicator regarding presence of the device elsewhere on a LAN. If so it might extend the usefulness of your app to fixed attached device detection too (warning of a device loss). I’ll play some more and try and determine if it is a viable indicator and if so at some point I may take a look and see if the client list is accessible and if I can adapt the code to use it.

Thank you for this! Everything is working great!! I’ve had a presence issue driving me nuts where if my Android phone was updating presence my girlfriend’s Windows phone would completely fall off and never update again. The same for if her phone was updating, my Android never would. Her phone is using a different account and I could never figure it out. No issues with a different iPhone. Long story short, thanks for your work!

1 Like

your welcome, glad it worked for you

Is it possible to trigger a Maker channel alert (on IFTTT) based on WiFi presence? Specifically, I would like to initiate a Maker request (https://maker.ifttt.com/trigger/test123/with/key/XXYYZZ) when anyone is home.

this should work for a maker request. Just change the url to the relevant maker url in the perl script

Unfortunately, the script is not working for me. I do not have SmartThings and wondering if the script would work without that.

I have a Asus RTN66U with the Merlin firmware. I enabled JFFS and copied the file CheckIfHome in the /jffs/scripts folder with chmod 777 with the correct MAC addresses (see http://pastebin.com/mwgRkmd2). I was hoping that the script should run and trigger the Maker requests depending on the Wifi Presence. I do not have ST to use the Virtual Presence Sensor Device.

Would appreciate any advice…thanks!