Tag Archives: x10

Enlarge your python x10 !

X10-controlled
X10-controlled

I have recently ordered a few X10 equipments to play with. For those who don’t know, X10 is a standard for Home-automation (domotics) that enables you to remote control devices over a classical power line. A typical scenario could be for example remotely changing the intensity of a light. This has many “serious” use cases but honestly, for me, this is more a fun device to play with. Even if I may use them later for my home, I guess, I’m more interested in seeing how they can be used in another contexes such as artistic installations.

CM15
CM15

One of the devices I’ve ordered is a USB controller (model CM15) that you plug both to a usb port and the powerline. It can also receive and send events coming from wireless controllers, but that’s out of the scope for now.

So, first, I’ve of course started lurking at the existing free software to control all these toys and discovered a few projects such as Eclipse, MisterHouse, etc. They all seem to be interesting but my initial plan was more to have a good library so that I can integrate them into my existing projects. I’ve then found a low-level perl library, another one for the CM17 in ruby and my best result was a C one with a demo application.

The later works like a charm and allowed me to enter the cool world of X10 by sending some commands to my actuators. Fun. But, even if C is good for many things such as operating systems, we nowadays tend to use higher level programming language, such as my prefered one : Python.

After searching for some CM15/X10 stuff for Python, I’ve only found three libraries : a module for the firecracker (CM17) which exposes a low-level interface (very C style, low level commands) and two others called PyXAL and PyX10 that basically wrap the X10 Abstraction Layer library. While they may seem interesting, these three projects are no more maintained and the latest commits are from 2000… erg !

One possible solution could have been to wrap this C code to a Python module, but even if it works well, I had the feeling that I could rewrite it in a more consive way and in an object-oriented manner. Moreoever, this kind of USB devices are usually not too much complex to use, leading me to prefer to write a pure Python module. Beginning of another story :D

My goal is to make a generic, yet not complex, X10 library. Using the documents and specifications I’ve found, I’ve already written what’s needed to detect, setup the CM15 and made a pretty object-oriented interface to talk to the devices. I’ve also added the concept of House and plan to have virtual groups to be able to send a command to a set of devices you have chosen. Have a look :

1
2
3
4
5
lamp = dev.actuator("A2")
lamp.dim(10)
lamp.off()
house = dev.house("B")
house.lightsOff()

By the way, the module can be used for any other X10 device, it’s made for that. All the code is almost generic, you just have to write your own controller class. Also, the API is likely to change so if you have suggestions…

I’ll publish the module soon and my plan is to enhance it little by little… in fact I’ll add a feature every time I need it. If you want it faster, I’ll be happy to apply your patches :-)