Rob Chartier ~ Contemplation...

.NET, C#, Work, etc.

News






www.flickr.com
This is a Flickr badge showing public photos from Rob & Kat Chartier. Make your own badge here.


Even Quicker Links

XBMC and X10 – Home Automation on your TV

As some of you may remember I upgraded my Home Theatre PC to the Ubuntu/Live version of Xbox Media Center.  Its a free and open source Media Center application.   To get an idea of what the UI looks like, see here.  Here is the current skin which I use, Confluence.

So anyways, I have been meaning to finally integrate X10 directly within XBMC in the form of a Python script, which is natively supported in XBMC.  This article describes how I was able to accomplish this.

Note: Items starting with “>” can be interpreted as command line commands via SSH

Hardware

For the XBMC base setup and configuration see my previous post here.  Now we need to add in the X10 components.  In the past I have been a big fan of the X10 modules.  What you need is a Firecracker (CM17a) module with a USB to Serial Adapter.  The specific USB to Serial Adapter is pretty important, because of the Linux drivers available.  Mine, which obviously works, is listed as…

Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC.

To be safe I do recommend using the same sort of device (at least the FTDI Chipset – Ubuntu seems to agree with it).

Once you have both of those simple components plug them in and allow your system to recognize the device.  This may require a reboot.

To determine if it has been detected or not, you will need to SSH into your XBMC device and execute the command:

> lsusb

You should see something like...

Bus 004 Device 003: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC

Since this is the first USB device on this rig, it is using ttyUSB0, so we must change permissions for that device via the command line:

> sudo chmod go+wr /dev/ttyUSB0

 

Software

Installing heyu

The software side of things is fairly easily done, with an existing tool called “heyu”.

Step by step..

1. SSH into your XBMC

2. > cd ~

3. > mkdir x10

4. > cd x10

5. > wget http://www.heyu.org/download/heyu-2.8.0.tgz

be sure to get the latest revision of heyu, I'm assuming 2.8.0 is the latest, but please do check.

6. Ensure the build-essentials are installed for your distro

> sudo apt-get update

> sudo apt-get install build-essential

7. Untar/gzip the heyu library

> tar -xvzf heyu-2.8.0.tgz

8. cd heyu-2.8.0

9. Build heyu (as documented in “INSTALL” file)

> sh ./Configure  [option]   (As a normal user)
> make                         (As a normal user)
> su                         (Become superuser)
> make install               (As superuser)  (choose 1)
> exit                       (Revert to normal user)
> heyu info                  (As a normal user, to test installation)

10. Start the heyu engine

> heyu start

11. And finally test; send firecracker (CM17A the All Off Command, for house code A)

> heyu falloff A

 

If that works, your now 1/2 of the way there!

The next set of steps will install the heyu engine to run at start up, by editing the rc.local file, here goes…

1. > sudo nano /etc/init.d/rc.local

2. Add the following lines:

chmod go+rw /dev/ttyUSB0
mkdir /var/tmp/heyu
chmod go+rw /var/tmp/heyu
/usr/local/bin/heyu start

(putty supports copy and paste, paste with the right mouse button)

3. Save, exit  (ctl-o, ctl-x)

If for some reason you cant save the document, you probably missed the “sudo” portion of the previous command.  Exit without saving, and start from Step 1 again.

4. Reboot (sudo reset)

Upon boot your XBMC installation will have the heyu engine started and ready for your commands.  If you SSH back into your device and issue the commands:

> heyu fon A1

>heyu falloff A

> heyu help 

      will give you the full help documentation as usual

XBMC Scripting with heyu

XBMC scripting is pretty straight forward if you go down the WindowXML route.  There are a decent amount of examples online, and I have attached here my sample, working code.

In the sample, if you work your way down to the path, and edit the file:

\X10\resources\skins\DefaultSkin\pal\HomeAutomation.xml

You will see the layout. Consider this XML is the main control structure and positioning that you can use.

Next edit the file:

\X10\default.py

This is the python script responsible for initializing the UI and handling the events.  Scroll down to about line 80 and you will see this block of code:

   1: if (controlID == 1001):
   2:     print "------------------executing A1 on------------------"
   3:     os.system('heyu fon A1')
   4: elif (controlID == 1002):
   5:     print "------------------executing A1 off-----------------"
   6:     print os.system('heyu foff A1')
   7: elif (controlID == 1003):
   8:     print "------------------executing restart-----------------"
   9:     print os.system('heyu restart')
  10: elif (controlID == 1004): 
  11:     print "------------------exiting-----------------"
  12:     self.close()

Notice that we are matching the “controlID” variable with the same control id=”1001” variable in the XML document.

As a final step, upload your edited script and XML document to your XBMC installation and give it a try.

Problems encountered so far

The heyu engine setup might need tweaking, especially when the XBMC device goes to sleep.  Upon waking up it seems that I need to force the heyu restart command, and even then its not 100% reliable.  I typically have to reboot to get it working just right.

Sometimes the receiver of the X10 signals is jammed.  My module is pretty old so I plan on grabbing a new/better model.

Let me know if you have any further questions, comments or concerns.

Comments

lucy_chen said:

hi,do you have any idea about xbmc automation testing tool? I used xnee tool to run automation testing by record the keyboard and mouse moving, bug unfortunately it can not catch mouse moving, and I have no idea about it, so I am appreciative if get answer.

# December 13, 2011 1:29 AM