Skip to content
Lieven Hollevoet edited this page Sep 22, 2014 · 1 revision
    • First a bit of background**
The CM11U or the CM12U X10 computer interface is usually connected to your MH box by USB these days, using a USB-to-Serial adapter, which works great. There is (or rather will be) an issue when you connect other USB-to-Serial adapters in the future, in that most computers tend to reshuffle the ID of these imaginary serial ports occasionally, so that your MH code which talks to your X10 interface may well end up talking to your Velleman board. This is because most USB-to-Serial adapter are identical, in that there is no way the PC can tell them apart, one Prolific adapter looks like all the others, as do most FTDI adapters (which may shock some people!). If you plan on only ever using one adapter this is not a problem, however most people end up using several. BUT I suggest spending an extra couple of £/$/E's and buying a FTDI adapter with a unique ID embedded in it. Using this ID and leaving the adapter permanently attached to the X10 interface (and to other serial kit) will lead to hassle free running of MH. See this page **[UdevRules]**
    • Step 1**
While your MH box is running, plug in the USB-to-Serial adapter. From the console : //**root@mh_server:/#**// dmesg This shows you the kernel logs. The last few lines should show you something like:

//[15296.392214] usb 7-1: new full-speed USB device number 2 using uhci_hcd// //[15296.989777] usbcore: registered new interface driver usbserial// //[15296.989792] USB Serial support registered for generic// //[15296.989825] usbcore: registered new interface driver usbserial_generic// //[15296.989828] usbserial: USB Serial Driver core// //[15296.996948] USB Serial support registered for pl2303// //[15296.996979] pl2303 7-1:1.0: pl2303 converter detected// //[15297.008336] usb 7-1: pl2303 converter now attached to// **ttyUSB0** //[15297.008373] usbcore: registered new interface driver pl2303// //[15297.008378] pl2303: Prolific PL2303 USB to serial adaptor driver//

You can see it's found the device and it's name it **/dev/ttyUSB0**

Now you need to edit you mh.private.ini file and add a line to tell MisterHouse where it is.

//**root@mh_server:/#**// sudo nano /opt/misterhouse/mh.private.ini

Add the line

cm11_port = /dev/ttyUSB0

    • Step 2**
Now we need to explain to MH about the X10 hardware that exists and the equipment that it's powering. This is done via the .mht file. Much more info here .mht file .

As a bare minimum example, edit your items.mht file like this -

//**mh@mh_server:/#**// nano /opt/misterhouse/items.mht

code Format = A

  1. noloop=start
  2. Type Address Name Groups Other Info
  3. A Appliances
X10A, A1, Humidifier, Appliances|Downstairs|Living_Room
  1. noloop=stop
  2. Voice Commands
VOICE, Humidifier, Humidifier code

Format A is the only format available in MH currently. The noloop command exclude the code from the main run loop, don't worry about it for now. The critical line is this -

X10A, A1, Humidifier, Appliances|Downstairs|Living_Room

This defines an Appliance (as opposed to a lighting module), on X10 address A1, called Humidifier (because it's attached to one), that's in the Downstairs Living Room. As well as having defined that an X10 module exits, MH has now also started creating a floor level plan (which can be seen on the web service, but will look a mess as nothing else has been defined!)

Once you've restarted MisterHouse, this object will appear in many places on the web service. You should be able to find the controls and turn the humidifier on and off remotely, but this is only half the fun...

    • Step 3**
Now we come to our first bit of real programming of MisterHouse. Create a new file in the /opt/misterhouse/code directrory called x10_devices.pl (it can be any name you like as long it ends in .pl)

//**mh@mh_server:/#**//nano /opt/misterhouse/code/x10_devices.pl

and add this code:

//# Category = X10// //#@ This module controls all the X10 switched equipment.//

//if (time_now '2:01 PM') {// //set $humidifier ON;// //speak "The humidifier is now on";// //}//

//if (time_now '11:01 PM') {// //set $humidifier OFF;// //speak "The humidifier is now on";// //}//

What this code does is as follows: The Category and the #@ line added extra text details that appear on the code selection page of the web service. The if(time_now) lines check the time, and if the time matches 2:01PM or 11:01PM (though this can be any time you need - just change the numbers) and it does, then it switches the humidifier on and off via the X10 controller. The speak command makes MH speak the message out of speakers attached to the MH box (or put around the house as many people have them) and logs the fact that the humidifier has been switched on or off. They are of course other ways of doing this, but this is just a rather verbose example.

To get this code to run you will been to restart MisterHouse. There is an option available just to reload the code, which will work in most cases, but as your code gets bigger, it's always best to restart MH to make sure everything is OK before you leave it for the night.

Now when 2:01PM rolls around, the humidifier should come on, and switch off again at 11:01PM.

[More]

Back: The .Ini file Return To Index

Clone this wiki locally