{"id":1093,"date":"2017-01-02T08:21:10","date_gmt":"2017-01-02T16:21:10","guid":{"rendered":"https:\/\/partofthething.com\/thoughts\/?p=1093"},"modified":"2017-11-17T21:03:57","modified_gmt":"2017-11-18T05:03:57","slug":"enlighten-your-old-furnace-with-a-raspberry-pi-home-assistant-an-esp8266-and-some-relays","status":"publish","type":"post","link":"https:\/\/partofthething.com\/thoughts\/enlighten-your-old-furnace-with-a-raspberry-pi-home-assistant-an-esp8266-and-some-relays\/","title":{"rendered":"Enlighten your old furnace with a Raspberry Pi, Home Assistant, an ESP8266, and some relays."},"content":{"rendered":"<p>My mom has one of those on\/off furnaces (EDIT: actually it&#8217;s a boiler) that heats up water and circulates it through pipes around the house that have little radiator fins. She wants it to turn on before she wakes up so it&#8217;s not so cold in the morning. In this post, I explain how to turn a normal furnace into a smart furnace controlled by Home Assistant for only a few bucks.<\/p>\n<figure id=\"attachment_1099\" aria-describedby=\"caption-attachment-1099\" style=\"width: 338px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/2017\/01\/hass-furnace.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1099\" src=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/2017\/01\/hass-furnace-169x300.jpg\" width=\"338\" height=\"600\" srcset=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/2017\/01\/hass-furnace-169x300.jpg 169w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/2017\/01\/hass-furnace-768x1365.jpg 768w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/2017\/01\/hass-furnace-576x1024.jpg 576w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/2017\/01\/hass-furnace.jpg 1152w\" sizes=\"auto, (max-width: 338px) 100vw, 338px\" \/><\/a><figcaption id=\"caption-attachment-1099\" class=\"wp-caption-text\">Furnace controls in Home Assistant<\/figcaption><\/figure>\n<p><!--more--><\/p>\n<h1>Starting point<\/h1>\n<p>I already had a Raspberry Pi 3 running <a href=\"https:\/\/home-assistant.io\">Home Assistant <\/a>for some basic home automation stuff around the house (a few lights, cameras, door sensors, temperature, ham radio, motion sensors.. see my earlier posts <a href=\"https:\/\/partofthething.com\/thoughts\/?cat=75\">in this category<\/a>). This can be set up pretty easily. I also have an OpenVPN server installed on the home router (using DD-WRT), allowing easy remote access to the LAN.<\/p>\n<p>The furnace is as simple as it gets. There are like 8 zones each controlled by a two-wire (red and white) Honeywell mercury thermostat.<\/p>\n<figure id=\"attachment_1094\" aria-describedby=\"caption-attachment-1094\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/2017\/01\/thermostat.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1094 size-medium\" src=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/2017\/01\/thermostat-300x283.jpg\" width=\"300\" height=\"283\" srcset=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/2017\/01\/thermostat-300x283.jpg 300w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/2017\/01\/thermostat.jpg 466w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-1094\" class=\"wp-caption-text\">Honeywell Mercury Thermostat<\/figcaption><\/figure>\n<figure id=\"attachment_1095\" aria-describedby=\"caption-attachment-1095\" style=\"width: 1000px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/2017\/01\/furnace.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1095 size-full\" src=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/2017\/01\/furnace.jpg\" width=\"1000\" height=\"750\" srcset=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/2017\/01\/furnace.jpg 1000w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/2017\/01\/furnace-300x225.jpg 300w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/2017\/01\/furnace-768x576.jpg 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/a><figcaption id=\"caption-attachment-1095\" class=\"wp-caption-text\">Furnace<\/figcaption><\/figure>\n<h1>Physically Controlling the Furnace<\/h1>\n<p>When one of these thermostats gets cold, mercury flows downhill and connects the two wires, which are hooked up to a 24V transformer that actuates a water valve (for example, the silver box in upper left of above photo). The water flows and the heat turns on. Again, this system is heat only so it&#8217;s as simple as it gets. To take control of it, all I need to do is be able to control a relay that connects the two wires. I could put a relay and temperature sensor in the wall near each thermostat and run some wires to control them, but it&#8217;s easier for me to put all the relays together by the furnace and rely on wireless temperature sensors.<\/p>\n<p>But how to control the relays? I don&#8217;t want to have a dedicated Pi down there for run a bunch of wires. Enter&#8230; the ESP8266.<\/p>\n<p><iframe loading=\"lazy\" title=\"Home Assistant controlling Relays via MQTT and an ESP8266\" width=\"660\" height=\"371\" src=\"https:\/\/www.youtube.com\/embed\/QqAfbP_PBHU?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>The ESP8266 is an incredible little System-on-a-Chip (SoC) that has a WiFi radio and can be programmed <a href=\"https:\/\/github.com\/esp8266\/Arduino\">just like an Arduino<\/a>. It has libraries ready to go for message passing (MQTT) to tell it when to flip switches, Over-The-Air updating so I can upgrade the system without plugging it into a computer, and tons of other stuff. It also has 16 GPIO pins, many of which are available for the user in most packages. And it&#8217;s just a few bucks! (Note that the <a href=\"https:\/\/espressif.com\/en\/products\/hardware\/esp32\/overview\">ESP32<\/a> just came out that has Bluetooth too). I got one packaged as a Wemos Mini D1 because it came with a USB interface, making it easier to deal with for a few extra dollars.<\/p>\n<figure id=\"attachment_1106\" aria-describedby=\"caption-attachment-1106\" style=\"width: 833px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/2017\/01\/IMG_4829.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1106\" src=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/2017\/01\/IMG_4829.jpg\" alt=\"\" width=\"833\" height=\"577\" srcset=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/2017\/01\/IMG_4829.jpg 833w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/2017\/01\/IMG_4829-300x208.jpg 300w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/2017\/01\/IMG_4829-768x532.jpg 768w\" sizes=\"auto, (max-width: 833px) 100vw, 833px\" \/><\/a><figcaption id=\"caption-attachment-1106\" class=\"wp-caption-text\">Wemos ESP8266 and Relays. USB cable is only for power because data comes over WiFi.<\/figcaption><\/figure>\n<p>On the other end of these relays, we simply patch into the contacts of the red and white thermostat wires from each zone we want to control. The original thermostats stay where they are, and the system reverts to normal old behavior when the relays are off.<\/p>\n<h4>MQTT for communication<\/h4>\n<p>MQTT is perfect for this kind of application. It&#8217;s an <a href=\"http:\/\/www.hivemq.com\/blog\/mqtt-essentials-part-1-introducing-mqtt\">IBM-developed simple messaging protocol<\/a> originally intended to control pipelines and stuff via satellite. It offers publish and subscribe services, which is exactly what we need. The ESP8266 will subscribe to a few topics and turn relays on and off according to what it gets and Home Assistant will publish commands based on user input or automations. MQTT also has a &#8220;last will&#8221; feature where the ESP8266 can tell the broker to send an &#8220;unexpectedly offline&#8221; message if it ever gets disconnected, which I use to send myself an email if the power at home goes out or if something else breaks. The<a href=\"https:\/\/github.com\/knolleary\/pubsubclient\"> PubSub library<\/a> (among others) adds MQTT capabilities to the ESP8266.<\/p>\n<p>I have an external MQTT broker on a server but you can alternatively just use the built-in MQTT server on Home Assistant or install one locally on your LAN. I like the external one because it will tell me if the house goes offline.<\/p>\n<h4>The ESP8266 Code<\/h4>\n<p>My code is <a href=\"https:\/\/partofthething.com\/thoughts\/?p=1096\">posted here<\/a>. It has &#8220;secure&#8221; MQTT (encrypted but not verified), and allows OTA updates from the LAN. Note that there are a lot of things that can go wrong (i.e. the furnace can stay on if this loses connection after it turns on) so use at your own risk! <span style=\"color: #ff0000;\">I assume no liability if this damages your property.<\/span> It should be monitored and adjusted carefully while you work out any kinks.<\/p>\n<h1>Home Assistant configuration for smart furnace<\/h1>\n<p>Home-Assistant does all the User Interface and Intelligence. You just have to configure it. The <a href=\"https:\/\/home-assistant.io\/components\/climate.generic_thermostat\/\">generic_thermostat<\/a> component is perfect for this.<\/p>\n<p>Relevant bits of my configuration are as follows:<\/p>\n<pre class=\"lang:yaml\">mqtt:\r\n\u00a0 broker: !secret remote_server\r\n\u00a0 port: !secret mqtt_port\r\n\u00a0 client_id: mom-ha\r\n\u00a0 keepalive: 60\r\n\u00a0 username: !secret mqtt_user\r\n\u00a0 password: !secret mqtt_pass\r\n\u00a0 certificate: \/etc\/ssl\/certs\/DST_Root_CA_X3.pem\r\n\u00a0 protocol: 3.1\r\n\u00a0 birth_message:\r\n\u00a0\u00a0\u00a0 topic: 'mom\/status\/hass'\r\n\u00a0\u00a0\u00a0 payload: 'online'\r\n\u00a0\u00a0\u00a0 qos: 1\r\n\u00a0\u00a0\u00a0 retain: true\r\n\u00a0 will_message:\r\n\u00a0\u00a0\u00a0 topic: 'mom\/status\/hass'\r\n\u00a0\u00a0\u00a0 payload: 'offline'\r\n\u00a0\u00a0\u00a0 qos: 1\r\n\u00a0\u00a0\u00a0 retain: true\r\n\u00a0\u00a0\u00a0\u00a0 \u00a0\r\nswitch:\r\n\u00a0 - platform: mqtt\r\n\u00a0\u00a0\u00a0 name: Living room heat\r\n\u00a0\u00a0\u00a0 command_topic: \"mom\/furnace\/livingroom\"\r\n\u00a0\u00a0\u00a0 state_topic: \"mom\/furnace\/livingroom\"\r\n\u00a0\u00a0\u00a0 payload_on: \"1\"\r\n\u00a0\u00a0\u00a0 payload_off: \"0\"\r\n\u00a0\u00a0\u00a0 qos: 1\r\n\u00a0\u00a0\u00a0 retain: true\r\n  - [more switches...]\r\n\r\nbinary_sensor:\r\n  - platform: mqtt\r\n\u00a0\u00a0\u00a0 name: \"Furnace\"\r\n\u00a0\u00a0\u00a0 payload_on: '1'\r\n\u00a0\u00a0\u00a0 payload_off: '0'\r\n\u00a0\u00a0\u00a0 state_topic: \"mom\/status\/furnace\"\r\n\u00a0\u00a0\u00a0 sensor_class: connectivity\r\n\u00a0\u00a0\u00a0 \r\nclimate:\r\n - platform: generic_thermostat\r\n   name: Living Room\r\n   heater: switch.living_room_heat\r\n   target_sensor: sensor.multisensor_temperature\r\n   min_cycle_duration:\r\n     minutes: 5\r\n   tolerance: 0.2\r\n   target_temp: 63\r\n   min_temp: 40\r\n   max_temp: 85\r\n\r\n<\/pre>\n<p>With those components in place you just make a few simple automations to turn the heat on in the morning and off at night.<\/p>\n<pre class=\"lang:yaml decode:true\" title=\"Automations\">- alias: Heat on in morning\r\n  trigger:\r\n    platform: time\r\n    at: \"07:15:00\"\r\n  action:\r\n    - service: climate.set_temperature\r\n      data:\r\n        entity_id: climate.living_room\r\n        temperature: 73\r\n  condition:\r\n    condition: and\r\n    conditions:\r\n      - condition: numeric_state\r\n        entity_id: sensor.dark_sky_temperature\r\n        below: '55.0'\r\n      - condition: template\r\n        value_template: '{{ states.climate.living_room.attributes.temperature &lt; 70 }}'\r\n\r\n\r\n- alias: Heat off at night\r\n  trigger:\r\n    platform: time\r\n    at: \"22:30:00\"\r\n  action:\r\n    - service: climate.set_temperature\r\n      data:\r\n        entity_id: climate.living_room\r\n        temperature: 62\r\n  condition:\r\n    condition: and\r\n    conditions:\r\n      - condition: template\r\n        value_template: '{{ states.climate.living_room.attributes.temperature &gt; 68 }}'\r\n<\/pre>\n<p>To get some basic morning pre-heating intelligence going on, this is totally sufficient. Exciting times!<\/p>\n<p>Here it is in action over a day:<\/p>\n<figure id=\"attachment_1506\" aria-describedby=\"caption-attachment-1506\" style=\"width: 713px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/Screenshot-from-2017-11-17-20-03-06.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1506\" src=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/Screenshot-from-2017-11-17-20-03-06.png\" alt=\"\" width=\"713\" height=\"741\" srcset=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/Screenshot-from-2017-11-17-20-03-06.png 713w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/Screenshot-from-2017-11-17-20-03-06-289x300.png 289w\" sizes=\"auto, (max-width: 713px) 100vw, 713px\" \/><\/a><figcaption id=\"caption-attachment-1506\" class=\"wp-caption-text\">Temperature turning on in morning and holding steady all day<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>My mom has one of those on\/off furnaces (EDIT: actually it&#8217;s a boiler) that heats up water and circulates it through pipes around the house that have little radiator fins. She wants it to turn on before she wakes up so it&#8217;s not so cold in the morning. In this post, I explain how to &hellip; <a href=\"https:\/\/partofthething.com\/thoughts\/enlighten-your-old-furnace-with-a-raspberry-pi-home-assistant-an-esp8266-and-some-relays\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Enlighten your old furnace with a Raspberry Pi, Home Assistant, an ESP8266, and some relays.<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[75],"tags":[],"class_list":["post-1093","post","type-post","status-publish","format-standard","hentry","category-home-automation"],"_links":{"self":[{"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/posts\/1093","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/comments?post=1093"}],"version-history":[{"count":10,"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/posts\/1093\/revisions"}],"predecessor-version":[{"id":1507,"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/posts\/1093\/revisions\/1507"}],"wp:attachment":[{"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/media?parent=1093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/categories?post=1093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/tags?post=1093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}