Home Automation EZine
EMagazine
Volume 6 Issue 6
Dec 2001 / Jan 2002

Features
Cover Page
2001 in Retrospect
Home Theater Control
Home Entertainment Networking - COAX
Home Media Trends
TV – The Next Phase for Broadband
Wireless Toys
Distributed Audio Wiring Practices
Digital Audio Receivers
Streaming Media Problems
MultiRoom Audio
 on Cat5

Smart Homes for Disabled People
New Face for Automation
802.11b Wireless
SmartHome Planning
Phoneline Networks
Voice Control for Home Automation
Streaming Wireless Entertainment
CeBus vs X10
Action / Reaction
Plan for Now
Provide for Then

X10bot for Linux
DLP™ Technology
Loudspeakers and Whole House Audio
HAVi and IEEE 1394
One Chip Does All
Rock-n-Roll Meets Wireless
Weather Stations

New Products
Previews
HAL Deluxe
Cateye Web Camera
Remote Anywhere
HomeVision Home Controller

Siemens Gigaset Wireless Phone
Interviews
Terry Wright
Chairman HomeCNA
John Barr
President OSGI
Mentor
Wayne Caswell
Wireless Networking

Free Email Updates
Industry News
Article Library
Review Library

Return to Main Menu
Home Toys Article
- December 2001 -
[Home Page]
Information Services
Order Free Catalogs and Product Info
[Click Message To Learn More]

x10bot Home Automation Daemon for Linux
by Daniel P. Stasinski

The end result is a home automation system that can be controlled from a single script that can be as simple or complex as your personal needs dictate. x10bot is a standalone software package and other than a CM11A and Linux based computer, it does not require any other tools to monitor and control your x10 system.

To configure x10bot, you simply add code to /etc/x10bot.conf for each unit you want to control and what you want it to do.

x10bot is distributed as GNU open source and can be downloaded from http://www.scriptkitties.com/x10bot


The idea of x10bot came about earlier this year when my home was burglarized and I began looking for solutions to home control and security. Prior to that day, my away lighting was cheap 24-hour timer switches and no I had security to speak of. My newfound goal became to create something that could integrate lighting control, security cameras and Internet access, all tied together with a fully extendable programming language.

My language of choice was TCL (Tool Command Language), a popular scripting language that was created from the ground up for the purpose of being integrated into other packages. It is also great as a “glue” to bind other packages together. With it, I was able to tie together a simple telnet server, event manager and x10 control library in short order. Even if you are not familiar with TCL, you can become quite proficient in it in a matter of a few hours.

The end result was a home automation system that could be controlled from a single script that can be as simple or complex as your personal needs dictate. x10bot is a standalone software package and other than a CM11A and Linux based computer, it does not require any other tools to monitor and control your x10 system.

To configure x10bot, you simply add code to /etc/x10bot.conf for each unit you want to control and what you want it to do. The following demonstrates a minimalist approach:

# x10bot config script
# latitude and longitude for Phoenix, AZ (for
# daytime, sunrise and sunset calculation)

  coordinates 33.4341667 -112.0080556

# Create aliases for the light and sensor

  alias G1 LivingRoomLight "Living room light"
  alias G2 BedroomoomLight "Bedroom light"
  alias G5 LivingRoomSensor "Living room motion sensor"

# Assign the code in LivingRoomSensorProc (below) to
# be executed whenever LivingRoomSensor is tripped

  bind LivingRoomSensor LivingRoomSensorProc

# Schedule weekday events

  schedule_weekday 5 10 "turn LivingRoomLight on"
  schedule_weekday 5 15 "turn BedroomLight on"
  schedule_weekday 6 10 "turn LivingRoomLight off\n turn BedroomLight off"

# user defined procedure that tells if I am at home or work.
# if it’s a weekday and between 6:00am and 3:30pm, I am at
# work so return 1, otherwise return 0

proc atwork { } {

  set now [clock seconds]
  set dayofweek [string trim [clock format $now -format "%w"]]
  if { (($dayofweek > 0) && ($dayofweek < 6)) } {
    set time [clock format $now -format "%k%M"]
    if { ($time >= 605) && ($time <= 1430) } {
      return 1
    }
  }
  return 0
}

# code assigned to the living room motion detector
# if it detects motion and it is not daytime, turn the living room
# light on. If I am at work, send me an email at work to let me
# know the motion sensor was tripped. Call DoWebCam to take a
# picture and upload to my private web server.

proc LivingRoomSensorProc { address command value } {
  if { ($command == "CMD_ON") } {
    if { ![daytime] } {
      turn LivingRoomLight on
    }
    if { [atwork] } {
      x10_sendmail "devnull@mywork.com" "Sensor Tripped" "$address tripped"
      DoWebcam
    }
  }
}

In this example, I have defined the procedure LivingRoomSensorProc that gets called whenever the living room motion detector is tripped. If it’s nighttime, the living room light gets turned on. During the weekdays, it turns on the living room light at 5:10am, the bedroom light on at 5:15, and then shuts them both off at 6:10am.

The above is a very simple example. In my own real implementation, I have even finer detail. The lights will not turn on in response to the motion detector between 10:00pm and 5:00am unless I specifically turn them on, plus each light also has a “sticky mode” so that if I specifically turn a light off or on with a remote pad, that lamp stops responding to the motion detector commands for a period of one hour. For security purposes, if any of the motion sensors are tripped while I am at work, it also sends me an email there, alerts me via Instant Messenger, sends an alert to my pager and begins uploading the appropriate web cam pictures to my private web server. Every couple of minutes it updates my private server with full status information.

Another useful feature is remote telnet access. You can log in with most telnet clients and from there you can control individual units, get status information or execute user-defined commands:

# telnet admin.x10bot.org 4466
Trying admin.x10bot.org...
Connected to admin.x10bot.org
Escape character is '^]'.
LOGON 0
status G1
STATUS LivingRoomLight ON 1006128385 (Sun Oct 14 17:06:25 2001)
status_house G
STATUS LivingRoomLight ON 1006128385 (Sun Oct 14 17:06:25 2001)
STATUS BedroomLight OFF 1006103313 (Sun Oct 14 10:08:33 2001)
STATUS G3 UNKNOWN 0 (null)
STATUS G4 UNKNOWN 0 (null)
STATUS LivingRoomSensor ON 1006130654 (Sun Oct 14 17:44:14 2001)
STATUS BedroomSensor OFF 1006130654 (Sun Oct 14 17:44:14 2001)
STATUS KitchenSensor OFF 1006130654 (Sun Oct 14 17:44:14 2001)
STATUS PatioSensor OFF 1006130654 (Sun Oct 14 17:44:14 2001)
STATUS NightSensor ON 1006130898 (Sun Oct 14 17:48:18 2001)
STATUS FrontDoorSensor OFF 1006130732 (Sun Oct 14 17:45:32 2001)
STATUS G11 UNKNOWN 0 (null)
STATUS G12 UNKNOWN 0 (null)
STATUS G13 UNKNOWN 0 (null)
STATUS G14 UNKNOWN 0 (null)
TATUS G15 UNKNOWN 0 (null)
STATUS Keychain UNKNOWN 0 (null)
turn G1 on
SENT LivingRoomLight CMD_ON 0

A word of warning though: As of this writing, you will need to firewall off whatever port you decide to have x10bot listen to so you don’t have random people logging in and playing with your system. Future versions will take advantage of /etc/hosts.allow.

Also,in the works is a version to work with Dave Houston’s BX24-AHT X10 All Housecode Transceiver (see http://www.laser.com/dhouston/)

x10bot is distributed as GNU open source and can be downloaded from http://www.scriptkitties.com/x10bot.

Your Linux installation may already have TCL installed, but it is still a good idea to get the latest from http://tcl.activestate.com and supportive documentation from http://tcl.activestate.com/doc/.