X10 has been around for a long time. It started back in the early 80's, and was popularized by such consumer electronics stores as RadioShack. Now a full range of X10 products is available that let you control your home in every fashion. From garage doors, lights, appliances, security systems, sprinklers, sensors, timers, and other kits, x10 is a popular home automation solution

Using X10 to control computers

With a simple device called a cp290 (right) and a bunch of appliance modules (left), one can easily to the same with a room full of computers. Why? Have you ever had to come to work at 2:30 in the morning because a server had failed in such a way that the only solution to getting it back online is a power cycle? If you have, then you know the value of this already.

Okay, this is starting to sounds like a sales pitch, so let's get to the meat of the matter. You don't really need all of the stuff that this cp290 can do. It's capable of keeping sunset and sundown times, holding timers and storing icon locations. These things have been around for a long time, so don't be surprised when the manual you get with it references the Commodore 64, or the Apple][.

Anyway, I've been a victim of the midnight-madness caused by an unwelcome page, and I'd been searching for a long time for a cost effective solution to combat this problem. I've check out the product from APC (MasterSwitch), I've seen the adds for the RPC products from WTI in magazines and mailings (and on the net). But these and other products like them run $40-$150 per port! You get some nice capabilities for that money, like network management, distance, out of band management, etc, but it definitely was too expensive for us.

Finally, after searching for months for a reasonably priced commercial solution, I decided to construct my own using X10 modules. The result is a C and Tcl set of programs that we use to be able to remotely power on and off our servers. If you wanted to, you might even be able to use the Tcl plugin for netscape to enable power on/off via a web browser. Personally, I think the web browser is an overused metaphor for these sorts of things, and worries me from a security standpoint as well, but it should be possible.

How do these modules work??

X10 works by sending a series of 5V pulses over your power wiring. The modules interpret these pulses and, if appropriate, activate internal relays to turn power on and off. Each modules has two dials on the front. One dial goes from A to P. This is considered a housecode because X10 is designed for home use. I like to refer to it as a zone. The second dial goes from 1 to 16. This is the device code. Thus, your CP290 can theoretically address up to 256 different modules. In practice, you probably wouldn't be able to get this many and might run into interference on certain combinations. Besides, cp290 interfaces are cheap.

Sample Usage

Here's a sample of how you'd write a simple Tcl script to turn on and off machines. Let's say there are two of them named albert and einstein. First, you can setup an .x10rc file in your home directory like this.

x10 alias albert {a 3}
x10 alias einstein {b 4}

Now, this code will be able to turn albert and einstein on and off. For example, if you name the below script 'power', then power albert on will turn albert on, and, power einstein off will turn einstein off.

package require X10

# Initialize two x10 cp290 interfaces 
set bottom [x10 init /dev/cud1]
set top [x10 init /dev/cud4]
switch [llength $argv] {
        2 {
                set halias [lindex $argv 0]
                set command [lindex $argv 1]
                if {[catch {set interface $hostint($halias)}]} {
                        puts "Bad alias. I don't recognize that one."
                        puts "known aliases: [array names hostint]"
                        exit 1
                upvar 0 $interface inthandle
                puts "$inthandle [x10 alias $halias] $command"
		# Send the command
                if {[catch {eval $inthandle [x10 alias $halias] $command}]} {
                        puts "The x10 interface detected a transmission error"
                } else {
                        puts "command successful"
        # The 3 arg specification will require hardcoding the interface here
        # or looping through all interfaces, or building an array of
        # code to interface mappings
        3 {
                puts "$argv"
        default {
                puts "You must give an alias and a command or a zone/device/comm
                exit 1

As you can see from the above program, The code is smart enough to detect an error signal from the cp290. If so, it will tell you the transmission failed.

A short word on aliases

When you do a package require X10, the .x10rc program in your home directory is read. This is a good place to keep aliases that map from device names into x10 zones and codes. You've seen the aliases above for albert and einstein. That's easy. You can put anything you want in the .x10rc really, not just aliases. Here's an example of a number of devices that I put in my .x10rc that are on two separate cp290's. To manage this, I setup an array mapping the host name (as specified in the alias) to the name of the interface. I have called the interfaces top and bottom because of the positioning of the particular circuits on the UPS that we use. Note, anything that is not an x10 command needs to be declared as a global variable before you start initializing it, or your program will be oblivious to its existence.

x10 alias leaky {l 14}
x10 alias orville {n 16}
x10 alias roadrunner {f 7}
x10 alias wincenter {e 8}

global hostint
set hostint(leaky) top
set hostint(orville) top
set hostint(roadrunner) bottom
set hostint(wincenter) bottom


The x10 source and 2 Tcl programs are available from my FTP area. as x10.tar.gz

The original X10 shar file that 'does' take into account sunset and sunrise, timers, icons, and other things, is available here . It has it's own configuration language, and comes with many Linux distributions.


_go_back_ Click here to go back to the console server home page.