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!
So I found the answer to my 3rd question (how to use ARP) - itâs just as fast for detecting when I come ON the network, but slower to detect leaving the network. (takes up to 2 minutes, depending on where I hit the ARP refresh TTL, is what I am thinking, and that is configurable, but not sure I want the âextrasâ that come with changing that (i.e. more broadcast traffic)) But, coming home & things happening then is the most important to me, so I think I can live with the leaving delay. Here is what I ended up using (note that you have to convert the MAC addresses to all lower case for the fgrep as ARP puts them out in lower and fgrep is case sensitive)
Me=Away
macaddress() { arp; }
if (macaddress | fgrep â38:xx:xx:b5:x2:d3â >/dev/null)
then
Me=Home
fi
if [ â$Meâ = Home ]
then
if [ ! -f /tmp/CheckUser/_MeHome ]
then
touch /tmp/CheckUser/_MeHome
curl âhttps://graph-na04-useast2.api.smartthings.com/api/smartapps/installations/ACCESSKEY/Phone/home?access_token=ACCESSTOKENâ -k
fi
else
if [ -f /tmp/CheckUser/_MeHome ]
then
rm -f /tmp/CheckUser/_MeHome
curl "https://graph-na04-useast2.api.smartthings.com/api/smartapps/installations/ACCESSKEY/Phone/away?access_token=ACCESSTOKEN -k
fi
fi
Anyway - I hope that helps someone else - so far, it seems to be doing well.
Still interested to see if there is a better way!
I added an access point and did exactly the same - swapped wl for arp and had exactly the same experience; it detects just as fast, but waits another minute or so before things fall off the network. Not a problem, but matches your experience
Look at the second post by âwompahâ - link. Iâve been using this code and its been great. The monitordevices.cfg file stores all your MAC IDs to be tracked together with its statuses. Just replace the mosquitto_pub with your curl.
anyone enable AIMesh on their AsusWRT routers? I did and now when my phone connects to the node (not the main router with the presence script) it doesnt show presence. Any fix to this?
So this ARP setup ideal for me because my Asus AC3100 supports neither wl or qcsapi_sockrpc for client lookup (it has some different wifi chipset)
Thanks for this.
One problem however. The if statements donât run for me, for some reason (I tested by putting in an echo âtestâ within them).
I have confirmed that âarpâ on my router outputs a matching MAC address in lowercase.
I believe the issue is with this line:
macaddress() { arp; }
I donât think it is storing it into the variable macaddress.
echo â$macaddressâ does not print anything
EDIT: O.M.G. Such a stupid thing. I fixed it.
if (macaddress | fgrep â38:xx:xx:b5:x2:d3â >/dev/null)
no double quotes on the MAC address. must be single quotes. at least on my AC3100 for whatever reason, Iâm not sure why rrands1 version and everyone elseâs seems to work fine.
Iâm having the exact same problem. Ever since I enabled AIMesh on Merlin firmware 384.13, Iâve been having the same issue as you. Every time my cell connects to the node, my presence changes to Not Present.
I think thereâs a way to execute jffs script if you connect it to a USB stick on the node. I just need to look more into it.
If worse comes to worse, I may have to just use my T-Mobile AC1900 converted AC68U as a repeater and hope Wifi Presence works better. Iâll post here if I find out anything useful and let ya know. Please do the same if you get anywhere with this.
Hey there, were you ever able to figure this out? I stopped using AiMesh after I couldnt figure it out but since I moved into a larger place, I need to utilize AiMesh to get better coverage around my place and would like to have this fixed.
I dipped my toes into Home Assistant and they have direct integration with Asus Routers for presence detections - Ill have to try it out more to see how it runs with AiMesh
@ranova I did read somewhere how to fix this issue. I havenât had time to try it out for a long time due to other things taking up my time. Now that you brought back to my attention, Iâll take another try at it again soon and let you know.
If you want to try it out yourself, you need to execute the jffs script via a USB stick on the node. I unfortunately forgot where I read about this but hopefully Iâll be able to find it again. Let me know if you have any luck.
I found something similar for a reboot script on the node:
It seems that more recent firmware updates to AsusWRT has disabled auto launching scripts at boot to prevent malware, so the USB mounting trick is a work around. Thats bizarre since my main AsusWRT router still auto launches my Wifi presence script on boot.
Iâll have to try the USB workaround but Im not sure if it will actually work since when I try to manually run the script in SSH, it doesnât update the presence at all