I’ve been building my home automation system for years and have achieved extensive lighting, climate, entertainment, security and entry control. Never satisfied, I’m forever pondering potential refinements that would enhance the overall effectiveness and capability of my system. I recently concluded that one of those refinements would involve automating the control of the natural-gas fireplaces in my home.

Let me interject here that one should exercise EXTREME caution before deciding to implement any kind of automated home controls such as those I will outline below!

The key to gaining control of a fireplace is to have some kind of automated ignition system. In my case, I had Skytech remote control systems installed on each fireplace when I built our home. This system makes starting and terminating a fire as simple as pressing a button.

Why
As I’ve built my home automation system, I have focused on centralization and ease of control. Most of the house can be managed through a central console, but the interface is also accessible from a myriad of other devices throughout the house. My motivation was to get rid of the “ugly” Skytech remotes and incorporate control of the fireplaces into the central control system. This is not only more elegant than the current system, it, more importantly, allows me to incorporate the fireplaces into my HA scenes. Another reason for implementing automated control of the fireplaces is safety. Imagine, if you will, that one of my children are the last to leave the house for the day and forgets to turn off a fireplace. With centralized control, the HA system can now automatically turn off all fireplaces when it senses that the house is empty or when the security system is engaged. Another scenario would be to automatically shut-off the fireplaces if the HA system senses a structure fire or if high levels of carbon monoxide are detected.

The Plan
Since I’ll replace the every-day use of the fireplace remotes with my centralized control system, I thought the easiest way to accomplish my goal was to use an Arduino and a couple of reed relays to simulate button presses on the remote.

Circuit Schematic

Circuit Schematic

Since my goal is to automate control, I decided to use an Ethernet Shield so I could make a simple URL call to turn a fireplace on and another call to turn a fireplace off.

The schematic above shows what I actually implemented.

The parts

  1. Breadboard
  2. 1 x Arduino Uno
  3. 1 x Ethernet Shield
  4. 2 x Reed Relays
  5. Spool of solid 22 AWG wire

The relays I had on-hand were NTE Electronics SPST NO R56-1D.5-6D, although the on-board diode contained in this model is unnecessary, these would work just fine for this application.

The Implementation
The key to accomplishing our goal is to open the remote and locate the buttons. In this case, the buttons are mini push button switches. I then turned the PCB over and located the pads for both the ON button and the OFF button. Once I knew where I needed to connect my relays, I then set up my soldering iron and proceeded to connect a six inch lead to two pads on each button and then put the remote unit back together.

Next I wired up my circuit:

ON Relay

  • Arduino PIN2 to relay PIN2
  • Arduino GRD to relay PIN6
  • Relay PIN1 to remote ON lead
  • Relay PIN7 to remote ON lead

OFF Relay

  • Arduino PIN3 to relay PIN2
  • Arduino GRD to relay PIN6
  • Relay PIN1 to remote OFF lead
  • Relay PIN7 to remote OFF lead

Now we need software to drive the circuit. The simple sketch below will tell the Arduino to engage our ON button relay, which should turn the fireplace on when 192.168.1.10/?RELAY=1 is called from an external application. Calling 192.168.1.10/?RELAY=2 will tell the Arduino to fire the off relay, which should turn the fireplace off.

#include <SPI.h>
#include <Ethernet.h>

// MAC address from Ethernet shield sticker under board
byte mac[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
IPAddress ip(192, 168, 1, 10); // IP address, may need to change depending on network
EthernetServer server(80);  // create a server at port 80

String HTTP_req;          // stores the HTTP request

void setup()
{
    Ethernet.begin(mac, ip);  // initialize Ethernet device
    server.begin();           // start to listen for clients
    Serial.begin(9600);       // for diagnostics
    pinMode(2, OUTPUT);       // relay on pin 2
    pinMode(3, OUTPUT);       // relay on pin 3
}

void loop()
{
      EthernetClient client = server.available();  // try to get client

    if (client) {  // got client?
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {   // client data available to read
                char c = client.read(); // read 1 byte (character) from client
                HTTP_req += c;  // save the HTTP request 1 char at a time
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' && currentLineIsBlank) {
                    // send a standard http response header
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println("Connection: close");
                    client.println();
                    // send web page
                    ProcessRequest(client);
                    Serial.print(HTTP_req);
                    HTTP_req = "";    // finished with request, empty string
                    break;
                }
                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                } 
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
            } // end if (client.available())
        } // end while (client.connected())
        delay(1);      // give the web browser time to receive the data
        client.stop(); // close the connection
    } // end if (client)

}

// process request
void ProcessRequest(EthernetClient cl)
{
    if (HTTP_req.indexOf("RELAY=1") > -1) {  // see if request is for the ON relay
        digitalWrite(2, HIGH);
        delay(1500);
        digitalWrite(2, LOW);
        cl.println("1");
    }
    
    if (HTTP_req.indexOf("RELAY=2") > -1) {  // see if request is for OFF relay
        digitalWrite(3, HIGH);
        delay(1500);
        digitalWrite(3, LOW);
        cl.println("2");
    }
}

That’s it!

If you have more than one fireplace, just add additional relays and modify the sketch accordingly.

Conclusion
This method worked like a charm! I didn’t have to remove the fascia from the fireplaces themselves to access and modify the electronic valve control system. This method also leaves the remotes fully functional even though they have a tethered connection to the Arduino. This allows me to use the remote to start a fire even if there is a power failure in the house and the HA system is inaccessible.

Last but not least, another benefit of this implementation approach is the fact that there is no permanent damage. When I decide to sell my home, I’ll just snip the leads off of each remote and the new owners can use the remotes the “old fashioned” way!

Until next time – GEEK OUT!

~GT~

 

When we receive a first-time visitor to our home they ALWAYS ask about the whole-home control panel mounted in our family room. This panel allows us to control and obtain status on just about every aspect of our house from a single location.  This, invariably, leads to questions about what my Home Automation (HA) system can do.

While not an exhaustive list, following are some of the features I’ve integrated so far:

  • Turn on the lights in the house when arriving home after dark and nobody is home
  • Announce when the garage door opens
  • Notify me and the police if the alarm is tripped
  • Notify me if a motion detector is activated and the house is in AWAY mode
  • Notify me when the alarm state changes (enabled / disabled)
  • Display the alarm status (set / not set) on keypads throughout the house
  • Display garage door status (open / closed) on keypads throughout the house
  • Open / Close the garage door from keypads throughout the house
  • Turn on / off porch lights with the setting / rising of the sun
  • Log upstairs and downstairs temperature and humidity
  • Log incoming and outgoing phone calls
  • Control alarm, fans, lights and thermostats from a central command console
  • Control alarm, fans, lights and thermostats from an iphone / iPad
  • Control alarm, fans, lights and thermostats via SMS
  • Control alarm, fans, lights and thermostats via IR
  • Display incoming caller information on TV
  • Log all motion activity
  • Control household music library and radio stations from central command console
  • Play household music library and radio stations on audio zones throughout the house
  • Notify me when one or more Printer Ink cartridges need to be replaced
  • Display on command console
    • Replace air filters
    • Add salt to softener system
    • Purge water system
    • Printer Ink Cartridge Levels
    • Motion in zones throughout the house
    • Who is home
    • Garage Door status
    • Alarm status
    • Voicemail status
  • Lights Out timer for my daughter (10 / 30 / 60 min intervals)
  • Panic Mode – all lights on instantly
  • Sleep Mode – all lights off instantly
  • Notify me when a HA device needs attention (battery replacement, etc)
  • Backup offsite server data (Wiki / Mail / etc)
  • Automatically filter all internet traffic
  • Notify me when power fails

Developing all of this capability over the years means the inter-workings of my HA system have become increasingly complex.  This is most evident when something ceases to function correctly and I have to jump in and troubleshoot the problem.  As the system grew I started documenting the details in a wiki which has proved invaluable for troubleshooting. I also found it helpful to maintain a high-level visual overview of my network and data flow.

Since these are areas that are the subject of so many of the questions that I receive, I thought I would post some images to give you some inspiration on how you might architect your own HA system.

Until next time – GEEK OUT!

~GT~

   

 

If you tinker with technology then chances are you already know what the “Internet of Things” is all about. If you don’t know, then my question to you is, where have you been!?

For those of you not in the know, here’s a quick primer.

“The Internet of Things is a network of Internet-enabled objects, together with web services that interact with these objects. Underlying the Internet of Things are technologies such as RFID (radio frequency identification), sensors, and smartphones.”[1] 

One way that folks put this concept into practice is the set up their “things” so they, like their owners, can update their status.  I like to think of it as Twitter for my stuff.  One site that gives your devices a place to update their status information is called Pachube (pronounced “PATCH-bay” [2]).  I’ve been using Pachube for a couple of years to report health data from my servers but I’ve been wanting to experiment with building a microcontroller based stand-alone device that could use sensors to gather environmental data and then report that data to Pachube without the need for a computer.

A microcontroller (in this context) is a pre-built device consisting of circuitry on a single printed circuit board (PCB) such as microprocessor, I/O circuits, clock generator, RAM, stored program memory, etc. The idea behind the microcontroller is that it is immediately available and useful to an application developer, without needing to spend time and effort in developing the controller board itself [3].

In the case of an Arduino, however, the idea is to make it easy to prototype solutions by building your own circuits and devices and proving them before committing your device to a PCB of it’s own or going into large-scale production

There are lots of microcontrollers on the market such as the Arduino, BASIC Stamp and others. I’ve been reading about the Open-Source Arduino Platfrom for a long time and had been looking for an excuse to buy one and expirament. To get my feet wet, I decided to buy the latest Arduino board, some photocells, a nice selection of resistors, and a simple breadboard.

Building The Circuit

When I received the parts, my first task was to build a very simple circuit. Since a photocell is basically a resistor, the easiest way to get a measurement was to connect one end to 5V and the other to a pull-down resistor to ground. Now all I had to do was make a connection from analog input to the point between the fixed pull-down resistor and the photocell.

Now we have a complete circuit and should be able to build a simple sketch (firmware program) to read the data and pump it to our serial port.

  Ldr

Writing The Sketch

In Arduino parlance, a sketch refers to the program that is written and uploaded to the ATMega chip (aka the firmware) that tells the Arduino what to do.

The easiest way to get up and going is to download the Arduino IDE from the Arduino website.  The IDE makes it easy to compile and upload our code and at this point, easy is what we want.

int ldrPin = 0;
void setup() {
Serial.begin(9600);
}
void loop () {
Serial.println(analogRead(ldrPin)/204.8);
delay(1500);
}

Our sketch is very simple.  We start by defining the location of our photocell which in this case is Pin 0. We then open the serial port at 9600 baud and then start a perpetual loop that reads the voltage from the photocell, waits 1500 milliseconds (1.5 seconds) and then sends the result to the serial port.

When we read the analog port the value that is returned is a value between 0, representing zero volts, and 1024, representing five volts. I could easily use that number but I want to convert the number to actual voltage which I do by dividing the value returned by the analogRead function by 204.8.

Reading and Posting

As I stated in my opening, the goal with the Arduino is to have a stand-alone device that can post data to Pachube (or anywhere for that matter) independently.  Since we’re just experimenting with the fundamentals, in this instance, we’ll leave our Arduino connected to the computer to read the data and then post it.

On my Mac I opened a Terminal session and navigated to /dev to look for the device name of the Arduino.  In my case it’s cu.usbmodem621. To validate that we’re getting data, I opened a read-only connection to see what I would get (be sure to close the Arduino IDE first).

cat /dev/cu.usbmodem621

If you receive a value on a new line every 1.5 seconds then everything is functioning correctly.  Since I’ve been using Pachube for a while, I already have my API Key which is necessary to programmatically update the Pachube feed.  If you don’t have an account already, go to pachube.com, set one up and grab your API Key.

Now that we know our device name, know that we’re getting data and have our Pachube API Key, we can now write our script.

You can use any scripting language to accomplish the task of reading serial data from the Arduino and then making the necessary calls to post the data.  My preference is PHP, so that’s what I’ll use here.

#!/usr/bin/php -q
<?php
$handle = fopen("/dev/cu.usbmodem621","r");
$str_ldr = fgets($handle);
sleep(5);
$mintime = time();
do{
$str_ldr = fgets($handle);
$str_ldr = trim( preg_replace( '/s+/', ' ', $str_ldr ) );
if( time()> $mintime+60) {
echo $str_ldr . "n";
echo exec("curl --request PUT --header "X-PachubeApiKey: 11112222333344445555566666777778888899999" --data "$str_ldr" "http://www.pachube.com/api/00000.csv" --silent");
$mintime = time();
}
}while(1);
fclose($handle);
?>;

First thing we do is open a connection to the Arduino and read in some data and then wait for 5 seconds. You may have noticed that the first line of data you get from the device after you open a fresh connection is not always clean. Using this method allows the connection to “settle” before we start grabbing data to post.

Next we start an infinite loop to grab a line of data, strip the CRLF, call out to cURL to post our data, wait 60 seconds and then do it all over again.

The image below shows a Pachube 24h graph.

Pachube Graph

Conclusion

I was surprised how easy it was to prototype with the Arduino and to have a working solution up and running with so little effort. My next goal will be to add new sensors to extend my home automation system (track real-time electricity, gas and water usage) and then add an Ethernet Shield to remove the need for a computer to post my data.

Until next time – GEEK OUT!!

~GT~

   

© 2012 Geek-Tips Suffusion theme by Sayontan Sinha