In my last 2 articles, I have shared with you code from my home automation system (HAS) controller written in Python that allows you to access your Google Calendar for scheduling events and communicating with the Insteon PowerLinc USB modem for controlling your Insteon and X10 HAS devices from Raspberry Pi (or other dedicated computer).
In today’s article, I want to share with you some Python code that uses OpenCV to detect faces from the Insteon (or FOSCAM) IP Camera which you can get from SmartHome.com for about $79. At my house, I use this code to detect when my fiancee or I approach one of the exterior doors. When we do, my HAS will recognize us and will automagically unlock the door that we are approaching. To do that, I am using the MiLocks 3-in-1 deadbolt system which is also available at SmartHome.com and will run you about $100 per lock. You will also need the MorningLinc Insteon adapter which will allow you to communicate with the MiLocks deadbolts over RF. These are also available from SmartHome.com and will run you about $50. You will only need 1 which is capable of controlling multiple locks.
Before I share the code, I should say that this particular code does NOT include the ability to recognize one person from another like that found in my personal HAS controller. All this code is capable of doing is detecting a face and saving a screenshot of that face to the file system (regardless who the face belongs to). The reason I am not sharing the face matching code yet is because there are a lot of complex steps required to train the system to detect individuals. I am currently working on a way to simplify these tasks. It took me several weeks to prepare the system manually for recognizing my fiancee and I with an acceptable accuracy and to not unlock our doors due to any false positives. Once I get this process simplified, I will share the code.
As explained in yesterday’s article, I have been overhauling my home automation system (HAS) and have decided to release parts of my controller software written in Python and runs on Raspberry Pi. I have been working on breaking apart the controller software so that each piece can be ran standalone. For example, yesterday’s article showed how to read your Google Calendar with Python. By doing that, you can schedule events to occur in your HAS by simply adding items to your Google Calendar.
Today, I want to share with you some Python code that allows you to control Insteon & X10 devices in your HAS using the Insteon PowerLinc USB modem which you can get from http://www.smarthome.com/powerlinc-modem-insteon-2413u-usb-interface-dual-band.html for about $80. Since the PowerLinc requires an always-on computer to be connected to it, it’s recommended to use a low powered computer such as the Raspberry Pi. Since the code below is written in Python, you can also use it from Windows or Mac if you want. Just make sure you change the “port” property in the serial connection to match your environment. If you combine this code with yesterday’s code, you can schedule your lights and other appliances to turn on and off by scheduling items in your Google Calendar.
I’ve been doing a lot of work on my home automation system during the Christmas break. As part of that work, I have decided to break apart certain pieces of the “controller” (written in Python and running on a stack of Raspberry Pi’s) and share the code with everyone that might be looking for a place to get started doing something similar. I’m not going to share the code in its entirety, but I will be sharing bits and pieces of it that I have rewritten to be ran standalone. The next several articles will include code that can be ran on its own, but can also be combined with code from the other articles (and a little bit more) to produce a really nice and powerful home automation controller.
The first piece of my home automation system (HAS) that I want to share is the Python code that allows my HAS to monitor my Google Calendar. Whenever events popup on my calendar that my house needs to be aware of (such as leaving for a business trip or vacation and returning back home), my HAS will take actions accordingly. For example, whenever my fiancee and I are scheduled to leave the house for more than 24 hours, the HAS will wait until we leave and will shut off things such as the hot-water-heater, ice-machine, thermostat, etc… and will turn on other things such as the alarm (if we – or the house itself – haven’t already enabled it).
A few years ago, I was asked to develop a Windows application for a nursing home that allows them to keep track of their residents and the medications they get. I was given some drawings that their users created and was asked to use them to throw together a simple prototype that demonstrates what could be possible. After about an hour or two, I had taken their drawings and converted them into an actual working application. Since this was only supposed to be a prototype, I never finished out all of its functionality. However, I did put enough work into it so that they could enter some basic information for their residents (name, DOB, apartment #, SSN, etc…). Along with the basic resident information, the app also allowed them to record contacts for their residents as well as any medications, diseases, allergies, or dietary information they needed for their residents. I even added the ability to store pictures of their residents and even added reporting capabilities so that whatever was viewed in the app could be printed on paper.
The very next day, I took what I had done so far and showed it to the customer who loved it. We discussed how I could put a larger database behind it and make it so that different users using the same computer or users on multiple computers could access the application. I mentioned the idea of making this a web application that could run on an internal server. But, they didn’t like that idea and preferred the thick client version just like the prototype. I even went thru an extensive whiteboard session to begin discussing what the app would eventually grow to become for the production-ready version of the app.
Shortly into the conversation, it came time to talk about the brass tax. At that point, the customer got all defensive and started acting like I should have been doing all of this work for free. In fact, he was so adamant that he crossed a boundary that I wasn’t willing to stick around for any longer. So, I grabbed my laptop, left the building, and never spoke to him again.
Today I was going thru some of my personal projects and stumbled across this one. Instead of deleting it from my computer or leaving it to waste away, I thought I would share it with anyone that might find a simple application like this useful. So, that’s just what I am going to do.
A while back, I wrote an article showing you how to create your own C# app for controlling the FOSCAM Wireless IP Camera. In that project, I showed you how to access individual images from your camera using the “snapshot.cgi” URL. Basically, that app would call the IP camera and retrieve 1 frame at a time which would simulate the appearance of streaming video. However, that app wasn’t really utilizing the streaming video capabilities that the camera had to offer which was somewhat noticeable in the video playback. Since writing that article, I have received hundreds of emails asking if I would show how to use the “videostream.cgi” URL instead. At one point I had built an app that does just that, but seemed to have lost the project somewhere along the way. Unfortunately, I have not had a lot of extra time to revisit this app until. The only reason I’m getting the chance / making the time to revisit the app now is because I have recently been conducting a major overhaul of my home automation & security system which involves this app.
One of the things I’ve done during that process is replace all of my FOSCAM IP Cameras with the INSTEON 75790WH wireless security IP cameras which are available on Amazon currently for around $65.00. They are pretty much the same exact cameras. Just like the FOSCAM IP cameras, the INSTEON cameras also include pan, tilt, & night vision. But, with many parts of my home automation system already being INSTEON, I chose to also use the INSTEON cameras as well. Since the FOSCAM and INSTEON cameras are basically the same, the C# IP camera controller app I introduced you to in the previous article will work for both. Plus, the updated version of the app I’m going to show you here also works with both cameras. After playing around with both cameras, the only real reason I would suggest going with the INSTEON version over the FOSCAM version is that INSTEON’s mobile app already supports the INSTEON camera natively. But, if you’re a geek like me and decide to roll your own software, you will be pleased with either camera.