Controlling occupancy from your router (Open firmware: Tomato/DD-WRT/OpenWRT)

Did you add the execute command to the services-start script? By default, there is no “services-start” file in /jffs/scripts/ so you’ll have to add it. You should be able to use my example in post # 91.

Yup, made sure both perms are 0755

Sent from my HTC6525LVW using Tapatalk

Troubleshooting:

From Tools → Run Cmd on the router web GUI:

wl -i eth1 assoclist | grep
wl -i eth2 assoclist | grep

You should see “assoclist ” as the response - which proves you are using the right commands.

Next step is to issue the wget from Run Cmd:
wget -qs “http://192.168.x.xx:3480/data_request?id=variableset&DeviceNum=xx&serviceId=urn:dcineco-com:serviceId:MSwitch1&Variable=Status5&Value=1

You should see the switch update in Vera UI.

After that, you’ll need to double-check and comb through your script. One thing I noticed is that you are missing the closing quotes on the VERAURL line…

Also, I don’t understand why you removed the code that set the value to 0 via else and swapped in the MAC1==0 section… that’s your code so you’re on your own there. :slight_smile:

Good luck.

VERSION 2.0

  • heavily modified code to be more self documenting and also account easier for more modifications/features later

quick note: the ASUS routers more recent FW removed the Run Cmd from the GUI. We must use SSH/Telnet.

This code is DIFFERENT than other code posted by other users…
this code enables the script to use a single button for each device, for both Wifi SSIDs/Frequencies - it DOES NOT track the specific radio (2.4 or 5) for each individual device (I may add this feature later as a user definable option).

[code]#!/bin/sh

folder location: /jffs/scripts

file name: services-start

sh /jffs/scripts/VeraOccupancy &[/code]

[code]#!/bin/sh
#set -x # activate debugging when launched from cmd

folder location: /jffs/scripts

file name: VeraOccupancy

version: 2.00

Instructions:

modifying code - search for and replace all XX

when using less than 4 MAC addresses: you must remove code for the other MACs

when adding additional MAC addresses: ensure you understand each section needs to be replicateduplicate

to be added to future versions… User Constants for all variables; Single code Loop to iterate through all MACs

Vera Device & Button reference - place your info here to remind yourself

MAC1 = Device: Occupancy Trigger (246) button 5

MAC2 = Device: Occupancy Trigger (246) button 6

MAC3 = Device: Wifi Tracking (278) button 3

MAC4 = Device: Wifi Tracking (278) button 1

User Constants

MAC_ADDRESS_1=“XX:XX:XX:XX:XX:XX” # HTC
MAC_ADDRESS_2=“XX:XX:XX:XX:XX:XX” # Samsung
MAC_ADDRESS_3=“XX:XX:XX:XX:XX:XX” # WindowsPC
MAC_ADDRESS_4=“XX:XX:XX:XX:XX:XX” # FireTV

VERAURL="“http://XX.XX.XX.XX:3480/data_request?id=variableset&DeviceNum=XXserviceId=urn:dcineco-com:serviceId:MSwitch1&Variable=
VERAURL2=“http://XX.XX.XX.XX:3480/data_request?id=variableset&DeviceNum=XX&serviceId=urn:dcineco-com:serviceId:MSwitch1&Variable=

WATCHDOG_SLEEP_SEC=10
a1_2ghz_last=“0”
a1_5ghz_last=“0”
a2_2ghz_last=“0”
a2_5ghz_last=“0”
a3_2ghz_last=“0”
a3_5ghz_last=“0”
a4_2ghz_last=“0”
a4_5ghz_last=“0”
x=0
y=0

while sleep $WATCHDOG_SLEEP_SEC
do
if [ “$x” == 60 ]; then
# Every 10 minutes or so we do them all again, just in case Vera missed something
x=0
a1_2ghz_last=“0”
a1_5ghz_last=“0”
a2_2ghz_last=“0”
a2_5ghz_last=“0”
a3_2ghz_last=“0”
a3_5ghz_last=“0”
a4_2ghz_last=“0”
a4_5ghz_last=“0”
fi
x=$(( $x + 1 ))

Monitor MAC_ADDRESS_1

2.4ghz band

a1_2ghz_new=wl -i eth1 assoclist | grep $MAC_ADDRESS_1
if [ “$a1_2ghz_new” == “$a1_2ghz_last” ] ; then
sleep 0
else
a1_2ghz_last=“$a1_2ghz_new”
if [ “$a1_2ghz_new” == “assoclist $MAC_ADDRESS_1” ]; then
wget -qs “${VERAURL}StatusXX&Value=1”
fi
fi

5ghz band

a1_5ghz_new=wl -i eth2 assoclist | grep $MAC_ADDRESS_1
if [ “$a1_5ghz_new” == “$a1_5ghz_last” ] ; then
sleep 0
else
a1_5ghz_last=“$a1_5ghz_new”
if [ “$a1_5ghz_new” == “assoclist $MAC_ADDRESS_1” ]; then
wget -qs “${VERAURL}StatusXX&Value=1”
fi
fi

if [ -z “$a1_2ghz_new” ] && [ -z “$a1_5ghz_new” ] ; then
wget -qs “${VERAURL}StatusXX&Value=0”
fi

Monitor MAC_ADDRESS_2

2.4ghz band

a2_2ghz_new=wl -i eth1 assoclist | grep $MAC_ADDRESS_2
if [ “$a2_2ghz_new” == “$a2_2ghz_last” ] ; then
sleep 0
else
a2_2ghz_last=“$a2_2ghz_new”
if [ “$a2_2ghz_new” == “assoclist $MAC_ADDRESS_2” ]; then
wget -qs “${VERAURL}StatusXX&Value=1”
fi
fi

5ghz band

a2_5ghz_new=wl -i eth2 assoclist | grep $MAC_ADDRESS_2
if [ “$a2_5ghz_new” == “$a2_5ghz_last” ] ; then
sleep 0
else
a2_5ghz_last=“$a2_5ghz_new”
if [ “$a2_5ghz_new” == “assoclist $MAC_ADDRESS_2” ]; then
wget -qs “${VERAURL}StatusXX&Value=1”
fi
fi

if [ -z “$a2_2ghz_new” ] && [ -z “$a2_5ghz_new” ] ; then
wget -qs “${VERAURL}StatusXX&Value=0”
fi

Monitor MAC_ADDRESS_3

2.4ghz band

a3_2ghz_new=wl -i eth1 assoclist | grep $MAC_ADDRESS_3
if [ “$a3_2ghz_new” == “$a3_2ghz_last” ] ; then
sleep 0
else
a3_2ghz_last=“$a3_2ghz_new”
if [ “$a3_2ghz_new” == “assoclist $MAC_ADDRESS_3” ]; then
wget -qs “${VERAURL2}StatusXX&Value=1”
fi
fi

5ghz band

a3_5ghz_new=wl -i eth2 assoclist | grep $MAC_ADDRESS_3
if [ “$a3_5ghz_new” == “$a3_5ghz_last” ] ; then
sleep 0
else
a3_5ghz_last=“$a2_5ghz_new”
if [ “$a3_5ghz_new” == “assoclist $MAC_ADDRESS_3” ]; then
wget -qs “${VERAURL2}StatusXX&Value=1”
fi
fi

if [ -z “$a3_2ghz_new” ] && [ -z “$a3_5ghz_new” ] ; then
wget -qs “${VERAURL2}StatusXX&Value=0”
fi

Monitor MAC_ADDRESS_4

2.4ghz band

a4_2ghz_new=wl -i eth1 assoclist | grep $MAC_ADDRESS_4
if [ “$a4_2ghz_new” == “$a4_2ghz_last” ] ; then
sleep 0
else
a4_2ghz_last=“$a4_2ghz_new”
if [ “$a4_2ghz_new” == “assoclist $MAC_ADDRESS_4” ]; then
wget -qs “${VERAURL2}StatusXX&Value=1”
fi
fi

5ghz band

a4_5ghz_new=wl -i eth2 assoclist | grep $MAC_ADDRESS_4
if [ “$a4_5ghz_new” == “$a4_5ghz_last” ] ; then
sleep 0
else
a4_5ghz_last=“$a4_5ghz_new”
if [ “$a4_5ghz_new” == “assoclist $MAC_ADDRESS_4” ]; then
wget -qs “${VERAURL2}StatusXX&Value=1”
fi
fi

if [ -z “$a4_2ghz_new” ] && [ -z “$a4_5ghz_new” ] ; then
wget -qs “${VERAURL2}StatusXX&Value=0”
fi

done[/code]

I’m having trouble getting this to run.
I have a netgear r7000 nighthawk router with ddwrt
I enabled jffs, put the files in the folder as suggested above and set the perms.
I manually ran the wl command and the wget with url command and both worked.
it’s getting the script to run automatically that is my problem i think.
i tried to enable syslog and look at the messages but it didn’t show anything helpful.
any suggestions.?

Make sure you are searching for <> in the entire script… there are areas you need to enter the MSwitch’s Device # AND Variable # (Button #)

I’ve been running my version for 12 hours… been working fine so far. Let me know if you find any issues.

Also, if you want to see the debug output, you can put in the below at the top, make sure it is under the very first line…

set -x			# activate debugging from here

this will enable the output to show on the command line… but only if you open SSH/telnet and launch it from there.

edit: got it working… was a windows / unix formatting issue
my bad :slight_smile:

Script is executing, but seems to be hitting syntax errors. Oddly, seems to be directly related to blank lines. so I suspect you have an issue with what editor you are using - Ensure you use an Linux/Unix friendly editor like Notepad ++, not Windows Notepad.

And make sure you are saving it in UTF and then the permissions are set to be able to execute (X)

[quote=“Aaron, post:108, topic:180260”]Script is executing, but seems to be hitting syntax errors. Oddly, seems to be directly related to blank lines. so I suspect you have an issue with what editor you are using - Ensure you use an Linux/Unix friendly editor like Notepad ++, not Windows Notepad.

And make sure you are saving it in UTF and then the permissions are set to be able to execute (X)[/quote]

yep that is what it was! :slight_smile: thanks!

Just to confirm, does the ‘wl’ report on any wireless devices, even if they are not connected to the DDWRT router network?

It only reports the devices that are connected to the DD-WRT router you are running it on. It will not list devices not connected at that time or connected to another router. Which is why this method works for a Home/Away switch.

Wifi devices broadcast their MAC address even without connecting to a wireless network. There are some commercial applications that use this technology to track anonymous devices. I was hoping I could use this to track devices quicker than having them connect to the network. If you’re relying on them to connect to the DDWRT router, I would think that using the Ping sensor to track presence would be easier.

I found the ping sensor to be slower and have more false triggers. There is alot of things going on in the under powered VERA. Polling and all.
This was a great way to relieve vera a bit vs. running several ping sensors.

Does your phone take to long to connect to your router? If your router could scan or see the mac address why wouldn’t it be connected to the network? Distance is distance.

I can see how in commercial applications they are scanning everyone even people who don’t have access to their network. But in our case you should be tracking devices you already know and have and have your wifi access.

I update my version of the code to v2 here… http://forum.micasaverde.com/index.php/topic,24084.msg208828.html#msg208828

I found the ping sensor to be slower and have more false triggers. There is alot of things going on in the under powered VERA. Polling and all.
This was a great way to relieve vera a bit vs. running several ping sensors.

Does your phone take to long to connect to your router? If your router could scan or see the mac address why wouldn’t it be connected to the network? Distance is distance.

I can see how in commercial applications they are scanning everyone even people who don’t have access to their network. But in our case you should be tracking devices you already know and have and have your wifi access.[/quote]

double Ditto

I found ping unreliable and I tried all sorts of settings and multiple phones. Reliability issues were due to the phones and/or Wifi combos… not the plug-in. For wired computers Ping Sensor works fine.

My solution for phone/Occupancy is to use in combination with code on the router to detect the phones Mac address.
The router tells vera when the phone is home (10 second interval) and to be set as ‘away’ both the ping (2 min interval) and the router must show the phone gone. This seems to be pretty good and survive phone reboots when needed.

I also use Tasker (Network Location, not GPS) with Authomation HD to send home / away triggers based on location detection.

  • I tried using VeraProximity and Auto Location apps, both totally unreliable for me for some unknown reason.

All of these together seems pretty good… Not perfect.

I think the only way to get perfect would be to use bluetooth beacons all around your house /property.

I have one asus router with merlin and one with tomato…

Exactly where do I put in the code on both? Can’t find the right place to paste it.

And how do I testrun the code?

Using the latest multi switch on ui7 I had to change the URL to http://X.X.X.X:3480/data_request?id=lu_action&output_format=xml&DeviceNum=X&serviceId=urn:dcineco-com:serviceId:MSwitch1&action=SetStatus1&newStatus1=0

The second switch would be &action=SetStatus2&newStatus2=0

Rather than using the variableset. Hope it helps, also the last script has two Vera URLs declared one of the has the quotes declared incorrectly.

Hope this helps anyone trying to follow this guide.

Looks like there are a lot of great contributions and improvements!

Sadly, in the spirit of usual MCV forum threads, it looks like it’s pretty tough to digest all this information unless you wanna browse through 8 pages. I’d like to see if I can help out improving the organization of the thread by reposting all the latest updates on the OP. Does anyone have any “must have” updates worth including?

The last post looks particularly helpful. I’ll start by adding that. Thanks @AskewPiste!

Ditto here. After the last update I had to update the calls as the wget job was hanging and making the script not work . But only for the one to my UI7 Vera. Not the same job that goes to my UI5 Vera. After updating the script with the new calls the hangs disappeared.

any issues with Aaron’s updated script? i plan on tackling this over the weekend. thx

I have switched out the wireless to Ubiquity Unifi Ap’s inside and outside the house. I think I thrown most if not everything in this thread out.

Any ideas?

How about back to pinging an IP useing this script vs. several PING sensor plugins in vera?

I see 2.0 was posted but is that only for a certain processor/router and I don’t see ping local machines in that script?