Monday, October 29, 2012

X10 Home Automation with Raspberry Pi

PLEASE NOTE THAT THIS TUTORIAL INCLUDING ALL REFERENCED FILES HAVE BEEN MOVED TO THE URL BELOW:

http://80degreeswest.com/apps/x10

------------------------------------------------------------

I have a confession to make.

Ever since I ordered my Raspberry Pi and finally received it in the mail I've been obsessed with it.  Probably not in a healthy way.  My wife calls herself a 'Pi widow'.  

I get more and more amazed every day at what this little box can do.

First, I put RaspBMC on it and set it up with my Network Storage to stream my entire movie and music library to my TV.  That worked great, but I since decided to go with Roku box (which is great) to free up the Pi box for other projects.

And this is where this post comes in as the current project was to setup home automation using Raspberry Pi.

Please note, that you should have some basic Linux experience or ability to Google for how to do stuff in Linux.  I'm not a Linux expert by any means so I cannot provide any expertise on how to troubleshoot anything if you run into issues.

Here is what you will need:
  • Raspberry Pi
  • SD card (I used 4 GB SanDisk Ultra II 15MB/s)
  • CM19A X10 controller (eBay, Amazon)
  • TM751 X10 Module (Get it here)
  • Any other X10 modules you want to use
  • Network cable
  • USB hub with Micro USB cable (or a dedicated Micro USB power supply - 5V)
  • HDMI cable
  • TV or Monitor with HDMI input
  • USB Mouse
  • USB Keyboard
Software I used:
Step 1: Install Linux on the Raspberry Pi:
Step 2: Install Apache web server:
  • sudo apt-get install apache2
  • Configure your router to assign a static IP address to your Raspberry Pi
Step 3: Install Java Runtime Environment:
  • sudo apt-get clean
  • sudo apt-get update
  • sudo apt-get install openjdk-6-jre
Step 4: Install Libusb:
  • sudo apt-get install libusb-1.0-0-dev
Step 5: Install Mochad:
  • wget http://sourceforge.net/projects/mochad/files/mochad-0.1.15.tar.gz
  • tar xf mochad-0.1.15.tar.gz
  • cd mochad-0.1.15
  • ./configure
  • make
  • sudo make install
Step 6: Install X10 Java Server:
  • Download it from here
  • Extract X10.class and put it in your /home/pi directory
  • Download the startup script here
  • Extract x10 and put it in your /etc/init.d directory
  • Run this command to make script executable: sudo chmod 755 /etc/init.d/x10
  • Run this command to launch server on Linux boot: sudo update-rc.d x10 defaults
Step 7: Install X10 Web Client:
  • Download the zip here
  • Extract it to X10 folder and copy the whole folder to the apache web directory /var/www
  • Edit index.htm file to modify your devices
  • In index.htm, update mochadServer and controllerServer ip address (replace current IP with your Pi's IP address.
After all the steps are done, unplug your mouse and plug in the CM19A X10 Controller (or use a USB hub to have it all plugged in).  Restart your Pi.  Set your TM751 on house code A, open your web client and try it out by going to http://192.168.1.10/X10 (replace the IP address with the one of your Pi).