Computers are too ornery and difficult to manage to be meddling in daily affairs of the house.
Automating daily house chores with a computer is a fun and useful thing to do, but it can only reliably be done with a dedicated and specialized microprocessor.
PCs are destined for more than just sending e-mail and playing golf; soon they will rule the world (or at least parts of your house)!
If you subscribe to the first philosophy, youre probably reading the wrong magazine. I bet a good number of you are members of group two. I used to be a member of this group when I started working with home automation (HA) with Steves first Home Run HA system from the BYTE magazine days.
Over the years, as PCs got faster and cheaper, Ive migrated to the third group. The nice thing about doing HA on a PC is that you have a much wider choice of programs and hardware to integrate. Every day it seems like there is some neat new program or device you can hook into a PC.
At my day job (designing chips at IBM), Ive found great productivity in a programming language called Perl. About a year ago, I decided to write a Perl-based, open-source multiplatform HA program. I call it MisterHousewhich is easier than calling it a Perl-based, open-source multiplatform HA program.
This article gives a little background on MisterHouse and shows how I use it to log phone calls and announce who is calling over our house PA system.
It used to be that when someone wrote a program and then made it available for free, it was called "free software." Often, only the binary for the program would be distributed.
Recently, the term "open source" has been promoted. Theres an official definition at www.opensource.org/osd.html, but the basic idea is that the source of the software is posted on the Internet so that anyone can help work on it.
With new hardware becoming available daily and the amount of information on the Internet growing exponentially, the number of HA possibilities is growing faster than any one person can possibly keep up with. Using the open-source idea, if the program doesnt do what you need done, you can extend it and then share it for others to use.
In the few months that I have had MisterHouse (MH) posted online, I have reaped not only lots of good ideas from other users, but also bug fixes, code extensions, and completely new applications.
Heres another quiz: Which is the better OS to do HA on? Windows and the great wealth of fun software available on it, or a Unix OS with its improved reliability and multitasking?
Cant decide? With Perl you can run on either OS! In fact, Perl is available on several different OSs, but Ive only tested MisterHouse on Windows 95, 98, NT 4.0, Linux, and AIX.
By using the same underlying interface subroutines, you can keep the higher-level user event code platform-independent. For example, on Windows, a serial port item will use the SerialPort module to read and write serial data using Win32 API calls to a serial port DLL. On a POSIX-compatible Unix system (Linux and most others), that call is translated by the SerialPort module to use POSIX TERMIOS calls.
Heres another example. When you ask MH to run a background process on Windows, the Perl Win32::Process module is used; on Unix, the fork function is used. The user code is the same, regardless of the platform.
Much of the fun in HA comes when your computer talks and listens. Perl doesnt come with built-in voice software, but it talks to programs that do.
On Unix, you can implement text to speech (TTS) with the Festival speech synthesis system. Festival provides a server that MH can talk to via TCP/IP sockets, and you can plug in different voices and languages.
On Windows, you can do both TTS and voice recognition (VR) using freely downloadable engines from Microsoft. These engines provide access via OLE methods, which Perl also supports. Several different voices are available, including some digitized voices that sound amazingly humanlike.
The VR is in a command-and-control mode (i.e., it will not recognize any arbitrary set of words; only the ones from a set of phrases you specify using the MH Voice_Cmd object). This mode improves reliability over what you might get with a dictation mode, where any word can be expected.
All of the voice command objects you specify will be available with VR, as well as from the command line, a GUI Tk interface, and a web interface.
The Tk interface is built using Perl Tk widgets. These widgets enable us to create GUI objects with just a few lines of code. Photo 1 shows the default Tk interface.
The web interface can be used from any Internet browser, whether its in your house or not. The interface uses a web-authentication password to allow remote control (e.g., go to misterhouse. net and you can take a look at the one on my house).
Using HTML templates, the web interface can be easily changed. The default web interface is shown in Photo 2.
Other programs communicate with MH through TCP/IP sockets or via commands in a file. The "Hardware Interfaces" sidebar shows the various interfaces that MH currently supports.
All HA programs have some sort of programming language built in for event programming. Instead of implementing a new event-control language, I used Perl.
Perl is a powerful language and it can take quite a while to learn all of its tricks. But, by using object-oriented programming and extending it with HA-related functions, MH hides much of the complexity. Listing 1 is an event for turning on an X-10-controlled light half an hour after sunset.
Before I go on, I want to cover a few basic Perl syntax rules. All variables start with a $. Strings are quoted with either single or double quotes. Use double quotes if you want variables within the string to be substituted.
Commands begin with # and commands end with a semicolon. Do loops and conditional blocks start and end with { }. There are two ways to do if statementsif (test) {action} and action if test;. If tests are == (or !=) for numeric data and eq (or ne) for string data.
Local variables are declared with the function called my. Object methods (e.g., set) can be specified in two ways:
set $dishwasher ON; # Indirect object form
$dishwasher->set(ON); # Classic 'object oriented' form
By looking at the examples supplied with the MH package, you can learn what you need to know about Perl for its use in MH. Another good starting point is www.perl.com. The reference book of choice is Programming Perl. If you want to know how to do something in particular, The Perl Cookbook is excellent.
Enough background, its time for an example! If youre going to have your house talk to you effectively, you can either give it a really loud voice or you can use a house PA system with a speaker in key rooms.
But what if you want to have a conversation with your house in the living room while your spouse is trying to sleep in the bedroom? You can either get him/her a nice set of earplugs or you can insert a computer-controlled relay card between the PA amplifier and the speakers, as shown in Figure 1.
The digital I/O card is an inexpensive ($30) PIC-based card available from Weeder Technologies. The relay card is a Universal Relay Card from Jameco ($100). By modifying pa_control.pl, you can define which room is controlled by which relay.
Now you can direct speech to the room of your choice, using either of the following formats:
speak "rooms=bedroom Time to wake up";
speak(rooms => "all", text => "The laundry clothes are dry");
The other two Weeder cards shown in Figure 1 let you monitor outgoing and incoming phone numbers. The DTMF card detects any pressed phone keys, and the caller-ID card decodes the name and number of incoming calls. If you have a caller-ID-capable modem, you can use it instead. By sensing when the modem is not in use, MH can share this modem with other programs.
The code in Listing 2 monitors the data coming from these two cards. The Weeder kits have a simple protocol that uses the first character of a string to indicate which card is sending data: "I" is for the caller-ID card and "O" is for the DTMF card. The MH code detects these codes and stores the incoming data in the $callerid and $phonetone objects.
The $caller_id_data string is parsed by the Caller_ID::make_ speakable function, which changes the phonebook-formatted name into a more pronounceable name. For example, it changes "WINTER BRUCE LA" into "Bruce Winter" by swapping fields and dropping initials and abbreviations.
If the callers area code differs from yours, this code uses a lookup table to add the city or state that the call is from. Optionally, it will use a user-defined rule to replace the received name with a more phonetically correct name or a prerecorded WAV file.
$phonetone_data and $caller_ id_data are logged into monthly log files that can be retrieved and displayed by display_calls. The Tk interface for this feature is shown in Photo 3.
The caller-ID signal is sent between the first and second rings. In order to give MH a chance to decode and speak the caller-ID information before the phones start ringing, a ring morpher is inserted between the external phone line and the other phones in the house.
The ring morpher has the side effect of delaying the ring by one cycle. This delay allows us to hear the caller-ID announcement (e.g., "phone call from Bill Clinton") at the same time the phones start to ring.
Here are a few of the events we use to control our house. You can find them online (see the Software section).
I have window quilt curtains hooked up to pulleys attached to 24-V DC motors and a set of relays. Each curtain has two relayson/off and up/down. These relays are driven either by local switches or by Weeder DIO outputs. curtains.pl monitors the outside temperature and sunlight levels using a Weeder analog kit, and opens or closes the south-facing curtains to maximize solar heat gain in the winter months.
The deep_thought.pl trivia.pl modules display and/or speak fun facts from various databases. It certainly makes breakfast entertaining!
door_monitor.pl monitors door openings and closings using magnetic reed relays connected to Weeder DIO inputs. Do your kids leave outside doors open? This code issues a friendly reminder to close the door using the outside PA speaker. It will also close the garage door at night, but only after it senses no movement in the garage.
It also monitors movements in hallways and stairways using X-10 movement sensors. When doors open and close or people are sensed in key areas, I have MH play short, unobtrusive sounds so I can tell where people are goingsort of like a high-tech squeaky door!
internet_data.pl retrieves and processes pages off the web (e.g., Lettermans top 10 list, local weather conditions). It also sets the clock according to an Internet-connected atomic clock.
The internet_mail.pl event uses a background process to call the get_email script, which checks who has sent you mail in specified e-mail boxes. After the process has finished, MH announces what new e-mail you received and from whom.
Using a user-specified IP socket port, telnet.pl lets you use a telnet program to log in, specify an optional password, and issue commands.
Like a kitchen timer, timer_seconds timer_minutes timer_hours periodically tells how many seconds, minutes, and hours are left on your timer.
A ham-radio enthusiast wrote the tracking.pl code. Using a GPS unit, a pair of radios, and TNCs (terminal node controllers), this code tracks and announces his cars position and speed. Using an optional position file, it announces position with respect to various landmarks (e.g., "Dads car has just left the IBM parking lot" or "Juniors car is parked at lovers lane").
This code does other nifty things with packet radio (e.g., monitor current weather conditions from the nearest packet radioconnected weather station.
Using the get_tv_grid script in a background process, tv_grid.pl collects customized TV programming from the Internet to local files. It adds a "program the VCR" button to the TV grid entry, so you can not only see whats on but also instruct MH to create an event to start and stop the VCR at a certain time for the specified channel.
weather_monitor.pl weather_ wx200.pl reads data from a WX200 or WM918 weather station. It then logs, displays, and optionally speaks the data.
Even if you dont have any of the hardware currently supported, you can still run MH and play around with the web, Tk, VR, and TTS interfaces.
The install.html file has the installation instructions. mh.html has documentation on the various objects, methods, and functions, and updates. html contains a list of updates.
mh_src_###.zip has all the source code, support files, and documentation. If you dont have Perl installed, youll need mh_win_###.zip or mh_linux_ ###.zip, which have the platform-dependent compiled versions of MH.
Depending on how many events you load and if you have the Tk interface turned on or not, MH will use from 5 to 15 MB of memory. At ten passes per second, it uses about 30% of the CPU cycles of a 100-MHz Pentium CPU.
So, dust off that old PC, give your house a little personality, and come join the open-source movement and make the world a better place! Or at least have your house train your kids to keep the back door closed.
MH events for authors house, misterhouse.net/mh/code/Bruce
Mailing list, www.onelist.com/subscribe.cgi/misterhouse, www. onelist.com/archives.cgi/misterhouse
L. Wall, T. Christiansen, and R. Schwartz, Programming Perl, OReilly, Sebastopol, CA, 1996.
SOURCES Digital I/O card
Universal Relay Card
Jameco
(800) 536-4316
(415) 592-8097
Fax: (415) 592-2503
www.jameco.com
TTS and VR engines
www.microsoft.com/iit/download/
speechengines.htm
Text-to-speech with Festival
www.cstr.ed.ac.uk/projects/festival
ActiveHome kit
X10 (USA), Inc.
(800) 675-3044
www.x10.com
Interfaces
JDS Technologies
(858) 486-8787
Fax: (858) 486-8789
www.jdstechnologies.com