Complete automation is something that many IT professionals can only dream of. We've managed to automate many of our tasks. We've automated backups, reboots, and many other jobs. But there are other tasks—some beyond the normal duties of IT personnel—that would benefit from automation. These tasks range from simply turning off a light to engaging a security system. Or even a nifty trick that I'm about to show you.
I keep a small reef tank at my home, and I recently discovered that my corals improve when the powerheads (submersible water pumps) in my tank oscillate the current. Eventually, I managed to use my favorite OS (a GPL'd piece of software) and a firecracker module from X-10 to create a very cheap wave-maker for my saltwater reef tank. Now, what does this story have to do with IT? Well, just consider how many applications such automation may hold. (Not to mention the fact that it illustrates the flexibility and cost efficiency of the Linux OS.)
What you need
To pull off this simple automation trick, you only need a few tools. If you have the following items, you can set up your wave system:
- A PC that runs Linux
- BottleRocket software
- An X10 Firecracker setup (including an appliance module and serial port remote) from Smarthome
- A powerhead pump
- A fish tank
Once you've installed the X10 remote plugs into a serial port on your machine, you need to install the BottleRocket software and give your user permission to /dev/ttyS0 (if that's the port into which you've plugged your X10 remote). Installing the BottleRocket software is a very simple process. Download the software into /usr/local and su into root. In root, run the following command:
tar xvzf bottlerocket-current-tar.gz
The above name may change, and the tar command may vary depending on what release you’re installing. Once you've un-tarred the archive, cd into the newly created directory and run the following set of commands:
Now, BottleRocket should be installed. Run BottleRocket only from the command line. It’s very simple. The basic command is divided into three parts:
- The executable command
- The on/off switch
- The device
The executable command is br, and it’s always the same. (Depending on your path, it may be /usr/local/bin/br.) The on/off switch reads -n for “on” and -f for “off.” The device switch will show a number between one and eight; the number corresponds to the setting on the appliance module. To turn on an appliance that’s set to the first device, run:
/usr/local/bin/br -n 1
To turn off that same appliance, run:
/usr/local/bin/br -f 1
The final step in the BottleRocket setup is to give your user permission to use /dev/ttyS0. To assign this permission, run the following command as root (where USERNAME is the Linux username for your system):
chown USERNAME /dev/ttyS0
Once you've run the above command, you’re ready to test your newly configured setup. Plug an appliance, such as a fan, into the module and run the commands that I’ve outlined above. If the fan turns on, you're good to go!
The cron aspect of this setup is a little tricky. I wanted the powerhead to turn on every even minute and turn off every odd minute. Crontab came to my rescue. As the user, open a terminal window and type the following command:
This command will put you in the edit mode of crontab. (When you run the above command, you’ll be thrown into vi.) Once you’re in the edit mode of crontab, you’ll have an empty file that you can fill (unless you've previously created a crontab). First, you’ll want to go into insert mode; press [i]. When you’re in insert mode, type the following lines:
1-59/2 * * * * /usr/local/bin/br —house=B -n 1
0-58/2 * * * * /usr/local/bin/br —house=B -f 1
These lines will turn the device on every even minute and turn it off every odd minute (and 24/7, too). Once you've entered the text, press [Esc] and type the following line in order to write the file and quit vi:
Now that everything is set up and configured, you’ll have to restart the cron daemon (as root) with the following command:
Once the cron daemon has restarted, you should start hearing your appliance module turn on and off.
The major drawback to this system is that it results in a great deal of wear and tear on the X10 modules. The appliance modules use an electric charge to trip a mechanical switch (hence the noise), which wears out over time. Switching a device on and off 1,440 times a day will shorten its lifespan drastically. To avoid this problem, change the crontab so that the device is on for only one minute and off for 12 minutes; using the following code will save you from having to replace the modules every five or six months:
1-59/6 * * * * /usr/local/bin/br —house=B -n 1
0-58/2 * * * * /usr/local/bin/br —house=B -f 1
After you’ve started running this system, you’ll probably draw the same conclusions that I did: With such simple and inexpensive automation, the possibilities are limitless. Do you need random lights to turn on and off in your office to deter possible intruders? Do you need a security system to turn on or off when a guard can’t be present? Or do you need a device or system to shut down or power up at a certain time each day? If you said “yes” to any of these questions, then the above setup will be perfect for you.
Jack Wallen, Jr. is very pleased to have joined the TechRepublic staff as editor in chief of Linux content. Jack was thrown out of the "Window" back in 1995, when he grew tired of the "Blue Screen of Death" and realized that "computing does not equal rebooting." Prior to Jack's headfirst dive into the computer industry, he was a professional actor with film, TV, and Broadway credits. Now, Jack is content with his new position of Linux evangelist. Ladies and gentlemen—the poster boy for the Linux Generation!The authors and editors have taken care in preparation of the content contained herein, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for any damages. Always have a verified backup before making any changes.
Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.