Background:
I started my home automation system rather simply with a few lights automated with a timer. I was always fascinated with the functionality provided by home automation systems such as HomeVision or the JDS Time Commander but could see myself spending the amount of money required to obtain one of those systems.
When the ActiveHome 2-way interface came out, I thought right away that it could help me develop my own system to do exactly what I want. The price of $49 was definitely within my budget and the programming specification was available at X10′s web site. I figured I could buy the device and write my own software (I am a computer analyst). As luck would have it, my boss at work bought an ActiveHome to test out. He liked the device but wanted a device that had more functionality such as if-then-else logic. He decided he didn’t want it so he sold it to me at a great discount.
I thought that my home automation system should have a name so I came up with “IBHome”. The software is what provides the more advanced functionality within my home.
Requirements:
The basic features I wanted to develop:
- Send & receive X10 commands/macros on powerline
- Play .wav files in response to events or timers
- Perform text-to-speech in response to events or timers
- Invoke computer programs in response to events or timers
- Initiate Internet dialup connection
- Check for new Internet Email
- Support different “modes” (e.g. Home/Away)
- If-then-else logic
Design:
The basis of IBHome’s design is centered around the concept of “events” and “actions”. An event triggers one or more actions. An example of an event would be receiving an X10 command from the ActiveHome interface. This event could then in turn kick off a collection of actions to perform a task. Actions could be such things as sending an X10 command, sending an alphanumeric page, checking for new email, playing a wav file, or starting up a connection to the Internet.
The other thing I considered during the design phase was the fact that I won’t necessarily be able to add in all the functionality that I want. I decided that IBHome needed to be extensible without having to make changes to the base code. I achieved this using the concept of “plugins”. IBHome utilizes plugin “Event Generators” and “Action Providers”. This provides the ultimate in flexibility. Plugins are dynamically loaded Java classes that follow IBHome’s plugin API.
An example of an “Event Generator” is my Java class that interfaces to the ActiveHome 2-Way Interface. All processing necessary for the ActiveHome Interface is contained within this class. The class posts X10 “events” when they are received. If I ever decide to work with another X10 2-way interface, all I have to do is develop a new class to talk to the interface and add the class name into the IBHome confguration file.
Development:
I have developed IBHome using Java under Linux. I am using Java so I can run IBHome on different platforms.
IBHome uses text files for all configuration and event definitions. It is very easy to modify and can be added to easily during development. The text file format was chosen at this time so I don’t have to waste development effort changing a graphical interface every time I want to add or enhance the configuration.
I was able to interface to the ActiveHome 2-way interface rather easily using the specification document from the X10 Beta Web Site and the Java Communications API that allows Java access to Serial and Parallel ports. I run the ActiveHome interface code in a separate thread for better timing.
Current Features:
- Graphical Interface utilizing the “Swing” Java components.
- Start dial-up Internet connection specifying text name of configured dial-up networking entry.
- Disconnect selected Internet connection.
- Send X10 command.
- Play .wav file.
- “Speak” text phrase.
- Invoke executable on computer.
- Check for new Email and create text strings with From: and Subject: information.
- Retrieve current stock price and price change for specified list of stock ticker symbols. Makes HTTP request to Internet quote server and parses out the information.
- Retrieve current local weather. Makes HTTP request to Internet weather site and parses out the information.
- Generate home statistics HTML page with information regarding device on/off status and other information. (Not always up to date due to development/test cycle.
- Ability to FTP a file to a remote server.
- Can control the XMMS MP3 player. Commands supported: Play, Stop, Next Track, Previous Track and Load Playlist. I can use my X10 RF remote to play my favorite MP3 files.
- Can control the internal CD drive to play audio CDs remotely. Commands supported: Play, Stop, Next Track and Previous Track. I can use my X10 RF remote to play my favorite CDs on the computer.
- Detect the insertion of an iButton into a “blue dot” reciever. The iButton I use is a smartcard with a better physical container. More robust than a smartcard. IBHome displays the internal iButton serial number for automating different actions for different iButtons.
- Can download any web file and save it locally.
- Built-in web server provides remote access into IBHome. Current functionality allows for viewing the status of X10 devices, current log entries and for remotely posting new “events”.
Web Server:
Since I now have IBHome running 24 hours a day on my dedicated HA machine, I wanted some way to remotely access IBHome from my main development machine. I was thinking about a Java client front-end utilizing Java’s Remote Method Invocation (RMI), but then decided that an HTML based solutio might be better. This would allow me to remotely access IBHome from any networked device that supports a web browser.
I didn’t want to be dependent on anyone else’s code so I wrote my own mini web server as a plugin to IBHome. It supports the following basic functions:
- Multi-threaded for good performance.
- Configurable base directory.
- Configurable port.
- Configurable file extension mime types.
- Can serve any type of file.
- Supports my own “weblet” architecture for server-side Java transactions.
I built in “weblet” (for lack of a better name) access so IBHome plugins can provide methods to be invoked directly by the HTTP request. This can be achieved by either a direct URL or by the “action” with an HTML form. My “weblet” architecture allows plugin developers to provide a full HTML interface to needed functionality.
Speech Recognition:
Talk and IBHome shall listen…
I’ve incorporated speech into IBHome. IBHome can now recognize voice commands and perform actions based on which command you speak! I built a speech plugin using an implementation of the Java Speech API. Any speech engine that supports the Java Speech API will work with IBHome.
I originally developed this feature using IBM’s ViaVoice. IBM has since stopped development of the Linux version of ViaVoice. With the big push IBM is making into the world of Linux, I am hoping that they will resurrect the Linux version of ViaVoice.
The speech plugin allows for speech recognition and for text-to-speech processing. This means you can verbally command IBHome to perform a task and IBHome can verbally respond after the task has been completed! Cool!
I added some simple logic to keep IBHome from picking up recognized phrases during regular conversations. IBHome will not process any voice commands until it receives it’s “attention” phrase. Once the “attention” phrase has been recieved, IBHome will process all recognized phrases until a “standby” phrase is received. This way I can verbally control when IBHome “listens”.
Here is a sample voice exchange I have configured for IBHome:
Me: Hey Computer
IBHome: What is thy bidding master
Me: Family room lights on
IBHome: Lights now on
Me: Bye Computer
IBHome: Standing by
The recognized phrases are configured in a Java Speech Grammer Language (JSGL) file. This makes it real easy to add phrases or to change the “attention” and “standby” phrases. The text associated with the recognized phrase is posted as an event into IBHome. You can then configure IBHome to perform whatever actions you desire. For example, I have configured the phrase “check email” to have IBHome connect to the Internet, retrieve any new email messages, disconnect from the Internet, and then speak the “from” and “subject” portions of the messages to me using text-to-speech.
Java Installation:
I was looking into a couple of Java software installation programs that I could possibly use to create a single file distribution for IBHome. There are a couple of real nice commercial ones such as InstallAnywhere and JInstallShield, but the price is way to steep for me. Besides, I figured that I really only needed a small portion of the features provided. I also checked out IBM’s Installer for Java. You can download it for free from their website. It also has many features but I found that the install file it was creating was a lot larger that I wanted.
So I decided that I could create my own Java based software installation package that I could use with IBHome. I liked the idea of distributing a single file that would contain all the necessary installation classes and files, but I did not want to append all the file data onto the end of a class file in the manner that IBM Used. I looked into the capabilities of the “jar” files and found the answer that I was looking for. I could place all the installation classes, IBHome classes and data files into a single “jar” file and then use a cool feature from Java 2 to invoke the installation class. Within the manifest for a jar file, you can specify the “Main-Class” to be invoked as the starting point within the jar file. This way, to invoke a jar file without knowing the contents, you can use the following syntax:
java -jar myfile.jar
Cool! A single installation file that can be distributed and requires a single step to invoke! I use the “getResource()” and “getResourceAsStream()” methods within a “Class” object to extract files from the jar file. Works real easy.
Here a few of the simple features I have added so far:
- Scriptable
- Display softare version announcement
- Display software license confirmation dialog
- Option to backup any file previous version of files
- User selectable installation directories
- Installation of files into selected directories and sub-directories
- File installation progress dialog
- Installation completion message
This takes care of about 98% of my needs for an IBHome installation solution. The Java classes for the installation process are only a total of 15K bytes. This is an extremely low overhead for the file distribution size.
My Setup:
My computer system is configured to run IBHome at startup. This assures me that the system will restart correctly in case of a power outage.
IBHome has been configured to perform the following tasks:
- Log all captured X10 events and actions performed in event log that is part of main window of IBHome.
- Set HOME or AWAY mode when receiving a defined X10 on/off event.
- Every hour between the hours of 8:00 AM and 10:00 PM. Check for new Email, get the current weather, get the lastest Stock Prices, generate home statistics page, FTP stats page to private web site, then page me with email, weather and stock prices.
- Play a .wav file when someone approaches the front of the house and IBHome is in HOME mode.
- Send a text page when motion is detected in the backyard and IBHome is in AWAY mode.
- Check for email after receiving the configured X10 command from my RF wireless remote and announce new email using text-to-speech.
- Send preconfigured text page informing me to call home after receiving the configured X10 command from my RF wireless remote. This is simple convenience built in for my wife to contact me in case of an emergency.
A lot of the basic timed X10 events and macros that I use are stored directly in the ActiveHome interface itself. It has a large EPROM so I use it to it’s fullest extent.