{"id":1444,"date":"2014-11-14T00:00:04","date_gmt":"2014-11-14T08:00:04","guid":{"rendered":"http:\/\/192.168.3.4\/?p=1444"},"modified":"2018-01-09T06:49:50","modified_gmt":"2018-01-09T14:49:50","slug":"command-and-control-as-easy-as-pi","status":"publish","type":"post","link":"https:\/\/www.cloudacm.com\/?p=1444","title":{"rendered":"Command and control as easy as RPi"},"content":{"rendered":"<p><strong>Introduction &#8211; dedicated to a specific task<\/strong><\/p>\n<p>The HVAC system in any house is a great starting point for home automation. \u00a0This is commonly used in practically every home in the US. \u00a0The heat or air conditioning part my vary from state to state, but the system as a whole remains standard. \u00a0Controlling the <a href=\"http:\/\/www.youtube.com\/watch?v=IbKMQgjUQwk\" target=\"_blank\">HVAC system using RPi<\/a> is a great way to learn the RPi platform and enhance your home.<\/p>\n<p>In this section, we&#8217;ll take inputs from thermostats and temperature sensors to control the actions of the RPi. \u00a0We&#8217;ll continue on by activating fans and heaters based on parameters we set in the RPi. \u00a0Next, we&#8217;ll read values provided by data sources\u00a0on the internet to enhance our control actions. \u00a0Finally, we&#8217;ll wrap up the section by posting out to internet hosts\u00a0so the public can view the results, without giving them direct access to the critical HVAC system.<\/p>\n<p>You can refer to the <a href=\"http:\/\/www.youtube.com\/channel\/UCRAvo5cQWyfog8nRzlf_jWg\" target=\"_blank\">RaspberryPiIVBeginners<\/a> Youtube channel to get an introduction\u00a0to RPi input and output control. \u00a0Matt has done a bang up job.<\/p>\n<p><strong>Purpose &#8211; the wheel has already been invented, how can we make it spin with less effort<\/strong><\/p>\n<p>HVAC\u00a0control systems\u00a0have a price range that scale with feature and reliability. \u00a0The goals\u00a0of automation are comfort, cost savings, conscientiousness consumption, and ultimately\u00a0energy efficiency. \u00a0 The use of a RPi to handle the ins and outs is\u00a0a perfect fit in understanding what the RPi can do. \u00a0It can help to achieve these goals.<\/p>\n<p>In this example, the RPi will be tasked to do these operations.<\/p>\n<ol>\n<li>Read input from a thermostat or\u00a0temperature sensor\u00a0and represent it accurately.<\/li>\n<li>Send an output to control a device , such as a fan, pump, or heater\u00a0with reliably.<\/li>\n<li>Send data to a network host for it to present on the internet.<\/li>\n<\/ol>\n<p>Once we have these key functions operating, it will become clear why the RPi is a better choice than a micro controller. \u00a0Simple IO and math functions can be handled by micro controllers, but we&#8217;re after more. \u00a0We&#8217;re looking for a better understanding why the system does what it does, so we can make better design choices.<\/p>\n<p><strong>Detail &#8211; fitting the RPi in and getting it in the middle of it<\/strong><\/p>\n<p>Some basic features\u00a0should be setup on the RPi first. \u00a0These are <a href=\"http:\/\/www.webmin.com\/\" target=\"_blank\">Webmin<\/a> and <a href=\"http:\/\/oss.oetiker.ch\/smokeping\/\" target=\"_blank\">Smokeping<\/a>. \u00a0Having <a href=\"http:\/\/www.webmin.com\/\" target=\"_blank\">Webmin<\/a> and <a href=\"http:\/\/oss.oetiker.ch\/smokeping\/\" target=\"_blank\">Smokeping<\/a> will allow us to troubleshoot much easier if there are issues later on. \u00a0We&#8217;ll need to install them since they\u00a0don&#8217;t come installed by default, at least with the current Raspian image. \u00a0It&#8217;s assumed that you have the Raspian OS installed with camera and SSH support enabled, along with XRDP. \u00a0We&#8217;ll be running the RPi headless, so these will be a requirement. \u00a0If you haven&#8217;t or that doesn&#8217;t make sense, please refer to <a href=\"http:\/\/192.168.3.4\/?p=1420\" target=\"_blank\">my earlier post<\/a> for more\u00a0details.<\/p>\n<p>Installing Webmin isn&#8217;t too much trouble. \u00a0<a href=\"http:\/\/www.raspberrypi.org\/forums\/viewtopic.php?f=36&amp;t=6096\" target=\"_blank\">These command<\/a> from a headless SSH connection should get you through the setup. \u00a0Once that is done, now you&#8217;re ready to view the health and operation of your RPi through a web interface,\u00a0<em>https:\/\/&lt;Your_RPi_IP_Address_Here&gt;:10000\/<\/em><\/p>\n<p>The Smokeping setup is fairly\u00a0straightforward. \u00a0Here is <a href=\"http:\/\/www.myhomebroadband.com\/the-home-blog\/use-a-raspberry-pi-to-monitor-your-virgin-media-superhub\" target=\"_blank\">a post<\/a> about the setup and config, thank you <a href=\"http:\/\/blog.kugelfish.com\/2014\/10\/why-open-source-software-works.html\" target=\"_blank\">Bernhard<\/a> and MyHomeBroadband.\u00a0 When that is all done, you can access the stats with your web browser,\u00a0<em>http:\/\/&lt;Your_RPi_IP_Address_Here&gt;\/cgi-bin\/smokeping.cgi<\/em><\/p>\n<p>Now that the RPi is ready, lets look at the hardware it will connect to and control.<\/p>\n<p>Thermostats range in price and complexity. \u00a0However, the basic operation remains the same on all thermostats. \u00a0They change the state of an\u00a0electrical circuit when a user selected temperature is met or exceeded. \u00a0With hysteresis, they delay state changes from occurring too quickly, this protects the controlled hardware from damage due to cycling on and off rapidly.<\/p>\n<p>Thermostats come in 2 flavors when connecting to circuits, low voltage and mains. \u00a0Since the RPi would be cooked if connected to mains, we&#8217;ll stick with the low voltage circuit variety.<\/p>\n<p>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. \u00a0The signal is binary, either on or off. \u00a0This means all we need the RPi to check is the HIGH or LOW state of a GPIO pin. \u00a0Find the relay control port on your thermostat, please refer to the documentation of your specific model. \u00a0I&#8217;ll be using a Honeywell\u00a0<span id=\"ctl00_B2CMasterBodyContentPlaceholder_UCProductdetails_TitleText\"><a href=\"http:\/\/yourhome.honeywell.com\/home\/Products\/Thermostats\/5-2-Day-Programmable\/RTHL2310B.htm\" target=\"_blank\">RTHL2310B<\/a>. \u00a0This model has a terminal block on the back of the unit that can connect to wiring. \u00a0The manufacturers instructions have details on how to connect the wires, but it&#8217;s not clear what port is the actual one to use for the RPi. \u00a0So I used a multimeter and found these for each of the operating modes.<\/span><\/p>\n<p><a href=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2014\/11\/ThermostatWiring.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-1479\" src=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2014\/11\/ThermostatWiring.png\" alt=\"ThermostatWiring\" width=\"450\" height=\"183\" srcset=\"https:\/\/www.cloudacm.com\/wp-content\/uploads\/2014\/11\/ThermostatWiring.png 960w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2014\/11\/ThermostatWiring-300x122.png 300w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2014\/11\/ThermostatWiring-100x40.png 100w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2014\/11\/ThermostatWiring-150x61.png 150w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2014\/11\/ThermostatWiring-200x81.png 200w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2014\/11\/ThermostatWiring-450x183.png 450w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2014\/11\/ThermostatWiring-600x244.png 600w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2014\/11\/ThermostatWiring-900x366.png 900w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Connecting these ports to the RPi isn&#8217;t as <a href=\"http:\/\/www.youtube.com\/watch?v=NjNn4bbbgSw\" target=\"_blank\">cumbersome<\/a>\u00a0as <a href=\"http:\/\/www.youtube.com\/watch?v=Mxaj_Kvl9bQ\" target=\"_blank\">you might think<\/a>. \u00a0This <a href=\"http:\/\/makezine.com\/projects\/tutorial-raspberry-pi-gpio-pins-and-python\/\" target=\"_blank\">post<\/a> on Make shows you some of the basics. \u00a0I&#8217;m using the older RPi board, so check your pinout for the newer RPi <a href=\"http:\/\/pi.gadgetoid.com\/pinout\" target=\"_blank\">here<\/a>. \u00a0Either way, be sure to connect a 100 ohm resister between ground on the RPI and the thermostat. \u00a0Doing this will prevent potential problems if something shorts. \u00a0Now onto the output device.<\/p>\n<p>Since the 5 volts coming from the RPi may not be what your furnace, pump, or fan is expecting, we&#8217;ll need to match the output with what the thermostat provides. \u00a0My thermostat closes a circuit when a set mode is operating,\u00a0just like it flipping a switch. \u00a0So, I&#8217;ll need to change my HIGH 5 volt output to a closed circuit. \u00a0This is easy to do with a\u00a05 volt relay module, I happen to have one from <a href=\"http:\/\/www.sainsmart.com\/arduino-compatibles-1\/relay\/arduino-pro-mini-1.html\" target=\"_blank\">SainSmart<\/a> that was used for another project. \u00a0This board will be able to handle a 1000 watt heater, nice.<\/p>\n<p>Controlling the relay module couldn&#8217;t be simpler. \u00a0All I have to do to get it to trigger is connect 5 volts VCC,\u00a0ground, and output a HIGH on one of the connected GPIO pins to the relay module. \u00a0Click, it&#8217;s on. \u00a0Now that the hardware is all good, let&#8217;s delve into the software\u00a0that will work with the devices.<\/p>\n<p>The RPi has to monitor GPIO pins connected to the thermostat. \u00a0Based the state of each INPUT pin, it has to set the pin state on the GPIO OUTPUT pins\u00a0that control the relay boards connected to the\u00a0heater or\u00a0cooling fans.\u00a0 Basically, it&#8217;s going to match the INPUT to the OUTPUT.\u00a0 Although this will be happening behind the scenes, I would like to have some interface.<\/p>\n<p>Here is where <a href=\"https:\/\/code.google.com\/p\/webiopi\/\" target=\"_blank\">WebIOPi<\/a> comes into play.<br \/>\n<iframe loading=\"lazy\" src=\"\/\/www.youtube.com\/embed\/6RaBz01pi4E\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><br \/>\nHaving 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 <a href=\"https:\/\/learn.adafruit.com\/raspberry-pi-garage-door-opener?view=all\" target=\"_blank\">install<\/a>\u00a0and operate it. \u00a0Once installed, anyone with access\u00a0can monitor and control the GPIO pins using a web front end. \u00a0Be mindful of security, you may not want that control easily available to anyone on the internet. \u00a0With that said, it really slices the loaf.<\/p>\n<p>With WebIOPi, we can monitor the INPUT pins that sense state changes coming from the thermostat. \u00a0The code then changes the OUTPUT pin state, based on the INPUT pin state. \u00a0WebIOPi doesn&#8217;t stop there, now we can view the states on a web page. \u00a0But wait, there is more. \u00a0The 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. \u00a0One example would be an external temperature sensor reading in another part of the house. \u00a0Another example would be a time range we set in the web page when we want it to run or not run. \u00a0I would cover the topic in more detail, but it&#8217;s beyond the scope of this write up. \u00a0You can find more details about it at the <a href=\"https:\/\/code.google.com\/p\/webiopi\/wiki\/Tutorial_Macros\" target=\"_blank\">WebIOPi<\/a> macro topic page.<\/p>\n<p>Now that the hardware and software have been hammered out, we&#8217;ve covered reading values, writing values, and presenting it all on the internet. \u00a0This post has been jam packed with info, most of which can be expanded on into more detail. \u00a0For our purposes, we have a good starting point for HVAC automation and control.<\/p>\n<p><strong>Relations &#8211; it&#8217;s a big world for such a small thing<\/strong><\/p>\n<p>Since the RPi GPIO\u00a0features presented in the WebIOPi framework are rooted in the concepts of the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Internet_of_Things\" target=\"_blank\">IoT<\/a>, it&#8217;s natural to branch out to external websites. \u00a0Some websites offer services that will post data readings. \u00a0One such website is\u00a0<a href=\"https:\/\/weatherspark.com\/forecasts\/noaa\/31576\" target=\"_blank\">WeatherSpark<\/a>. \u00a0This site has gathered and re purposed the data gathered from\u00a0dispersed hosts. \u00a0They have done a remarkable job at presenting the data in a clear and structured manner. \u00a0However, they aren&#8217;t just re purposing data from sources, they also gather data from sites like <a href=\"http:\/\/forecast.weather.gov\/MapClick.php?lat=47.62000&amp;lon=-122.36&amp;unit=0&amp;lg=english&amp;FcstType=dwml\" target=\"_blank\">NOAA<\/a>.<\/p>\n<p>The technique used is referred to as <a href=\"http:\/\/en.wikipedia.org\/wiki\/Web_scraping\" target=\"_blank\">web scraping<\/a>. \u00a0Sites like NOAA present data that is constantly changing. \u00a0Using web scraping allows a third party, such as WeatherSpark, to present that data historically. \u00a0We&#8217;re in luck because work has been done to allow the RPi to do this too. \u00a0BeautifulSoup is a project that leverages python and will run on RPi.\u00a0<iframe loading=\"lazy\" src=\"\/\/www.youtube.com\/embed\/x9lXgsGxhVM\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>These tools expand the command and control features that would otherwise not be available to the RPi.<\/p>\n<p><strong>Summary &#8211; the limit was imagined, now imagine no limit<\/strong><\/p>\n<p>The RPi offers several ways to connect to devices. \u00a0It also is an excellent platform for controlling devices automatically or from easy to use interfaces. \u00a0The GPIO pinout on the RPi is well suited to handle digital and analog signal inputs or outputs. \u00a0This allows the RPi to be shimmed between devices that would otherwise not offer any extended control function.<\/p>\n<p>The RPi&#8217;s native python language extends the command and control of the GPIO pins. \u00a0Using logic and automation scripts allow the RPi to perform some remarkable tasks. \u00a0This language also supports seeding and scrapping of web content, which can extend the ability of the RPi well past its design capabilities. \u00a0It&#8217;s capabilities are defined by imagination not a spec sheet.<\/p>\n<p>The RPi is truly a remarkable device. \u00a0The 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. \u00a0The small affordable computer lab has such a wide support group, it is this that makes the RPi a noble effort.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction &#8211; dedicated to a specific task The HVAC system in any house is a great starting point for home automation. \u00a0This is commonly used in practically every home in the US. \u00a0The heat or air conditioning part my vary from state to state, but the system as a whole remains standard. \u00a0Controlling the HVAC system using RPi is a great way to learn the RPi platform and enhance your home. In this section, we&#8217;ll take inputs from thermostats and&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.cloudacm.com\/?p=1444\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,6,3],"tags":[],"class_list":["post-1444","post","type-post","status-publish","format-standard","hentry","category-data-mining","category-raspberry-pi","category-rd"],"_links":{"self":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/1444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1444"}],"version-history":[{"count":65,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/1444\/revisions"}],"predecessor-version":[{"id":1522,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/1444\/revisions\/1522"}],"wp:attachment":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}