2008-09-12

Control your home appliance thru Internet via freetalk, Jabber/Google talk and X10

by Forrest Sheng Bao http://fsbao.net

Few months ago, I made a video.

Many friends asked me how I made it. Now here it is. This is a very brief one and I will enrich it later.

Hardware requirements:

  1. You will need a computer interface to X10. It is an adapter between your computer and the X10 network. And since your computer can connect to the Internet, you can control all home appliances connected to X10 network thru your computer, and thus, over the Internet.
  2. You will also need a lamp or appliance module to receive the X10 signal and to switch on/off your home appliance.
You can get above two stuffs from many companies. But I recommend X10.com 's stuffs. My computer interface model is HC60CRX. A popular model number is CM15/CM11.
This article is based on an X10 communication software called Heyu. It could work well with X10.com 's stuff.

Jabber account requirements:

You will need two Jabber IM accounts, like Google talk. Freetalk is an Jabber protocol client software. We can hook up some extra functions to Freetalk so that it will do something when you send special texts to it.

You can login your regular Jabber account from the machine you are using and login to your irregular Jabber account from the machine at your home place, where has the home appliance to be controlled.

Steps

1. Install freetalk and Heyu

sudo apt-get install freetalk

Go to http://heyu.org/download/ to download Heyu.

Open a terminal and unzip Heyu source code. Change to the directory containing Heyu source code and run

./Configure
And then follow the instruction.

You will be automatically prompted like this: I did not find a Heyu configuration file. Where would you like the sample Heyu configuration file installed? 1. In directory /home/forrest/.heyu/ 2. In subdirectory .heyu/ under a different user home directory 3. In directory /etc/heyu (for system-wide access) 4. No thanks, I'll take care of it myself Choice [1, 2, 3, or 4] ? 1 According to my experience, I prefer to put the configuration file under my home directory. So I input 1 and enter.

Then, your will be asked about the serial port address. By default, the port name is /dev/ttyS0 if you have a serial port on your computer. If you are using a USB-RS232 converter, then it should be /dev/ttyUSB0.

I will add the TTY port for your CM11 to the config file
Specify /dev/ttyS0, /dev/ttyS1, etc., or the word dummy
To which port is the CM11 attached?
/dev/ttyUSB0
Setting uid:gid = 1000:1000 for /home/forrest/.heyu/x10config

2. Configure you X10 adapter and lamp module

Now please set the home code (i.e., A) and device code (i.e., 2) of your lamp module, according to your device manual. For example, you can screw a knob to do that. The home code and device code are used in X10 protocol to address devices. I addressed my lamp module as A2.

Then, hook your X10 computer interface with your computer and plug it, as well as the lamp module, to the power outlets. Don't forget to connect your light with the lamp module.

3. Configure and test heyu

You can use heyu info command to see all devices under the same home code.

forrest@Xnote:~/.heyu$ heyu info
Heyu version 2.3.2
Configuration at /home/forrest/.heyu/x10config
Powerline interface on /dev/ttyUSB0
Firmware revision Level = 1
Interface battery usage = Unknown (0xFFFF)
Raw interface clock: Thu, 20:26:59, Day 254
(--> Civil Time: Thu 21:26:59 Sep 11 2008 CDT)
No schedule has been uploaded by Heyu.
Housecode = A
0 = off, 1 = on, unit 16.......8...4..1
Last addressed device = 0x0000 (0000000000000000)
Status of monitored devices = 0x0000 (0000000000000000)
Status of dimmed devices = 0x0000 (0000000000000000)
If you got the error, like this:
tarting heyu_relay
Unable to send address bytes
maybe the X10 computer interface is not connected properly. If you are using USB-RS232 converter, try to plug-unplug the converter to solve this "freezing" problem.

To turn on a lamp module, run like this:

heyu on A2
. And to turn it off, run
heyu off A2
.

4. Hook freetalk with Heyu

Create a hidden directory under your home directory

mkdir ~/.freetalk
And create a file called freetalk.scm in that new hidden directory. If you already have one Jabber account, you need a new one. So they can "chat" each other. You will use one account to send messages to another one. After freetalk gets the message, it will do something you want.

You can set some login information, like this:

(ft-set-jid! "someone@gmail.com")
(ft-set-server! "talk.google.com")
(ft-set-password! "thepsswod")
(ft-set-prompt! "~\\/~ ")
(ft-set-sslconn! #t)
(ft-set-port! 5223)
Make sure it's the information of the account intent to receive your magic messages.

So you don't need to input all these information anymore. Just type freetalk at the shell terminal and they will be automatically used.

Now is the most exciting part. You can associate special behavior with the a sentence. Insert things like this into your freetalk.scm:

(define (issue timestamp from msg)
"Forward command"
(if (ignored-message? msg)
(ft-hook-return)
(cond ((equal? msg "turn the slow cooker on")
(begin
(system "heyu on A2")
(system "echo Turn slow cooker on")
(ft-send-message "someone@gmail.com" "Sir, slow cooker is on now. Mission accomplished.")
(ft-hook-return)
))
((equal? msg "turn the slow cooker off")
(begin
(system "heyu off A2")
(system "echo Turn slow cooker off")
(ft-send-message "someone@gmail.com" "Sir, slow cooker is off now. Mission accomplished.")
(ft-hook-return)
))
)
)
)
This configuration uses the grammar of the LISP programming language. In above example code, after you send "turn the slow cooker on", your A2 device will be on.

Ok, that's it. If you have anything not understood, please feel free to contact me.

No comments: