Jump to content

Detect when you arrive home without hacking your router


502ss

Recommended Posts

Posted

I wrote this program a while ago but kept forgetting to post it. Another member sent me a PM asking about it so I figured no better time than the present! :) This has been running for over a year and has worked 100% of the time! :)

 

Basically all you need for this to work is a raspberry pi (or some other device that can run bash, curl, etc) and the ability to assign a static IP to your mobile device(s).

 

How it works:

 

I have a variable on the ISY that changes from "140" to "150" when I cross a Geo fence and are within 5-8 minutes from home.

 

The program is running through a loop constantly looking for the variable to be "150", if it's anything other than "150" the program does nothing, sleeps for 10 seconds and runs again.

 

Once the program detects that the variable has changed to "150" it starts performing an arp-scan looking for the static IP of my mobile to show up on the WIFI. If it doesn't find it it breaks out of the loop, sleeps for 10 seconds and tries again.

 

Once it finds the IP on the WIFI. It changes another variable on the ISY. This change of the variable in my environment triggers a morning industry door lock to unlock.

 

The program then sleeps for 60 seconds and sets the variable back to "140" so the whole process could start over again.

 

I whipped this script up really quick and could have made it cleaner by using variables to define ISY IP, username, password, etc. but I didn't :) feel free to modify as needed!

 

Let me know if you have any questions.

#!/bin/bash
while :
do
        curl -s http://isy_uname:isy_password@isy_ip:isy_port/rest/vars/get/1/19 | grep 150  > /dev/null
        if [ $? -eq 0 ]
                then
                        #echo "found 150"
                        while :
                        do
                                #echo "running arp command"
                                sudo arp-scan <phone_ip> | grep <phone_ip> > /dev/null
                                        if [ $? -eq 0 ]
                                                then
                                                        curl -s http://isy_uname:isy_password@isy_ip:isy_port/rest/vars/set/2/10/1 > /dev/null
                                                        sleep 30
                                                        curl -s http://isy_uname:isy_password@isy_ip:isy_port/rest/vars/set/2/10/0 > /dev/null
                                                        break
                                        fi
                                sudo arp-scan <phone2_ip> | grep <phone2_ip> > /dev/null
                                        if [ $? -eq 0 ]
                                                then
                                                        curl -s http://isy_uname:isy_password@isy_ip:isy_port/rest/vars/set/2/10/1 > /dev/null
                                                        sleep 30
                                                        curl -s http://isy_uname:isy_password@isy_ip:isy_port/rest/vars/set/2/10/0 > /dev/null
                                                        break
                                        fi
                        done
                        sleep 60
                        curl -s http://isy_uname:isy_password@isy_ip:isy_port/rest/vars/set/1/19/140 > /dev/null
                else
                        #echo "found something else"
                        sleep 10
                fi
done 
Posted (edited)

In use an iBeacon and ML to write to an ISY variable when I enter/exit a Geofence. The downside is it is only updated once on crossing, not continuously.

Edited by elvisimprsntr
Posted

So, I know a lot of folks are resistant to using IFTTT because of the lag, but I've accomplished the same thing using my phone and tracking its connection to my router.

 

There is a recipe on IFTTT that tracks a specific devices connection status to your home router (onhub specific). When my phone disconnects it sets a home/away variable to 1 and sets my home in away mode. Once My phone connects, which happens once I enter my street, it triggers the variable to 0, which sets my home to home mode. The trigger is pretty instant, and I haven't really noticed a lag at all.

 

I combine the set up above with an automatic pro for redundancy. When I turn off my car at my house it triggers a variable to set my home to home. When I start my car at home it sets my home to away.

 

This way I can be home but away from the house walking the dog and my house doesn't go crazy and lock doors or make it difficult to get back inside if it starts raining.

Posted (edited)

There is a recipe on IFTTT that tracks a specific devices connection status to your home router (onhub specific). When my phone disconnects it sets a home/away variable to 1 and sets my home in away mode. Once My phone connects, which happens once I enter my street, it triggers the variable to 0, which sets my home to home mode. The trigger is pretty instant, and I haven't really noticed a lag at all.

 

This works fine for setting $Home=1 when I arrive at home, but IFTTT falsely detects a disconnect randomly in the middle of the night, ( Due to Android turning WiFI off when charging is complete and phone is asleep).   

 

I could disable the feature in Android, at the expense of much higher battery usage, shorter battery life.

Edited by KeviNH
Posted (edited)

I wrote this program a while ago but kept forgetting to post it. Another member sent me a PM asking about it so I figured no better time than the present! :) This has been running for over a year and has worked 100% of the time! :)

 

Basically all you need for this to work is a raspberry pi (or some other device that can run bash, curl, etc) and the ability to assign a static IP to your mobile device(s).

 

How it works:

 

I have a variable on the ISY that changes from "140" to "150" when I cross a Geo fence and are within 5-8 minutes from home.

 

The program is running through a loop constantly looking for the variable to be "150", if it's anything other

 

《snippage》[/code]

Maybe you don't know about event triggered programming style.

 

No looping is required. Just put a simple variable =150 in the if section and Then will run every and any time the value changes to 150.

 

Of course you need to use a STATE variable to make it trigger programs auto magically. :)

 

Sent from a tiny keyboard. Response may be brief.

Edited by larryllix
Posted

Maybe you don't know about event triggered programming style.

 

No looping is required. Just put a simple variable =150 in the if section and Then will run every and any time the value changes to 150.

Of course you need to use a STATE variable to make it trigger programs auto magically. :)

Pretty sure OP is saying the BASH script is constantly looping -- 'bash' on rPi is not event triggered.

 

He could enable a network service on rPi and have ISY make a network resource call out to the Pi when the event is triggered, but that requires considerably more advanced skills to build.

Posted (edited)

Pretty sure OP is saying the BASH script is constantly looping -- 'bash' on rPi is not event triggered.

 

He could enable a network service on rPi and have ISY make a network resource call out to the Pi when the event is triggered, but that requires considerably more advanced skills to build.

Yeah, I think you are right.

 

The looping comment is right after the ISY comments so I probably misunderstood it's association.

 

Thanks.

 

Sent from a tiny keyboard. Response may be brief.

 

I can't read the scrambled script on my android Tapatalk, right now, but will definitely be looking at this when I get back to a decent browser.

Edited by larryllix
Posted

Larryllix, I don't think you understand his method exactly, then again it wasn't described very clearly. Here's what I get from the description.

 

There's a Geofence program on his phone that will set a variable from 140 to 150 on the ISY when he's 5 - 8 minutes out.

 

There's program running on a Pi that is looping every 10 seconds, looking for that variable to be changed to 150.

When the Pi program sees the value of 150, it starts looping, looking for the phone's IP address to show up in his Pi device list?

It would appear that if the phone is not found in the device list that he sleeps for 60 secs and starts over.

 

When the phone is found in the Pi device list, a different variable is updated, which triggers the ISY to run his "arrive" programs and the original variable is set back to 140.

 

So it appears to be using a combination of GeoFence 5 - 8 mins out and then waiting until his Pi sees the phone before telling ISY he's home.

There's no looping on the ISY, that's done on the Pi.

 

Not sure why the two stage check, surely the Pi could just keep looking for the phone to appear in it's device list without the need for a GeoFence on the phone.

Posted

I use Tasker (Android) to update a state variable in ISY. Tasker has geofence but I primarily use "wifi near" so you don't even have to be connected just near it. You can also combine them so that if one or the other has an error it has a redundant check. It's not instant though.

 

Ifttt has geofencing that seems to work fine too.

 

I like your arp scan, I'll have to play with that some more. In the past only problem I found with that was some phones don't connect until screen is on. I do use a similar mac address scan to notify me what guest is at my house since you can pull the mac address from your router of previously connected devices.

 

I also just set up a Bluetooth scan on my Raspberry Pi that checks every 15 seconds for your bt mac address (doesn't have to be connected, can be phone or the mac address of your actual cars bt, etc). I use that to recognize when I arrive home to open the garage or unlock the front door.

 

Sent from my SM-N930V using Tapatalk

Posted

Larryllix I thought the same thing first read through. As far as the script on the Pi I suppose you could have the ISY tell the script to start when the variable changes to 150 also. But like andyf0 said could just let it run all the time too. All kinds of ways to do it.

 

Sent from my SM-N930V using Tapatalk

Posted

Hey guys/gals..

 

 I'm just wondering what benefit does this has over just using geofence itself to trigger the OP ultimate action to unlock the door upon entering the range?

 

 Don't currently use raspberry pi or very familiar with it so thinking if it provides more functionality (I'm sure it does but just not sure of all the possibilities) then maybe it's time to look further into that setup in parallel. 

Posted

sorry for the confusion, let me try to answer some of the questions/comments and make things a bit clearer.

 

1) I guess I made some assumptions in my original post that the folks reading this thread would understand that when I posted bash code that any reference to a "program" was referring to the bash prog am and not an ISY program. My apologies.

 

2) the reason I am not using JS and restful on the pi to listen for the ISY to tell me when the variable changes was for simplicity. I have this functionality running on another pi to control the lowering of a motorized TV based on a command from the ISY and it works cool but I know some people on here are looking for simple integration and a simple looping bash program achieves that.

 

3) the reason for using geo fence and the bash script is really for two reasons.

a) I don't want the door unlocking before I am physically in the yard (even if it's only 5-8 minutes)

B) I have other events that are triggered off me physically arriving home which I also do not want to trigger prematurely (disabling camera recording, etc.)

 

4) I chose to use the variable from the ISY to trigger the arp-scans strictly because thats the way I wanted to do it. There are probably a dozen ways to achieve the same functionality. This is the way "I" chose to provide the functionality.

 

Hopefully this clears thing up? Let me know if you have any other questions.

 

Thanks

Jim

Posted

Hey Jim..

 

 Sorry.. I'm still a little new to the advanced automation features of the ISY and other integrated options out there... Since the Echo Voice integration it really changed things for me. I have had basics for years not realizing what was in front of me. To be honest I was not even aware of the geofence option until your thread. Been on here lately just trying to learn and topics such as yours are opening a whole new world to me. 

 

 So my question was more simple as I started to make some basic ISY programs with the geofence and seeing that you could adjust your range to pretty much your immediate location, I was just wondering what I was missing. I am intrigued by yours and everyones ability here absorbing all the great info shared. It truly is fascinating the knowledge and creative thinking here and what is shared. Very cool. I am now looking into raspberry pi.. you may have created a monster :) ..

 

Thank you for sharing.. 

 

Best,

Stan

Posted

Hey Jim..

 

 Sorry.. I'm still a little new to the advanced automation features of the ISY and other integrated options out there... Since the Echo Voice integration it really changed things for me. I have had basics for years not realizing what was in front of me. To be honest I was not even aware of the geofence option until your thread. Been on here lately just trying to learn and topics such as yours are opening a whole new world to me. 

 

 So my question was more simple as I started to make some basic ISY programs with the geofence and seeing that you could adjust your range to pretty much your immediate location, I was just wondering what I was missing. I am intrigued by yours and everyones ability here absorbing all the great info shared. It truly is fascinating the knowledge and creative thinking here and what is shared. Very cool. I am now looking into raspberry pi.. you may have created a monster :) ..

 

Thank you for sharing.. 

 

Best,

Stan

Stan - No need to apologize. I think almost everyone of us here is here to learn! My suggestion would be spend the money and get a pi! They really are quite powerful. If you can learn some basic bash programming (and bash is pretty easy to learn with tons of examples on the internet) then it really becomes a device that can compliment the ISY. I do suggest though that you keep it pretty much behind your router. If you start making some of the pi services public facing (like a public facing web server, etc.) then I would suggest you think about hardening the pi.

 

Thanks

Jim

Posted

Stan - No need to apologize. I think almost everyone of us here is here to learn! My suggestion would be spend the money and get a pi! They really are quite powerful. If you can learn some basic bash programming (and bash is pretty easy to learn with tons of examples on the internet) then it really becomes a device that can compliment the ISY. I do suggest though that you keep it pretty much behind your router. If you start making some of the pi services public facing (like a public facing web server, etc.) then I would suggest you think about hardening the pi.

 

Thanks

Jim

 

 

 Hi Jim.. 

 

 I am looking :) .. lots of options out there for kits. Looks like for about $70 I can get a complete kit with 32GB micro card (Amazon). I'm sure that sounds like enough space for what I'l ever come up with in any basic code.

 

 You should have seen my eyes light up from this thread when geofence smacked me in the face. And given I have mobilinc already it was just a matter of my brain engaging & processing these facts.. a few clicks and now my front door locks when I leave down the road (if I forget) and unlocks when I approach home.. My wife must think I'm nutz.. She asked how I learned this and I told her by reading from very smart folks here.. :) .. 

 

 

Thanks,

Stan

Posted

Hi Jim.. 

 

 I am looking :) .. lots of options out there for kits. Looks like for about $70 I can get a complete kit with 32GB micro card (Amazon). I'm sure that sounds like enough space for what I'l ever come up with in any basic code.

 

 You should have seen my eyes light up from this thread when geofence smacked me in the face. And given I have mobilinc already it was just a matter of my brain engaging & processing these facts.. a few clicks and now my front door locks when I leave down the road (if I forget) and unlocks when I approach home.. My wife must think I'm nutz.. She asked how I learned this and I told her by reading from very smart folks here.. :) .. 

 

 

Thanks,

Stan

That starter kit is the way to go! Glad your having fun with this stuff! Sometimes it seems like an addiction! :)

Posted

Hi Jim..

 

I am looking :) .. lots of options out there for kits. Looks like for about $70 I can get a complete kit with 32GB micro card (Amazon). I'm sure that sounds like enough space for what I'l ever come up with in any basic code.

 

You should have seen my eyes light up from this thread when geofence smacked me in the face. And given I have mobilinc already it was just a matter of my brain engaging & processing these facts.. a few clicks and now my front door locks when I leave down the road (if I forget) and unlocks when I approach home.. My wife must think I'm nutz.. She asked how I learned this and I told her by reading from very smart folks here.. :) ..

 

 

Thanks,

Stan

Sure. Blame it all on us!

 

:)

 

Sent from a tiny keyboard. Response may be brief.

Posted

Sure. Blame it all on us!

 

:)

 

Sent from a tiny keyboard. Response may be brief.

 

LOL!

 

 

That starter kit is the way to go! Glad your having fun with this stuff! Sometimes it seems like an addiction! :)

 

Yeah.. when ya start dreaming this stuff it's time to check into the clinic!

Posted

LOL!

 

 

 

Yeah.. when ya start dreaming this stuff it's time to check into the clinic!

Is there an Insteon clinic?

Did I miss something?

 

Sent from a tiny keyboard. Response may be brief.

Posted

I am new to bash.  Can anyone tell me why my else statement wont work? Its not even getting to it.  The exit of arp-scan is 1 not found and 0 found.  

I am confused.

Thanks
Mike

#!/bin/bash
                        while :
                        do
                                echo "running arp command Phone 1"
                                sudo arp-scan phone | grep phone > /dev/null
									echo $?
                                        if [ $? -eq 0 ]
                                                then
                                                        curl -s http://user:pw@ip:80/rest/vars/set/2/1/1 > /dev/null
												else         
														curl -s http://user:pw@ip:80/rest/vars/set/2/1/0 > /dev/null
                                        fi
								echo "running arp command Phone 2"		
                                sudo arp-scan phone2 | grep phone2 > /dev/null
									echo $?
                                        if [ $? -eq 0 ]
                                                then
                                                        curl -s http://user:pw@ip:80/rest/vars/set/2/3/1 > /dev/null
                                        elif [ $? -eq 1 ]
                                                then       
														curl -s http://user:pw@ip:80/rest/vars/set/2/3/0 > /dev/null               
                                        fi
                        done
                        sleep 60
Posted

You are substituting "phone" & "phone2" with the IP address of your phones right? What you show is just protecting your phone's IP address?

Posted

arp-scan can take an IP address, a subnet range, or a domain name. I assume the above refers to devices with local domain names phone and phone2.

Guest
This topic is now closed to further replies.

×
×
  • Create New...