Awesome great, catch. I know about the case sensitivity, but did not catch the lower case MAC.
So should this logic basically work
What am I missing?
macaddress=“arp -an”
case “$macaddress” in 90:b0:ed:12:34:56) <-- There are asterix here, but it does not show up for some reason on here.
Paul=Home
;;
esac
Just to clarify. If I manually enter:
macaddress="arp -an"
then type $macaddress
I get a list of all attached devices as expected
I can see the MAC address 90:b0:ed:12:34:56 in that list as well as other info.
but, the variable Paul never gets set to home.
I will say that ARP does seem to be a bit slower for me than the wl commands, maybe taking 20-30 seconds to update after its disconnected.
Maybe
case “$macaddress” in
"90:b0:ed:12:34:56")
Paul=Home
;;
esac
FWIW on AC86-U I use the following for all associations:
macadresser="wl -i eth1 assoclistwl -i eth2 assoclistwl -i wl0.1 assoclist"
Basically I tried all interfaces listed in ifconfig -a and these 3 work.
One setup as a wireless router and the other in Access Point (AP) mode. Do I need to setup both routers or just the main one that’s setup as the wireless router
Just jumping in to agree and add some details. I have the same setup. Have to create a virtual presence sensor for the Router AND the AP. I just use them together in my routines. It has worked well for me. Only issues I’ve had I believe are with Smartthings. Like the other day, it just stopped reporting me as present. The router was reporting me as present, but Smartthings was not updating correctly. My phone itself also was reporting me as present. After a few hours, it started working again.
Hey I know its been a while, but was wondering if you would be willing to share your router script that uses ARP vs wl. I’ve been working pretty good using two virtual presence sensors for each phone, but would love to just have one. I feel like I’m missing something very simple when it comes to the ARP command.
OK, it took me a while to figure out the using arp vs wl. But I figured it out. Here’s what I’ve noticed. It pretty quick for a user to show as HOME, but it takes longer to Show as away. Not that much longer, but maybe 30-40 seconds before a user gets removed from the arp table. I don’t feel like that is really an issue at all. I care much more about the users showing up as quickly as possible. Thanks for putting this together in the first place. Its been fun figuring it out. I am currently using this on my main router in a network with a router and an AP both running Merlin. So far its been working great. I’ll report back any issues:
#!/bin/sh
User1=Away
User2=Away
User3=Away
User4=Away
if (arp -an | fgrep "xx:xx:xx:xx:xx:xx" >/dev/null)
then
User1="Home"
fi
if (arp -an | fgrep "xx:xx:xx:xx:xx:xx" >/dev/null)
then
User2="Home"
fi
if (arp -an | fgrep "xx:xx:xx:xx:xx:xx" >/dev/null)
then
User3="Home"
fi
if (arp -an | fgrep "xx:xx:xx:xx:xx:xx" >/dev/null)
then
User4="Home"
fi
if [ "$User1" = Home ]
then
if [ ! -f /jffs/scripts/users/User1 ]
then
touch /jffs/scripts/users/User1
curl -H "Authorization: Bearer <Access Token>" -X POST "https://graph.api.smartthings.com/api/smartapps/installations/<AppID>/home"
fi
else
if [ -f /jffs/scripts/users/User1 ]
then
rm -f /jffs/scripts/users/User1
curl -H "Authorization: Bearer <Access Token>" -X POST "https://graph.api.smartthings.com/api/smartapps/installations/<AppID>/away"
fi
fi
if [ "$User2" = Home ]
then
if [ ! -f /jffs/scripts/users/User2 ]
then
touch /jffs/scripts/users/User2
curl -H "Authorization: Bearer <Access Token>" -X POST "https://graph.api.smartthings.com/api/smartapps/installations/<AppID>/home"
fi
else
if [ -f /jffs/scripts/users/User2 ]
then
rm -f /jffs/scripts/users/User2
curl -H "Authorization: Bearer <Access Token>" -X POST "https://graph.api.smartthings.com/api/smartapps/installations/<AppID>/away"
fi
fi
if [ "$User3" = Home ]
then
if [ ! -f /jffs/scripts/users/User3 ]
then
touch /jffs/scripts/users/User3
curl -H "Authorization: Bearer <Access Token>" -X POST "https://graph.api.smartthings.com/api/smartapps/installations/<AppID>/home"
fi
else
if [ -f /jffs/scripts/users/User3 ]
then
rm -f /jffs/scripts/users/User3
curl -H "Authorization: Bearer <Access Token>" -X POST "https://graph.api.smartthings.com/api/smartapps/installations/<AppID>/away"
fi
fi
if [ "$User4" = Home ]
then
if [ ! -f /jffs/scripts/users/User4 ]
then
touch /jffs/scripts/users/User4
curl -H "Authorization: Bearer <Access Token>" -X POST "https://graph.api.smartthings.com/api/smartapps/installations/<AppID>/home"
fi
else
if [ -f /jffs/scripts/users/User4 ]
then
rm -f /jffs/scripts/users/User4
curl -H "Authorization: Bearer <Access Token>" -X POST "https://graph.api.smartthings.com/api/smartapps/installations/<AppID>/away"
fi
fi
I just tweaked @Fuzzyligic’s presence script to work with my wifi- extender and it is working well for last couple of weeks, so thought of posting modified script, I use TP-Link Wireless Extender
I had a bit of a hiccup with arp tonight, probably not a script issue, probably smartthings or the device, but caused me to come here and look at your script. Can you explain what it does? Even after disconnecting from wifi for 10 minutes my mac still shows up in dnsmasq.leases. Seems like it would take a while for it to show you as not present?
@ptdalen dnsmasq.leases will hold the MAC until the lease time is expired. Script is using dnsmasq only to get the previously assigned IP address for the device, when the device’s MAC is not seen in macadresser list. It pings the device IP from dnsmasq for 3 packets and if it gets a response back it marks it as you are home else away.It changes the mode almost instantaneously when the script is run. If you have multiple devices to check then use OR condition here
if [ “$Kiran” != Home || “$anotherdevice” != Home ]
then
cat /tmp/var/lib/misc/dnsmasq.leases > dnsmasq.txt
fi
and add check section
if [ “”$anotherdevice" != Home ]
then
val=$(awk ‘{if ($2 == “4c:xx:XX:xx:xx:-anotherdevice MAC”) system("ping -c 3 " $3 )}’ dnsmasq.txt | awk ‘BEGIN {FS="[=]|[ ]"} NR==2 { print $10}’)
if [ $val ]
then
Anotherdevice =Home
fi
fi
This will set if you are connected via extended device.
Thanks, seems interesting, and I’ve enjoyed trying different ways to get this working. Arp has been pretty good, but just seems to occasionally lose connection. Can you edit your initial post and use a [ code ] [ /code ] around the code. I think that maybe some items were stripped out. Here is what I have right now, and its not working. I’m sure its missing a single or double quote somewhere
#!/bin/sh
PersonOne=Away
PersonTwo=Away
PersonThree=Away
PersonFour=Away
macadresser="'wl -i eth1 assoclist' && 'wl -i eth2 assoclist'"
case "$macadresser" in
XX:XX:XX:XX:XX:XX)
PersonOne=Home
;;
esac
case "$macadresser" in
XX:XX:XX:XX:XX:XX)
PersonTwo=Home
;;
esac
case "$macadresser" in
XX:XX:XX:XX:XX:XX)
PersonThree=Home
;;
esac
case "$macadresser" in
XX:XX:XX:XX:XX:XX)
PersonFour=Home
;;
esac
if [ "$PersonOne" != Home || "$PersonTwo" != Home || "$PersonThree" != Home || "$PersonFour" != Home ]
then
cat /tmp/var/lib/misc/dnsmasq.leases > dnsmasq.txt
fi
if [ "$PersonOne" != Home ]
then
val=$(awk '{if ($2 == "xx:xx::xx:xx:xx") system("ping -c 3 " $3 )}' dnsmasq.txt | awk 'BEGIN {FS="[=]|[ ]"} NR==2 { print $10}')
if [ $val ]
then
PersonOne=Home
fi
fi
if [ "$PersonTwo" != Home ]
then
val=$(awk '{if ($2 == "xx:xx:xx:xx:xx") system("ping -c 3 " $3 )}' dnsmasq.txt | awk 'BEGIN {FS="[=]|[ ]"} NR==2 { print $10}')
if [ $val ]
then
PersonTwo=Home
fi
fi
if [ "$PersonThree" != Home ]
then
val=$(awk '{if ($2 == "xx:xx:xx:xx:xx") system("ping -c 3 " $3 )}' dnsmasq.txt | awk 'BEGIN {FS="[=]|[ ]"} NR==2 { print $10}')
if [ $val ]
then
PersonThree=Home
fi
fi
if [ "$PersonFour" != Home ]
then
val=$(awk '{if ($2 == "xx:xx:xx:xx:xx") system("ping -c 3 " $3 )}' dnsmasq.txt | awk 'BEGIN {FS="[=]|[ ]"} NR==2 { print $10}')
if [ $val ]
then
PersonFour=Home
fi
fi
if [ "$PersonOne" = Home ]
then
if [ ! -f /jffs/scripts/users/PersonOne ]
then
touch /jffs/scripts/users/PersonOne
curl -H "Authorization: Bearer <Access Token>" -X POST "https://graph.api.smartthings.com/api/smartapps/installations/<AppID>/home"
fi
else
if [ -f /jffs/scripts/users/PersonOne ]
then
rm -f /jffs/scripts/users/PersonOne
curl -H "Authorization: Bearer <Access Token>" -X POST "https://graph.api.smartthings.com/api/smartapps/installations/<AppID>/away"
fi
fi
if [ "$PersonTwo" = Home ]
then
if [ ! -f /jffs/scripts/users/PersonTwo ]
then
touch /jffs/scripts/users/PersonTwo
curl -H "Authorization: Bearer <Access Token>" -X POST "https://graph.api.smartthings.com/api/smartapps/installations/<AppID>/home"
fi
else
if [ -f /jffs/scripts/users/PersonTwo ]
then
rm -f /jffs/scripts/users/PersonTwo
curl -H "Authorization: Bearer <Access Token>" -X POST "https://graph.api.smartthings.com/api/smartapps/installations/<AppID>/away"
fi
fi
if [ "$PersonThree" = Home ]
then
if [ ! -f /jffs/scripts/users/PersonThree ]
then
touch /jffs/scripts/users/PersonThree
curl -H "Authorization: Bearer <Access Token>" -X POST "https://graph.api.smartthings.com/api/smartapps/installations/<AppID>/home"
fi
else
if [ -f /jffs/scripts/users/PersonThree ]
then
rm -f /jffs/scripts/users/PersonThree
curl -H "Authorization: Bearer <Access Token>" -X POST "https://graph.api.smartthings.com/api/smartapps/installations/<AppID>/away"
fi
fi
if [ "$PersonFour" = Home ]
then
if [ ! -f /jffs/scripts/users/PersonFour ]
then
touch /jffs/scripts/users/PersonFour
curl -H "Authorization: Bearer <Access Token>" -X POST "https://graph.api.smartthings.com/api/smartapps/installations/<AppID>/home"
fi
else
if [ -f /jffs/scripts/users/PersonFour ]
then
rm -f /jffs/scripts/users/PersonFour
curl -H "Authorization: Bearer <Access Token>" -X POST "https://graph.api.smartthings.com/api/smartapps/installations/<AppID>/away"
fi
fi
You had this in your code, one Square bracket for all conditions
if [ “$PersonOne” != Home || “$PersonTwo” != Home || “$PersonThree” != Home || “$PersonFour” != Home ]
I have closed the square brackets for each condition, quotes are not required around the if statement
if [ “$PersonOne” != Home ] || ["$PersonTwo" != Home] || ["$PersonThree" != Home] || ["$PersonFour" != Home ]
Can you also verify that this has the correct Quotes, I just know that the posts on here strip out certain things when [ code ] Is not used, so I think that may be it
Lastly, I noticed than when I ran the script that the “dnsmasq.txt” file never got created, so that’s probably something I need to figure out 1st. Hopefully the new brackets will take care of that.
I was also curious if you were using iPhone or android. Don’t think it would make any difference, but I’ve seen a few things about phones going into power save and not responding to a ping?
Ok, got the [: missing] figured out. Just needed spaces. Now it runs without error, dns file is created, but user file not being created, Will need to check the awk I guess