Showing posts with label home automation. Show all posts
Showing posts with label home automation. Show all posts

Saturday, September 13, 2014

Home Automation - The New Thing??

"Home Automation" - The latest buzz word of the world it appears. If you haven't heard much about it you likely will soon. With Apple jumping on the band wagon just maybe the general world population will begin to see and use the "smart home" technology that many of us have taken for granted for years.

Hearing about "cutting edge" home automation apps that text or email you when things like burglar alarms sound or doors open around you home when you're away sounds so cool... and they are, they just aren't so "cutting edge" to me. We've had such notifications for over 15 YEARS from our house. 

I'm not alone, Home Automation has been around for decades, it's just now maybe starting to go main stream. Heck I had my old VIC 20 computer turning lights on and off while we were away from home in the middle 1980's so not much is news to me. In fact our home has been online and accessible through the Internet since 1999.

Of course most of this is very DIY or very expensive to have someone else build it for you but the concepts have been there for a long time. The ability for your house to check if the garage door was left open late at night and close it for you, to let you know when the burglar or fire alarm goes off, to automatically turn certain lights on or off when a car pulls up or someone wanders around your yard are all things I've almost taken for granted anymore.


My solution is a hodgepodge mash up of various pieces and a lot of home written code but it does the job. Of course some of it is just for fun, I mean does one really need to know how many times the refrigerator or freezer opened each day or how many times the cat used the litter box? But it could be useful if the system could tell you that that freezer door appears to have been left open for 30 minutes couldn't it? Is it really necessary for my washing machine and dryer to Tweet their activities? Ok, I guess not, but hey it is fun making it do that. No telling, maybe there is another lonely washing machine out there just waiting to meet up with ours on Twitter. :-)

Seriously though, part of my issue with the current "Home Automation" trend is calling it the wrong thing. Such things like turning a light bulb on and off from anywhere with an App like the WeMo light or the Phillips Hue is cool but that's not automation, that's remote control. Of course those can be "automated" to some degree using IFTTT.com but that's not what the manufacturer is telling you. Oh well, the more hardware available the more options there are I guess. 

Having that Hue light bulb change colors when the garage door is open or the forecast says it's going to rain is a bit more automated. I haven't done that yet but know I how it would I would do it if I wanted to spend the bucks for a Hue. Turning off the lights and arming the alarms system when you leave the house is automation. Having the house tell you by speech that the garage door just opened, the dryer or washing machine just stopped, etc or text you when the doorbell rings is automation to me. Having the house know you're home or away based on where your phone is at, which is generally where YOU are at, is automation. 

Time will tell where the trend goes but at least it appears to gaining momentum and there are more and more DIY trends heading our way. Unfortunately many of them force you to sign up for some monthly service to use the features and I'm personally not in favor of that but likely many will be and maybe that is what it takes long term for Home Automation to make it to the masses. 


Thursday, July 12, 2012

Proximity Sensing Using Latitude and VBScript

Are You Home Yet?
The System Knows...
NOTICE: With the killing of Latitude by Google in 2013, this approach no longer works. Just be advised - too bad, it was a handy solution IMHO. - Stephen

I have played with how to tell my Home Automation system if I was home or away for quite some time. Sure I can press a "home" button and an "away" button but what fun is that for a "Smart" home? I wanted the ability for the system to "know" if I'm home or not "automagically" without my sometimes forgetful intervention.

Back before moving to an iPhone I had a bluetooth solution "semi-working". The phone was paired with a bluetooth adapter on the server and some software was running that could tell if the phone was in range or not. A script would then spin through the status file, a simple flat text file, and see if my phone was local and adjust the status in my system. Kludgy but usually worked.

When I moved to an iPhone I was UNhappy to find out that the same bluetooth option would not work so I was back to figuring out a new solution. This time I wrote a script that "pinged" the IP my phone had picked up on the WiFi and if it was there then I was home, if not, away. That worked but I had to make sure I always had WiFi enabled on the phone and the script simply fired off a command ping which was very slow. Also sometimes the ping would time out anyhow if my phone was not active so I would suddenly be "away" when I was really home.

Google Latitude Tracking

The more recent solution is a combination of using Google Latitude (http://www.google.com/latitude), which I was already experimenting with, and a local VBScript that provides the linkage between Latitude data and my HA system. Latitude is available for various mobile phones and although obviously very "Big Brotherish" it provides a nice framework to handle the GPS tracking piece of a proximity system. It also provides all kinds of mobility analytics such as how many miles you've traveled, how much time you spend "at work" and "at home" and other rather interesting pieces of information.

To be sure, Latitude is not perfect. It usually has my GPS location pretty well tied down but you will always see occasional "way out there" points when it defaults to the closest cell tower instead of a tight GPS point. But overall it's pretty good at keeping up with where you're at. Personally I haven't see any major battery drainage issues either but I am unrelenting on charging my devices every night no matter how they were used that day.

Of course the first thing you have to do is download the Latitude app for your particular mobile device. Visit the Latitude page and/or your app store and get it working on your device first. There are apps for many of the devices out there so check out the page / links. Make sure the Detect Your Location and Background Updating are turned on in the Settings area so the app is constantly updating location data.

To make Latitude your friend for getting data out, takes a special configuration that isn't overly obvious. You have to expose the data using the "Google Public Location Badge" feature. Sounds like you're giving away the farm but this is just an option if you WANT to publish everywhere you go all the time. The key is, this lets you build the data link but you DON'T HAVE TO share the link. The public location badge allows you to publish either a road map (KML), JSON or ATOM feeds of your location data but we are just going to use the data for our own purposes and not publish to the world.

To get your data link, log into Latitude on the web, click on the gear icon in the upper right, and go to Application Settings. At the very bottom of the screen is a "Developer Information" link. Click on that and you will see the linkage information and your own special username code in the various formats. We are using the JSON format here so the URL looks like this:

https://www.google.com/latitude/apps/badge/api?user={Your Code}&type=json

Once you have this link you can leave the rest of the page alone and move on. Just make sure the Enable and Show Best Location radio button is check in the configuration and click Save. That's after you've checked out all the other tidbits of data you'll have available about your movements of course.

Mobile Status Screen for
My Home Automation System

Getting the Data

Now we need to get the data feed and do some location checking. This is where the VBScript comes into play. You can do this in any other scripting or other language if you want, this is just the easiest to write and understand for me. This script is then scheduled on my HA server to run every five (5) minutes to see where I'm at. I actually have it log my Lat/Lon into my own local database and then check for within a certain range of my home address.

VBScript Sample

The key features of the sample script are the GetLatitude and the GetDistance functions. GetLatitude uses your provided Google Latitude user code and pulls the current lat/lon data out of your feed. The GetDistance function takes two lat/lon pairs and returns the distance, in miles, between them. I am using a free online web API to do the distance comparison here but you could spin your own code if you wanted to. GeoCoder.us is free for the low level personal use I am dealing with here. With those two functions you can have your script do whatever you want with the results. The sample script below uses a CheckDistance variable to compare against the results and take action.

You'll have to clean up some of the &Amp code issues if you copy/paste the script but the overall process is very simple. Also if you are behind a corporate proxy, the URL gets may or may not work. I've run an enhanced version of this script that links to my Home Automation system and toggles my status for months now and it's been quite stable. The code could obviously use some error handling or at least what to do if we get 0,0 back as location or odd distances but that's up to you creative people out there.

'** GetLatitude.vbsGet Google Latitude Lat/Lon for the user and log to the Log database
'v1.00 - SWN - 10/29/2011

'** Debugging flag - True to see messages
MyDebug = TRUE

'** Your information and location to test against
'** Google Latitude User ID
UserID  = "{Your Latitude Code Here}"

'** Location Latitude to test against
LocLat  = 35.32

'** Location Longitude to test against
LocLon  = -96.92

'** If you are within 1/2 Mile of LocLat/LocLon then If triggers
CheckDistance = .5

'** First get the user (YOU) current location from the Latitude JSON feed
MyLonLat = GetLatitude(UserID)

'** Debug stuff - show it if debugging
If MyDebug then MsgBox "Raw Coords: " & MyLonLat

'** Split out the Lat/Lon from the results
MyCoordsA = SPLIT(MyLonLat)
MyLon = MyCoordsA(0)
MyLat = MyCoordsA(1)

'** Now do a distance check between the points
'** Note this uses another free web API, GeoCoder.us to calc this for us
'** You could build your own dist compare if you wanted... but why if this is there?
'** Distance returned is in Miles so you can convert as desired from there
MyDistance = GetDistance(MyLat, MyLon, LocLat, LocLon)

'** Show distance if debugging
If MyDebug then MsgBox "Distance: " & MyDistance

'** Now take action on the distance check results
'** Obviously you will have to have some session state here so this doesn't fire on every check
'** In my HA system, it sets a Home flag so my code checks if the should be changed and takes action if needed
If MyDistance < CheckDistance then
 '** Do something cool because you're close
 MsgBox "You are within " & MyDistance & " of your target location."
Else
 '** Do something else because you're not
 MsgBox "You are OUTSIDE of your target location by " & MyDistance - CheckDistance & " miles."
End If

'** get the Lat/Lon data from your Google Latitude Feed
Function GetLatitude(strUserID)
    
 Set objHttp = CreateObject("Msxml2.ServerXMLHTTP")
 objHttp.Open "GET", "http://www.google.com/latitude/apps/badge/api?user=" & strUSERID & "&type=json&callback=parse", False
 objHttp.Send
 html = objHttp.ResponseText
 Lines = Split(html, "[", -1, 1)
 Count=UBound(Lines)
 MyCoords = lines(2)
 MyCoords = LEFT(MyCoords,INSTR(MyCoords,"]") - 1) 
 GetLatitude = MyCoords
 
 Set objHTTP = nothing 'Release the object 
End Function

'** Calc the distance between two lat/lon points and return as MILES
Function GetDistance(Lat1, Lon1, Lat2, Lon2)
 Set objHttp = CreateObject("Msxml2.ServerXMLHTTP")
 GetLink = "http://geocoder.us/service/distance?lat1=" & Lat1 & "&lat2=" & Lat2 & "&lng1=" & Lon1 & "&lng2=" & Lon2
 objHttp.Open "GET", GetLink, False
 objHttp.Send
 html = objHttp.ResponseText
 
 '** Parse out the information here
 StartPos  = Instr(html,"=")
 EndPos   = Instr(html,"mile")
 GetDistance = Ltrim(Rtrim(Mid(html,StartPos + 1, EndPos-StartPos-1)))
 GetDistance = GetDistance * 1
 Set objHttp = Nothing

End Function


Sunday, January 24, 2010

Online House Updated - Home Automation

Fueled by many cups of 1/2 Caff coffee (hey you have to cut down when you get old), cold and wet weather and a huge need for an update, I've spent my spare time in the past week or so updating our Online House and home automation system. The house can be visited HERE and the descriptive history is found HERE.

We've had an "automated house" since way back in the 80's when I had an old VIC 20 computer turning lights on and off. The next step up was in the 90's when we moved and I purchased a JDS Timecommander Plus system. The new system provided much more capability and is still the stable work horse for our system. When we moved to our current house in 2000, the system moved with us but the installation was half hearted. It worked fine and spent the past 10 years doing it's job but needed to be cleaned up and some new features added and some broken features fixed.

I feel I have somewhat accomplished that... but there is plenty more to do. The biggest need was to get a better mobile phone interface. The house has had mobile access for a very long time when "WAP" and "WML" were the only thing a phone understood. With the advent of the new smartphones and the iPhone that world changed and a much better interfaced was needed. The iPhone can handle the main site but it is still not optimized for small touch screens. The basic screen is shown at the right and allows access to most all the features and information the house provides. This interface will continue to get updated as ideas pop up and time allows. For now it is much easier to use from anywhere in the world to not only know what is up in the house but to control things as well.

Some of the "new" features... although planned all along, just not implemented, are the integration of the HVAC units so I know when and for how long each unit runs. Not a big deal but nice to know for cleaning filters and maintenance issues. I also re-integrated the washer and dryer that had to be removed when new units were purchased. Another fix, not new feature, but a handy item to have the system tell you when the machines are done across the speakers instead of waiting for that high pitched beep that I can hardly hear anymore...another getting old thing I guess.

On the new side all new paging and email routines were added to keep me updated even if I am not looking at the house remotely. Items such as burglar alarm, garage door opening during the day, motion detection when there should be no motion, phone calls, etc were added. A new routine to speak the current weather forecast was added that gets the Yahoo weather RSS feed, breaks it down and speaks it on command. Handy sometimes. I also added some bluetooth based proximity sensing. The system knows when I am around the server and can act upon that. Nothing really programmed in yet but the capability is now there.

The biggest thing added was putting the house on Twitter at http://Twitter.com/NolenHouse. Yeah, I know... WHY? Because I can? Because *I* like the idea. There are only a couple houses I could find that have done this and with my work on @ShawneePD and @ShawneeFD it was so easy to do... so WHY NOT?

I also updated the basic look and feel of the control pages replacing icons from the old clipart versions to new, more modern looking ones from across the net. I also changed the color theme "back to blue" because that is what I like.

But what about security?
That is the biggest question I seem to get and it *IS* a valid one. With all that information out there couldn't someone figure out when you are home or not and break in. Sure they could... just like they could your house by simply counting cars or watching the house. Of course THAT is what all the automation is about. Webcams that capture pictures, motion sensors that know when someone is there, burglar alarms watching windows and doors, and more that will not be listed here. So yes, it is a concern but the house has been online since 1999 doing it's best to protect and serve.

Of course there is always the watch dog... no, not THAT one...

For more information about Home Automation visit the Wiki or visit SmartHome.com.