Just before we left for our most recent vacation, Heather suggested we might want to put some of the lights on timers. This was just the opportunity I was looking for...
I've been following home automation protocols for as long as I can remember. I thought very seriously about doing an X10 setup years ago, but the lack of acknowledgement in that protocol makes it far too unreliable IMHO. I've been hearing more and more about INSTEON (see http://www.insteon.net/ or http://www.smarthome.com for more information). This one seems to have a good balance between cost and reliability; I got a couple of light switches and a controller before we left.
Since we've been back, I've been thinking about how to expand the INSTEON in the house. I've got some modules on order that will let me put the front porch light, front hall, and main hall on the system; this can tie in with the kitchen light I've already got on it. If it all works out properly, we'll be able to do things like turn the kitchen light on and off from the front door (right now, it's necessary to walk through a dark kitchen to get to the switch).
Controllers and Modems
One surprise is that they've got two completely separate and almost incompatible series of controllers for the system. One series, which they call powerline controllers (PLCs) is programmable in a proprietary interpreted language; the other, which they call powerline modems (PLMs) just communicates with the network. It looks like they've decided the PLCs were a bad idea; their automation software talks to the PLMs, and so does Mister House.
The PLMs come with either a serial or USB connection; the USB is just the same thing as the serial with a USB to serial convertor. However, it's hard enough to talk to that everybody seems to prefer the serial.
The PLCs come in serial, USB, or web-enabled. Mine is web-enabled. I've got another page describing my adventures with the ethernet-connected PLC, and its problems with Linux TCP flow control. While I was tracking that down, I discovered that it's got an undocumented port open (port 9761) which seems to talk the PLM protocol! So my task for today is to write a little daemon that will talk on that port, and let me send lighting commands and log events. Looks pretty straightforward. Ah, rats. I can send it commands, but it doesn't seem to ever send me an unsolicited message when I turn on/off a switch. So I'll have to get a real PLM, not use the PLC. The problem with undocumented features is they aren't guaranteed to work...
oops, looks like I just didn't understand the protocol, and it was probably useable. Oh, well
A Simple Home Controller
I had considered using the Mister House free software, but finally concluded it does too much, and has too much configuration I'd want to take out. So I'm writing my own controller software.
This has turned out to be a lot of fun, and an excuse to learn a lot of stuff I've needed to get to know for a while anyway.
Things done so far:
The Insteon modules in the house, their locations, groupings of them into rooms, and current status is being maintained with an sqlite database (http://www.sqlite.org/). This is a library that embeds an SQL interpreter into your program, and accesses a file as an SQL database -- all with no configuration and no separate database server. It supports transactions, so two programs can simultaneously be accessing a single sqlite database.
- It does what it does, and does it very well. It's terrific for things like embedded systems or projects like this one. It would be an utter disaster for things like enterprise-level databases.
- I've spent some time poring over documentation, and I've gotten a little daemon going that talks the Insteon protocol. It just sits in a loop asking every switch in the house for its current status; when there is a status change it updates the database and logs the change. Since the PLM is running 19.2KB on a serial line, the daemon can just keep going in circles without usng significant resources (let's see... 0.2% of the CPU on the machine it's running on right now). Like a good daemon, it also waits for clients to talk to it and give it commands.
- And, of course, I've written said client. It takes all its parameters from the command line; I can use it to turn any light or group of lights (defined in the database) on or off from the command line.
- Since I've got a command-line interface, I've now got light on/off times set up as a bunch of crontab entries.
- First prototype of the web interface is done.
Things to do:
- Need to have the web interface get regular status updates so I don't need to manually refresh the screen.
- Collapsing menus are nice, but animated collapsing menus would be nicer...
- What's going to justify a lot of this -- beyond the amount of fun I'm having with it -- will be more sophisticated timers. I'm logging the times of all switch events; the next thing to do is copy them into crontab tables so that when nobody is home the house duplicates all the lighting activity from a week previous.