Introduction: Linux: Beginning Home Automation on a Server.

About: Bytesize articles instead of a trilogy in one post.

Linux: beginning home automation on a server.

This is just a quickie proof of concept about using a web server to do home automation remotely. all we will be doing is just turning on some leds, but the blueprint will be there for doing larger things. You do need to have some knowledge of linux and using the command line. You could also use the same idea to control x10 modules or even the Insteon units.

I will not talk about setting up routers and how to open a port to access the server remotely. That is for another instructable. But then you could also use

You need to go to or and build a compatible cable with the led array mentioned in the instructable. This will be attached to your web server.

Update: added a screen shot of html code.
Update: added asm file (lptout.c) separately.

For more info on using insteon see:
Developer kit :
Generating web page tutorials:

You may like this instructable also:

Note: I contacted Insteon about getting a free developer kit to do instructables and help sell their product. They said NO!

Using an Android devcie will make even for more fun.

Step 1: Requirements

Some knowledge of linux.
Linux server running apache2 web server with a standard parallel port.. We are using an old Dell GX1 (Pentium II class).
Have administrative rights.
Have build-essential installed on the server
Knowledge of how to compile a c program.
A second computer or mobile web device to access the server remotely
Parallel port cable with led array attached. (see or
Note: Web page is an internal beta fictional but working site.

Note: Slot 1 pII cpu was swapped out for a slot 1 pIII cpu since the article was originally published.

Step 2: Creating the Parallel Port Controlled Program.

As root you will want to compile the following C program. Normally you would not want to do anything as root directly, but this is an exception.

$ su
# gcc -o lptout lptout.c
# exit
lptout.c (you will need to create this file on the server)
The file is now attached that I used.
 * Simple parallel port output control program for Linux
 * Written and copyright by Tomi Engdahl 1998
 * (e-mail:
 * The program output the data value to PC parallel port data pins
 * (default lpt1 I/O address 0x378). The data values are given as the
 * command line parameter to the program. The number can be
 * in decimal (0..255) or hexadecimal format (0x00..0xFF).

  /* See the attached file for the includes.
/* &#lt; replace with a < symbol and &#gt;  replace with a > symbol */
#include &#lt;stdio.h&#gt;
#include &#lt; stdlib.h&#gt;
#include &#lt60;unistd.h&#gt;
#include &#lt;sys/io.h&#gt;

#define base 0x378           /* printer port base address */

main(int argc, char **argv)
  int value;

  if (argc!=2)
    fprintf(stderr, "Error: Wrong number of arguments. This program needs one argument which is number between 0 and 255.\n"), exit(1);
  if (sscanf(argv[1],"%i",&value)!=1)
    fprintf(stderr, "Error: Parameter is not a number.\n"), exit(1);
  if ((value<0) || (value>255))
    fprintf(stderr, "Error: Invalid numeric value. The parameter number must be between 0 and 255\n"), exit(1);
  if (ioperm(base,1,1))
    fprintf(stderr, "Error: Couldn't get the port at %x\n", base), exit(1);

  outb((unsigned char)value, base);

Update: I included the source file I used separately since wiped part of it.

Step 3: Create Directory and Web Page

Make a directory under your www root.
sudo mkdir /var/www/pport

set permissions and ownership (For Apache2)
sudo chown -R www-data:www-data /var/www/pport
sudo chmod -R 744 /var/www/pport

Create web page (as index.html):
abbreviated version

For some reason this site interpreted the code instead of listing it.

Parallel port controlling test page

Step 4: Set Up Gateway Interface to Access Control Program

Create your cgi file and put it in the cgi-bin directory.

# Parallel port CGI script
# Send HTTP headers
echo Content-type: text/html;charset=ISO-8859
# Do the controlling
/usr/bin/lptout 0xff
# Output web page data
echo "
echo "Parallel port controlled
echo "Go back to controlling page"
echo "

(The instructables editor seems to hide code some times. Look at the picture for the correct code)

Make executable:
sudo chmod +x lpton.cgi

Step 5: Install Control Program.

Move the program lptout to turn on the lights to the /usr/bin/ (Executable code)

Set it to allow it to run on it's own
sudo chmod +s /usr/bin/lptout

Step 6: Final Step

Open up web browser to servername/pport (web server that has the code) (if you put the code on the root of www then you do not have to add the subdirectory.  Careful as you might overight existing code. Might be better to add it as part of a menu in the existing index.html.

Click on appropriate button.
that is it.

Step 7: Php Experiment

Couple of files to play with php. Try at your own risk. You will have to rename them and etc of course

Update: I now also have a MSWindows XP version,

Coming Soon! Teaching your server to get and retrieve tweets from twitter.

Step 8: Coming Soon!

We will be anning an instructable about using an old hp jet direct to the mix. You should be able to control the jet direct from your router using 3rd party firmware without needing a computer.With 3 parallel ports we should be in heaven.\

Step 9: Legacy Rc Control

Old fashioned rc control.

Step 10: General Information

There are many parts to home automation but the main need is to be able to turn something on or off. Without that the rest is meaningless. Let us start with a simple light switch that you can control manually. The off position we will call zero and the on position we will call the one state.

Of course the purpose of home automation is for you not to have to manually turn off or on a switch. So we can get an electronic part known as a switching transistor to do the job for us with the help of a computing device that we can program. These diagrams are way over simplified to make things simpler. We could ask the computer to turn off all the leds with a command like out 888,0 and if any leds were on, they would immediately turn off.

The again, we could issue a command to turn them all on with out 888,255

Then you would want to turn them off and on individually also. Then you would either write some code or have a per-written program to do it for you and have appliances turn on or off at your will. Of course once you have your programming arranged, you can control the leds or any kind of home appliance or anything else at will. That is when interesting things can start happening if you want them to.

In the real world. you probably would not be building any electronics. You could purchase network based control boxes. Most of the devices would be controlled by the time of day or manually controlled like a remote stereo system.

Many single sensors are cause and affect such as a garage door opener where the system waits for the detection of the controller and the proper security sequence. or you could have multiple sensors that work independently but cause the same affect such as a fire alarm or a security system

But let use get a bit more sophisticated. you could add a variety of sensors, but the most common might be the temperature sensor for control of your heating cooling system. The same idea could probably be adapted to a sous vide cooking system.

Now things have become a bit more complicated with additional sensors and control devices required. Also requires more complicated programming. You can see where systems can become very expensive.

We have only scratched the surface when it comes to sensors. That is part 1 for now,

Step 11: More General Information.

When it comes to home automation, you could use any number of systems
such as a off the shelf turnkey solution such as Insteon.Check with your hardware store for more details. You could build it yourself. Unless you are experienced at it, I would let a professional do it, if for no other reason of safety to yourself and others. If you do do it yourself, you will have to write the software to make it all happen. Though most of it may not be that hard, it can be daunting to the inexperienced. Again get a professional and a mentor. Also any drawings in this article are oversimplified and not to be used in actual systems. What to do first? You want to make a plan of what you want to do including any budget considerations. (What is it going to cost?)

Home Automation – Requirements Checklist

Functional Areas:


Standalone time-based controllers

Remote infrared or wireless (RF) controllers

Local PC only

Local PC w/Internet access enabled

Optional telephone interface for status and control

Security & Monitoring

Alarm System Integration

Standalone system with outputs

Standalone system with auxiliary inputs/outputs

Custom Alarm System

Motion detectors (people or vehicles)

Security cameras (archive motion triggered video clips)

Zone intrusion detectors (infrared)

Local siren alarm

Alerts (pager or email or dial-out)

Door/Window/Gate open sensor

Barking dog deterrent

Flood lights

Activity Monitoring

Cameras to monitor children or pets

Pet feeders, pet doors, automatic cleaners, pet containment

Electronic door latches

Activity logs

Disaster Recovery

Sensors: water level, extreme temperatures, wind, smoke, rain

Alerts (pager or email or emergency dial-out)

Scene Lighting

Everyday after dark lighting scheme

Night time pathway lighting

Event lighting scenes (parties, dining, mood settings)

Dusk/Dawn sensor or calculation from latitude & longitude

Motion triggered lights (i.e. front porch, backyard, interior rooms)

Vacation schedule after dark lighting scheme with auto-variance

Home Entertainment (A/V) Controls

Room lighting: control drapes, blinds, dimmers

Device power up sequence and configuration

Play selection (CD, DVD, VHS, Cable, Satellite, Media PC)

Channel/volume control

DVD/VCR/DVR control (play, pause, stop rewind, fast forward, eject)

General control

Single control –simplified (macro commands)

Remote programming control from the Internet (e.g. TIVO or other DVR)

Home HVAC Controls

Heating and cooling based on single/multiple internal thermostats

Set Heating/Cooling temperature targets via program

Control HVAC mode (Auto, Heating, Cooling, Off)

Ceiling fan controls

Send status on demand or periodic reports

Monitor pool/spa water temperature

Control window shades to lower room temperature


Surveillance Cameras

Stationary cameras with video cable plugs into TV or computer webcam

Pan/Tilt/Zoom (PTZ) cameras (hard-wired or wireless)

Continuous recording of video capture on motion detection

Remote viewing from the Internet (live stream or capture files)


Sprinkler controls (rain detection shut off)

Integrate custom systems (requires computer interface)

Appliance controls (electrical water heater, other)

Integrated Pool/Spa controls

It is apparent, you will need to do some research, not only potential products but, doing some price research. We will go into the above in more detail at a later time.

Now you do not have to implement everything, Maybe even one item is all you need. Now that we have that out of the way, Lets go back to the discussion. Last time we said that home automation is basically being able to turn something on or off remotely. Let us refine that a little bit. We actually need something to be controlled, a device to do the controlling, and an interface to oversee the controlling.

Something to be controlled can be digital such as on or off like a light switch. That is pretty easy. In some cases though, we need to be able to adjust a device to a certain level and that is analog sort of like measuring with a ruler, light dimmer switch or even with a thermometer.

We need a way to control devices based on a pre-setup instructions which may or many not be dependent on the time of day or feedback from sensor devices, We can send a signal to turn on an electronic switch as if you just simply turned on light switch or we could use an electronic valve like on a water faucet to adjust those things that are analog. For example you may want to dim or brighten a lamp. We use a stepper motor that can turn in increments in two directions to adjust a light dimmer switch. This would be as if you were turning the knob on the dimmer. Of course you will want a light sensor to get feedback on how the lamp is doing.

If you build it yourself, you can use everything from a microcontroller such as the Arduino to a full fledged computer. The system will need to be able to output the current status and let you change it if need be. For a computer you will need to have some kind of web server installed. The Arduino has a simple interface to be able to ouput to the web if the ethernet shield is attached.

So now you have remote control via a simple web page. Next time we will spend some time in the big long list at the start of the article.