Command and control as easy as RPi

Command and control as easy as RPi

Introduction – dedicated to a specific task

The HVAC system in any house is a great starting point for home automation.  This is commonly used in practically every home in the US.  The heat or air conditioning part my vary from state to state, but the system as a whole remains standard.  Controlling the HVAC system using RPi is a great way to learn the RPi platform and enhance your home.

In this section, we’ll take inputs from thermostats and temperature sensors to control the actions of the RPi.  We’ll continue on by activating fans and heaters based on parameters we set in the RPi.  Next, we’ll read values provided by data sources on the internet to enhance our control actions.  Finally, we’ll wrap up the section by posting out to internet hosts so the public can view the results, without giving them direct access to the critical HVAC system.

You can refer to the RaspberryPiIVBeginners Youtube channel to get an introduction to RPi input and output control.  Matt has done a bang up job.

Purpose – the wheel has already been invented, how can we make it spin with less effort

HVAC control systems have a price range that scale with feature and reliability.  The goals of automation are comfort, cost savings, conscientiousness consumption, and ultimately energy efficiency.   The use of a RPi to handle the ins and outs is a perfect fit in understanding what the RPi can do.  It can help to achieve these goals.

In this example, the RPi will be tasked to do these operations.

  1. Read input from a thermostat or temperature sensor and represent it accurately.
  2. Send an output to control a device , such as a fan, pump, or heater with reliably.
  3. Send data to a network host for it to present on the internet.

Once we have these key functions operating, it will become clear why the RPi is a better choice than a micro controller.  Simple IO and math functions can be handled by micro controllers, but we’re after more.  We’re looking for a better understanding why the system does what it does, so we can make better design choices.

Detail – fitting the RPi in and getting it in the middle of it

Some basic features should be setup on the RPi first.  These are Webmin and Smokeping.  Having Webmin and Smokeping will allow us to troubleshoot much easier if there are issues later on.  We’ll need to install them since they don’t come installed by default, at least with the current Raspian image.  It’s assumed that you have the Raspian OS installed with camera and SSH support enabled, along with XRDP.  We’ll be running the RPi headless, so these will be a requirement.  If you haven’t or that doesn’t make sense, please refer to my earlier post for more details.

Installing Webmin isn’t too much trouble.  These command from a headless SSH connection should get you through the setup.  Once that is done, now you’re ready to view the health and operation of your RPi through a web interface, https://<Your_RPi_IP_Address_Here>:10000/

The Smokeping setup is fairly straightforward.  Here is a post about the setup and config, thank you Bernhard and MyHomeBroadband.  When that is all done, you can access the stats with your web browser, http://<Your_RPi_IP_Address_Here>/cgi-bin/smokeping.cgi

Now that the RPi is ready, lets look at the hardware it will connect to and control.

Thermostats range in price and complexity.  However, the basic operation remains the same on all thermostats.  They change the state of an electrical circuit when a user selected temperature is met or exceeded.  With hysteresis, they delay state changes from occurring too quickly, this protects the controlled hardware from damage due to cycling on and off rapidly.

Thermostats come in 2 flavors when connecting to circuits, low voltage and mains.  Since the RPi would be cooked if connected to mains, we’ll stick with the low voltage circuit variety.

The thermostat will be an input device to the RPi, meaning it will send data in to the RPi to tell it one thing or another.  The signal is binary, either on or off.  This means all we need the RPi to check is the HIGH or LOW state of a GPIO pin.  Find the relay control port on your thermostat, please refer to the documentation of your specific model.  I’ll be using a Honeywell RTHL2310B.  This model has a terminal block on the back of the unit that can connect to wiring.  The manufacturers instructions have details on how to connect the wires, but it’s not clear what port is the actual one to use for the RPi.  So I used a multimeter and found these for each of the operating modes.







Connecting these ports to the RPi isn’t as cumbersome as you might think.  This post on Make shows you some of the basics.  I’m using the older RPi board, so check your pinout for the newer RPi here.  Either way, be sure to connect a 100 ohm resister between ground on the RPI and the thermostat.  Doing this will prevent potential problems if something shorts.  Now onto the output device.

Since the 5 volts coming from the RPi may not be what your furnace, pump, or fan is expecting, we’ll need to match the output with what the thermostat provides.  My thermostat closes a circuit when a set mode is operating, just like it flipping a switch.  So, I’ll need to change my HIGH 5 volt output to a closed circuit.  This is easy to do with a 5 volt relay module, I happen to have one from SainSmart that was used for another project.  This board will be able to handle a 1000 watt heater, nice.

Controlling the relay module couldn’t be simpler.  All I have to do to get it to trigger is connect 5 volts VCC, ground, and output a HIGH on one of the connected GPIO pins to the relay module.  Click, it’s on.  Now that the hardware is all good, let’s delve into the software that will work with the devices.

The RPi has to monitor GPIO pins connected to the thermostat.  Based the state of each INPUT pin, it has to set the pin state on the GPIO OUTPUT pins that control the relay boards connected to the heater or cooling fans.  Basically, it’s going to match the INPUT to the OUTPUT.  Although this will be happening behind the scenes, I would like to have some interface.

Here is where WebIOPi comes into play.

Having a web front end is going to be a must and WebIOPi is up for the task. Adafruit has a nice write up on how to install and operate it.  Once installed, anyone with access can monitor and control the GPIO pins using a web front end.  Be mindful of security, you may not want that control easily available to anyone on the internet.  With that said, it really slices the loaf.

With WebIOPi, we can monitor the INPUT pins that sense state changes coming from the thermostat.  The code then changes the OUTPUT pin state, based on the INPUT pin state.  WebIOPi doesn’t stop there, now we can view the states on a web page.  But wait, there is more.  The WebIOPi framework allows us to use macros, this is great because we can override the thermostat and use values based on any number of possibilities.  One example would be an external temperature sensor reading in another part of the house.  Another example would be a time range we set in the web page when we want it to run or not run.  I would cover the topic in more detail, but it’s beyond the scope of this write up.  You can find more details about it at the WebIOPi macro topic page.

Now that the hardware and software have been hammered out, we’ve covered reading values, writing values, and presenting it all on the internet.  This post has been jam packed with info, most of which can be expanded on into more detail.  For our purposes, we have a good starting point for HVAC automation and control.

Relations – it’s a big world for such a small thing

Since the RPi GPIO features presented in the WebIOPi framework are rooted in the concepts of the IoT, it’s natural to branch out to external websites.  Some websites offer services that will post data readings.  One such website is WeatherSpark.  This site has gathered and re purposed the data gathered from dispersed hosts.  They have done a remarkable job at presenting the data in a clear and structured manner.  However, they aren’t just re purposing data from sources, they also gather data from sites like NOAA.

The technique used is referred to as web scraping.  Sites like NOAA present data that is constantly changing.  Using web scraping allows a third party, such as WeatherSpark, to present that data historically.  We’re in luck because work has been done to allow the RPi to do this too.  BeautifulSoup is a project that leverages python and will run on RPi. 

These tools expand the command and control features that would otherwise not be available to the RPi.

Summary – the limit was imagined, now imagine no limit

The RPi offers several ways to connect to devices.  It also is an excellent platform for controlling devices automatically or from easy to use interfaces.  The GPIO pinout on the RPi is well suited to handle digital and analog signal inputs or outputs.  This allows the RPi to be shimmed between devices that would otherwise not offer any extended control function.

The RPi’s native python language extends the command and control of the GPIO pins.  Using logic and automation scripts allow the RPi to perform some remarkable tasks.  This language also supports seeding and scrapping of web content, which can extend the ability of the RPi well past its design capabilities.  It’s capabilities are defined by imagination not a spec sheet.

The RPi is truly a remarkable device.  The goal in 2006 was to educate those that would otherwise not have access to the knowledge, much like the Arduino effort in 2005 was for micro controllers.  The small affordable computer lab has such a wide support group, it is this that makes the RPi a noble effort.

Comments are closed.