Please do upload to GIT. I’m currently using the ST presence sensor from within the app, but that means I have to load ST & authorize everyones phone access to the house. Doing it this way, I can give the cleaning service limited WiFi access but still know their presence.
Thanks Stuart & @itcsburnett - I’ve never used Github before so here goes
Feedback is welcome … its my first python script too so any help is appreciated.
James
Thanks, now i want to see if i can run that on my android emulator rather than spinning up another Pi
All looks good… Before you know it you will have loads of repos on GitHub and lots of custom integrations done.
Im a little lost, so others may be as well.
in the code we need provide details on the devices that will connect to Wifi and thus be deemed present.
[“Name”,“AppID”,“AccessToken”,“IP_Addr”,“Present”],
Name: I presume can be whatever user wants
AppID: ?
AccessToken: ?
Present: is default?
This script is intended to work with the ASUSWRT Wifi Presence SmartApp and DTH … once you’ve gone through the direction to install those, you will see the AppID and AccessTokens … the IP_Addr is the IP of the phone you are interested in tracking. The Name is any name you want to call it (not really needed but helps keeping track of who’s who) The Present is a flag used to store the current state. This script replaces the Code that Stuart provided that runs on the WRT and is intended to run on a Raspberry (or similar).
Hope that helps.
I’m going to post this as a new thread …
Thank you for your post. I think I managed to follow the direction and:
- Published Device Handler by fuzzy logic
- Added Device using the Device Handler
- Published SmartApp by fuzzy logic with OAuth enabled
- Added SmartApp via SmartThings Classic Mobile App
But I went into issue while testing.
I ran the following command:
curl “https://graph.api.smartthings.com/api/smartapps/installations/my_app_id/Phone/away?access_token=my_access_token” -k
But I get back
{“error”:true,“type”:“AccessDenied”,“message”:“This request is not authorized by the specified access token”}
I am certain that the access_token is correct as modifying the token results in invalid_token error.
So that means the URI is not right. What am I missing?
When you log into the IDE what URL is shown at the top? Just swap the graph.api.smartthings.com with that URL for your shard and it should work
Looks like that fixes it! I have https://graph-na04-useast2.api.smartthings.com and using that URL works for me. I’m not sure why SmartThings force us into regions as I bet their will be na03, na05, uswest1, eventually.
There is lots of different shards. That is simply how smartthings scale thier platform using multiple shards.
BTW, the Presence works great with the Classic App. With the New App, the presence status on dashboard is always shown as “Checking for status…”. If I click on it, it will say the correct state (arrived/departed) Is it just me?
one comment to the CheckIfHome script. I think instead of checking mac addresses from individual interfaces, why not just get from the output of “arp -a”? I realized that my Guest WiFi is listed under wl0.1 instead of eth0.
You can, others have done so in this thread. But getting from the interfaces directly is immediate arp is not
iPHONE USERS! This is for you
My youngest swapped his Android for an iPhone, and immediately I started getting offline notifications from ST based on this script. It was also triggering SHM and turning all the lights off when he was at home alone!
I tried all the settings on the phone - no joy, but then found that iPhones do indeed ask to turn off the connection when locked, and the Asus router accepts or rejects this request based on the setting WWM APSD which is located in Wireless -> Professional on the router settings page.
Remember there’s one for 2.4GHz, and a separate page for 5GHz.
Turning this OFF instantly stopped his phone disconnecting when sleeping, went from 20-30 disconnects per night to zero.
@Fuzzyligic
Thank you very much for your efforts.
It tried to follow your instructions but with no luck getting this working for me.
I have repeated this many times and still not working
Can you check this for me please?
#!/bin/sh
if [ ! -d /tmp/CheckUser ]
then
mkdir /tmp/CheckUser
fi
Stuart=Away
macadresser=wl -i eth1 assoclist
antal=0
antal=qcsapi_sockrpc get_count_assoc wifi0
while [ $antal -gt 0 ]
do
antal=expr $antal - 1
macadresser="qcsapi_sockrpc get_station_mac_addr wifi0 $antal
;$macadresser"
done
case “$macadresser” in
24:18:XX:XX:XX:66)
Stuart=Home
;;
esac
if [ “$Stuart” = Home ]
then
if [ ! -f /tmp/CheckUser/StuartHome ]
then
touch /tmp/CheckUser/StuartHome
curl “https://graph-eu01-euwest1.api.smartthings.com/api/smartapps/installations/1234e5a6-789c-00xx-abcd-26d6fef704dd/Phone/home?access_token=a12ac34b-5cca-67a8-a99f-e00a12345c12” -k
fi
else
if [ -f /tmp/CheckUser/StuartHome ]
then
rm -f /tmp/CheckUser/StuartHome
curl “https://graph-eu01-euwest1.api.smartthings.com/api/smartapps/installations/1234e5a6-789c-00xx-abcd-26d6fef704dd/Phone/away?access_token=a12ac34b-5cca-67a8-a99f-e00a12345c12” -k
fi
fi
Note: fake access token & app id
What’s not working? Dues the file get created in the temp folder when the phone connects? And gets deleted when it disconnects?
If not check the Mac address is correct.
Or is the issue that it won’t turn on and off the virtual sensor in smartthings. If not make sure you have the correct shard. I.e make sure you are using the same region URL in your script that is shown in the IDE when you log in.
Hi @Fuzzyligic
Thank you so much for you quick reply.
My phone doesn’t seem able to connect!
- Once i use ls -als /jffs/scripts/CheckUser you can see that no phone is connected (please see screenshot in my previous post) also I switch wifi in my mobile on/off and same results. I check Check Users and no files is created!
- One more thing, once i run cu l command there is extra line (please see screenshot in my previous post) starts with /5*** service_Letsencrypt #LetsEncrypt
Not sure what it is? - My URL is correct https://graph-eu01-euwest1.api.smartthings.com/ as you can see in my previous post in CheckIfHome file
- I have installed you DH and Smart App following instrucyion and then installed from Mobile app but I am not clear on virtual sensor in smartthings, how to see the virtual sensor in smartthings is turning On/Off ? once i install the app from mobile, i cants see the virtual sensor under devices?
Smartapp & DH in IDE
Thanks again for great help
Hi @pillock, hope this finds you well. Did you notice any side effect on turning off this option other than preventing iphones from sleeping the connection? Higher battery usage or something else?
Thanks
Marcelo
So I have had this up and working for some time now, and it has been solid. I am adding a new Access Point (AP) to the network though, and that introduces some challenges. I have read all of these posts, but still am not finding what I am after. My script looks like this:
macaddress() { wl -i eth2 assoclist && wl -i eth1 assoclist; }
if (macaddress | fgrep “XX:XX:XX:XX:XX:XX” >/dev/null)
then
Me=Home
fi
My first question is: outside of running something off-router, does anyone have presence working using your main Asus router, an AP and this method, and if so, how (exactly) are you accomplishing that? There were some references to something along the lines of “I tried Joe’s method, slightly modified, and it works for me”, but nothing I could find specific as a “this works” solution. (this could be me - 300 posts is a lot of reading…
My second question would be: Is there an issue running the above script on both the Main Router (referred to now as MR) & also the AP? If I am understanding the script correctly, every execution of it (both on the MR & also the AP) does a check & either adds or deletes the status file & calls the curl script to update status. I could see this causing an issue if the MR runs & says “away” and calls curl, but then AP runs and says “home” & calls curl. This may lead to flap (again, if I am understanding the execution correctly).
The issue with the current script is that the WL command does not list the devices connected to the AP, so they all list as “Away” when they are connected to the AP, but are in fact present on the network.
It looks like the ARP command may work to list all devices visible on the network, but I need to change my lines for Command() and also the fgrep. Particularly, I need to have fgrep look for the MAC address. I am not sure what format to use to pull out the mac being on that line. One thing to note is that the ARP table seems to be slower to update than the original method using WL, so I am not sure if it is going to be as quick, but wanted to explore the option.
My question here is mainly : Are there any linux scripting gurus that can help me re-format the above lines to incorporate the ARP command instead of WL, and also the fgrep line to filter out based on whether the MAC is there, please?
Thank you so much for your help - I appreciate it, and look forward to hearing what works for you all!