Remote Control for the Heat in a Second Home

We recently experienced the pain and agony of tearing down and rebuilding our summer cottage on Cape Cod.

The old cottage had no insulation, and no heat beyond a simple space heater, so it was necessarily drained each autumn and re-opened the next spring.  Use was limited to maybe five months of the year.

The new cottage is insulated and heated, but, since we don't visit the beach very often in winter, the heat is set only just high enough to prevent the pipes from freezing.  When we do go down to take a winter weekend "away," it takes 8-10 hours to bring the interior up to a comfortable temperature.

What's needed, of course, is a way to turn the heat up before we plan to be there, so the warm-up process can start in our absence.  There are commercially available solutions for this, but I wanted to build my system that would let me call the cottage on the phone and turn the heat on.

Ultimately, the project worked so well, I had to replicate it at home.


In support of this and other requirements (real or imagined), I located an obsolete PC on craigslist for $20, and installed Linux.  I also bought an X100P phone card on eBay for I think $16 with shipping, and installed Asterisk, the open-source telephony software.  A bit of tinkering later, and I have a system that can answer the phone and present the usual voice menu tree with touch-tone navigation (well, maybe not completely usual.)

Furnace Control

The next bit was the hardware to allow the PC to call for heat directly, effectively overriding the regular thermostats.  I thought about building the hardware to do this, but while searching for some advice on-line, I came across this relay board kit that was clearly more nicely executed and for less money than anything I'd work up myself.  The user's guide even included a link to a Linux driver for the board, so I didn't even have to work that out myself.

I assembled the board, and connected two of the relays to operate in parallel with the low-voltage thermostats.  In other words, for each zone, either the PC could call for heat, or the thermostat (or both), and the furnace would fire.

Temperature Sensing

Of course, I needed to incorporate some temperature feedback into the system, or I'd just be guessing at how long the furnace needed to run (constantly on) to bring the temperature up to where we'd want it.  In particular, we didn't want to end up arriving to an 80-degree house on a mild winter day.  Carl's Electronics came to the rescue again, in the form of a temperature "logger" board, along with some extra temperature probes.  The probes are Dallas Semiconductor DS1820 "1-wire" digital thermometers -- they need +5V, ground, and one data wire.  Amazingly, I found some claims that the sensor can operate at the end of wire runs that can be a couple hundred feet in length.  

I ordered the kit, and did some initial experiments at home.  I found that you could get successful operation at the end of a long wire, provided you stuck a capacitor (I had 10 uF, oops, 0.10 uF, small ceramic ones marked "104") across the power rails at the end of the wire, along with the sensor.  (I don't know exactly how long the wire was -- I tested with a partially-used spool of Cat5.)

An added bonus: a normal thermostat only requires two conductors, but are commonly wired with cables having 5, 7, or 8 conductors.  In our case, this practice let me install the DS1820 directly within the existing mechanical thermostats, with only a small amount of dremeling required to the thermostat.  It doesn't get more tidy than that.  (Click picture to enlarge.)


One last issue I had: if the PC that's running at the heart of the system experiences a power failure, it doesn't reboot by itself when power is restored.  After some simple experiments, I determined that applying +5V to one of the leads of the soft power switch would boot the PC if it was off, or power it off if it was running.  Since I was only using two of the eight relays on the relay board, I re-wired one of the relays so that it activated whenever the PC was powered on, and used that to control a 555-based timer circuit that would reboot the system whenever power was available but the system was off.  The timer circuit is powered by a standard always-on +5V output from the power supply.  The result is some untidy splices inside the PC, but I figured if I shorted something, well, the world is full of obsolete, cheap PCs!

Here's a poor picture of the three PCBs (two kits and my timer circuit) attached to the PC.  They're presently tied to a blue plastic box cover using string, but I'll be tidying that up.  The large board is the relay kit, to the right is the temperature logger kit, and on the lower left is my 555-based reboot oscillator.  Also visible are the connections from the temperature logger to the thermostat cables that run up to the two thermostats in the house.


As I mentioned, the system runs Linux, of which I'm a huge fan. It also runs Asterisk, which handles everything related to the phone. The Asterisk dial plan includes this (in a password-protected context):

exten => 41,1,Playback(living-room-temperature-is)
exten => 41,2,agi(saytemp.php|/var/temperature/downstairs)
exten => 41,3,Playback(degrees-fahrenheit)
which invokes this simple PHP script I wrote, to read the temperature value over the phone:
    $f = @fopen($argv[1], "r");
    if ($f)
        if (!feof($f))
            $n = trim(fgets($f));
            echo 'SAY NUMBER '.$n.'""'."\n";


The temperature files (/var/temperature/downstairs, etc.) are populated by a daemon that continuously reads values from the temperature sensor board and writes them to /var/temperature/sensor1, sensor2, etc. After enough cases of forgetting which sensor measured which location, I added symbolic links with useful names, e.g., /var/temperature/downstairs.

I also have another daemon script, thermostat, that wakes up once a minute, checks whether there's a set-point temperature (/var/temperature/setpoint), and, if so, whether either heating zone should be turned on or off. It also appends a line of text to a temperature log file, so I have a minute-by-minute history of the temperatures in the cottage.

Finally, the Asterisk dial plan includes a context (reachable only if you know the pass code, naturally) that allows the caller to dial any desired set point; whatever the caller entered gets written to /var/temperature/setpoint, and within a minute, the thermostat daemon will wake up and act accordingly.

Web Server

After this was all put in place, we put in DSL service (and converted our phone service to VoIP), thanks to a great offer by Galaxy.  We can now access the server directly over the internet.  (See for yourself.)  The webcam was a natural next step, using some X10 remote cameras that I'd bought years ago for looking in on our then-toddlers, and an old Macintosh tuner/capture card I had lying around. (Capturing images from three separate cameras using one capture card takes a little scripting, an X10 CM17A "firecracker" device, and the open-source flipit program.)

Here's the current patch panel and wiring for telephone, DSL, and the LAN.  Hanging by a wire (for now) is the DSL/VoIP gateway.