Sunday, October 11, 2009

Waking Up to X10, Linux & Cron

Anyone who knows me will tell you I am not a morning person.  Maybe it's the shock to the system brought about by an alarm clock blaring, naturally followed by the squinted eyes when I flick the lights on.  Especially in the winter when the days are short, waking up before the sun is a pain, but a necessary part of life.  However, using a little technology and creativity, I hope to lessen the dread of the morning routine.

I've been a fan of X10 power line control devices for a very long time.  I've used them in combination with wired remotes, RF remotes and more recently, the CM11A computer interfaceThe other day, I decided to beat the winter morning blues by upgrading my system slightly and implementing my own sunrise!

While there are turnkey systems available (at sometimes great expense) to provide this level of automation and customization, I wanted to use the components I already had in place.  The complete system consists of:
  • LM465 soft-start lamp modules (3 for my needs)
  • CM11A computer interface
  • My all-purpose Linux server
  • Cron and a uber simple shell script
  • "Heyu" command line interface for the CM11A
For reference, the shell script is as follows:

for (( i=1; i<64; i++ ))
do
    /usr/local/bin/heyu xpreset f2,3,5 $i
    sleep 20.2
done

/usr/local/bin/heyu on f4
/usr/local/bin/heyu off f6


The cron job is setup to kick off at 6:30am Monday through Friday.  The shell script begins by sending a command using heyu to the CM11A to tell the LM465 modules to come on at a brightness of 1 (out of 63). Then, it delays for 20.2 seconds, then repeats the loop for a total of 63 iterations, each time increasing the brightness of the lights by one level.  The final two steps in the script are to turn on my espresso machine to get the boiler warm and turn off my white noise generator.

So, why the 20.2 second delay?  My goal is to have the entire process take 25 minutes.  Each time heyu sends the command, it takes about 3.7 seconds to run.  Those 3.7 seconds plus the 20.2 second delay times 63 iterations equals 1505.7 seconds, or about 25 minutes.  The end result is at 6:55am the lights are on at full brightness and by 7:00am the boiler in my espresso machine is hot and ready to go!

All of the components for this project (other than the Linux server) were sourced from eBay for a total of about $45.

A note regarding the LM465 modules: there are two versions of these modules.  The first generation is not "soft-start" enabled, while the later are.  The real kicker is there was no change in model number or any other external markings making it very difficult to tell which you are buying.  I bought my LM465's off of eBay where the seller specifically stated they were the soft-start variety.  For this implementation, I am not using the soft-start feature though, but rather other features that come along with the upgraded program in the internal microcontroller.  These later modules respond to an extended set of X10 commands, which enables the "turn on at level 1" feature.  Previous models would only turn on to full brightness.