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 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.
A while back I wrote an article about a C# wrapper I wrote for the Cronus video game controller adapter. For those of you that aren’t familiar with this adapter, it’s basically a USB dongle that attaches to your Xbox, PlayStation, Wii, or computer that allows you to use any USB gaming controller you want, even if the controller isn’t made for the console you are wanting to use it on. For example, this little device will allow you to use your Xbox 360 controller on your PlayStation 4 if you wanted. Another cool thing about this device is that you can automate game play from your computer. Click here to checkout how I automated Guitar Hero from my laptop using this device. If you don’t have a Cronus controller adapter, you can find them on Amazon for around $50.
The wrapper that I shared in the first article was only capable of connecting to your Xbox (or other console if you made the necessary changes) and could send commands to the console. Since posting that article, I have received numerous emails from people asking if I could upgrade the wrapper & example app to also be capable of reading the state of the controller. Well, I’m glad to say that I finally took the time to do that. You can now use my Cronus C# API wrapper to capture the state of each button on the controller. For example, whenever you press the “A” button, your app can now detect that button press and act on it if necessary. In the example app I’m including at the bottom of this article, each button pressed on the controller is indicated on the Windows form. I have also setup the example app to forward all button presses to the console. This will allow you to play your games while the controller is connected to the Cronus all while capturing the button presses in real-time on your computer.