In yesterday’s article, I showed you how to create a Python script that broadcasts a systems’ vitals (diskspace, memory, & CPU) out onto the network. As promised, today I will show you how to create a Python script that listens for these broadcasts and displays the results. I use this script as part of my home automation system and display the results on a touchscreen TFT that’s exposed out the front of an enclosure that houses the main-brain of my home automation system (see pictures below). But, you can do all kinds of other cool things with the results such as selecting Raspberry Pis with unused resources to act as slaves in a distributed computing application (which I will explain in another article). But for now, let’s get started.
In case you haven’t read any of my other home automation articles, I use a lot of Raspberry Pis in my home automation system. Keeping track of them used to be a burden, but not any more. As mentioned in yesterday’s article, I have Raspberry Pis installed in some pretty crazy places. Even though all of the Pis in my house have dedicated functions, some Pis aren’t used as extensively as others. For example, I have Raspberry Pis installed inside the walls of several rooms in my house which act as built-in media centers. But, when those Pis aren’t being used for providing media, I don’t want them sitting there doing nothing. So, I make them contribute their unused resources to the rest of the Pis in my house to get a little extra horsepower for some of the Pis that have more heavy lifting to do (such as the Pis that do face & speech recognition).
In order for me to keep up with which Pis are online and how much free diskspace, memory, and CPU utilization they have available to share with the rest of the house, I wrote a small Python app that runs every time the Raspberry Pi starts up and continues to broadcast its existence and system vitals every 10 seconds (configurable) where I detect those broadcasts and display the results on a touchscreen TFT monitor (which I will explain in my next article). For now, I want to share with you the Python script that broadcasts its system vitals out to any listening system on the network.
As I’ve mentioned numerous times on this site, I use Raspberry Pis and Python extensively in my home automation system. Since all of my Pis are installed in enclosures, inside the walls, under the house, in the attic, and basically all other inaccessible places in my house, I don’t have direct access to all of them which makes it a huge pain when they restart for whatever reason (mostly power outages with the Pis that aren’t connected to backup batteries). To ensure that my apps start back up when the Pis power back on, I have them set to run at startup and in this article I will show you how to do the same.
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.