{"componentChunkName":"component---src-templates-blog-post-js","path":"/lab-5/","webpackCompilationHash":"f2e780667fa7b13e6baf","result":{"data":{"github_icon":{"childImageSharp":{"fixed":{"base64":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsSAAALEgHS3X78AAACt0lEQVQ4y21UPWtUQRR9b010lURSv5fMZO/EiJ2kiwj+CSOKIRGRWKmNhYKF9lpkU8RCgqKFRT5BsLe201RB4i6oKRUhcb+i587c+94sZuHydmbuOffcj5kkt5Twj7+ZcRX+n1lXxf/Z3LjV3LpGZqmTsxnXhK3B5mCnBJfC13NkJnD5zUR+uaHLcNgZHZ/4ywbCPtN9+HyB71XFYZ0WygoyS08DCQCW/kBFGyRdAL0B1OU9f+bJzzDxYh8pZFaUbKzmHRh8yM6FMg4SqdUz+HYChuqhVFSonIlS2QThFJyWYL9Qzz2sP0PZJ/z/DvuN9Qusp0D6qsTRdZVZBeFOmQI9jFIYx/5IsbZ0GoS1skRuIVL7FWdDaIKb9XUz7mA0pLwkqgdLIsdkSUQ8KD6PGQPCA1F5k2u4KoRdOPSwviQjUOEiw5k7z2o9KchTrTvW52H7wB5KuTY4SkPHAQcfJJVypo74hfMwswi2peOFYLuccgdRuiL5TTys+RGkXqXxSnU66r72lkfLtTgS34JAaN07iZpmkmoutyDsB+XhVum4uddBoZ/TFkds6nzBqQGrCqmmlERdV5Wp3i7gtvkieA5DuxxtLdSPer5jhu5G17CiREqMgL5Rsj+fB2xbSrbJhHN+XKz7AWuKwz3YcUkzvuepjNEA9hew3hdlbWnMLXY6CeYmov3E9wLsrXFnuSZ72HvJgx/VcACgOgeOOtuRL0pHwyr9iqFJ7tRHBBgGcD3UlWTIMY/l7K2M1Sb5rAVcjwnlkZjve7oAeCbKHomakegV4jSPCeF9UdeC+ccBvsta374u4mBRXo9t2HtfE7k1uRIa90DTDfPnnkf4NPmv8NZdA+ibnThXPEtMpgoh4IkhzgSPgaEbEU7JqBxaW4zJCRDcxtlF6WqalaWZBvgOvkP6qGr3meMfi0sXgbOlbzsAAAAASUVORK5CYII=","width":50,"height":50,"src":"/static/b71bc541b323dcd8f0a887920f9670f9/352e5/github-icon.png","srcSet":"/static/b71bc541b323dcd8f0a887920f9670f9/352e5/github-icon.png 1x,\n/static/b71bc541b323dcd8f0a887920f9670f9/aae31/github-icon.png 1.5x,\n/static/b71bc541b323dcd8f0a887920f9670f9/47c2b/github-icon.png 2x"}}},"site":{"siteMetadata":{"title":"Da Post","author":"Matthew Robertson"}},"markdownRemark":{"id":"120eef05-5388-5fe2-a4f8-a5a4c910e325","excerpt":"Objectives The purposes of this lab are to: Install an open source home automation platform Interface this platform via MQTT with your various devices Use Home…","html":"<h3>Objectives</h3>\n<p>The purposes of this lab are to:</p>\n<ul>\n<li>Install an open source home automation platform</li>\n<li>Interface this platform via MQTT with your various devices</li>\n<li>Use Home Assistant to monitor the state of the garage door, and whether the car is parked in the garage. </li>\n</ul>\n<h3>Materials</h3>\n<p>The materials used for this lab were</p>\n<ul>\n<li>Personal computer (MacBook Pro)</li>\n<li>3 x ESP8266 Wemos D1 Mini (Microcontroller)</li>\n<li>3 x USB -> MicroUSB cable for connecting the Microcontroller to the computer</li>\n<li>3 x Breadboard</li>\n<li>1 x Stop light LED component with built in resistors</li>\n<li>1 x Hypersonic distance detector</li>\n<li>1 x Magnetic door sensor</li>\n<li>9 x Male to male jumper cables</li>\n<li>1 x Raspberry Pi 3</li>\n</ul>\n<h3>References</h3>\n<ol>\n<li><a href=\"https://www.arduino.cc/en/Tutorial/BuiltInExamples\">Arduino IDE Examples</a></li>\n<li><a href=\"https://github.com/knolleary/pubsubclient\">PubSubClient Docs</a></li>\n<li><a href=\"https://www.arduino.cc/en/main/software\">Arduino IDE</a></li>\n<li><a href=\"https://www.home-assistant.io/getting-started/\">Install Home Assistant</a></li>\n<li><a href=\"https://unix.stackexchange.com/questions/420640/unable-to-connect-to-any-wifi-with-networkmanager-due-to-error-secrets-were-req\">Connecting Home Assistant to WiFi</a></li>\n<li><a href=\"https://www.home-assistant.io/integrations/ifttt/\">Connecting Home Assistant to IFTTT</a></li>\n</ol>\n<h3>Procedures</h3>\n<ol>\n<li>\n<p>Download Hassio Home Assistant onto the Raspberry pi using the following instructions:</p>\n<ul>\n<li><a href=\"https://www.home-assistant.io/getting-started/\">https://www.home-assistant.io/getting-started/</a></li>\n</ul>\n</li>\n<li>\n<p>Next, you will need to make sure that you set up the network correctly. For me, I wasn’t able to get the suggested USB network configuration file to work. Instead I used the <code class=\"language-text\">nmcli</code> approach.</p>\n<ul>\n<li>First login to hassio with the command <code class=\"language-text\">login</code> after bootup (using root as the username)</li>\n<li>\n<p>Use the following command to see if the ssid you’re going to try and connect to exists</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">nmcli con show</code></pre></div>\n</li>\n<li>\n<p>Use the following command to delete that connection if it exists and make sure that you are starting from scratch</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">nmcli con delete <span class=\"token operator\">&lt;</span>SSID<span class=\"token operator\">></span></code></pre></div>\n</li>\n<li>\n<p>Use the following command to (re)add the new connection</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">nmcli dev wifi connect <span class=\"token operator\">&lt;</span>SSID<span class=\"token operator\">></span> password <span class=\"token operator\">&lt;</span>password<span class=\"token operator\">></span></code></pre></div>\n</li>\n<li>\n<p>Start up the new connection</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">nmcli con up <span class=\"token operator\">&lt;</span>WiFi Name<span class=\"token operator\">></span></code></pre></div>\n</li>\n</ul>\n</li>\n<li>Now you can connect to your new Home Assistant instance at the IP address it has or if you have mDNS discovery on your network you can go to `<a href=\"http://hassio.local:8123\">http://hassio.local:8123</a></li>\n<li>\n<p>Once you are connected to Home Assistance, you need to install the MQTT Add On</p>\n<ul>\n<li>Go to the Hass.io Page and select the Add On tab</li>\n<li>Search for MQTT</li>\n<li>Click on the mosquitto broker and install it</li>\n<li>Go to <code class=\"language-text\">Configuration &gt; Users</code> and add a new username and password for the user that will be used to connect all the ESP-8266</li>\n</ul>\n</li>\n<li>\n<p>Rewrite all of the Arduino code to connect to the new Home Assistant MQTT broker. After you have done this, remove all the logic from the stop-light that decided on what light it should be set to. This logic is going to be moved into home assistant using automations. You will need to add the following line to each of the setup functions of each Arduino.</p>\n<div class=\"gatsby-highlight\" data-language=\"c#\"><pre class=\"language-c#\"><code class=\"language-c#\">client.connect((char*) device_id.c_str(), &quot;[username]&quot;, &quot;[password]&quot;);\nclient.publish(&quot;homeassistant/sensor/garage/[dev_name]/config&quot;, &quot;{\\&quot;name\\&quot;: \\&quot;[Device Name]\\&quot;, \\&quot;state_topic\\&quot;: \\&quot;/[Publish Topic]\\&quot;}&quot;);</code></pre></div>\n</li>\n<li>\n<p>Now that you have all of your devices registering themselves with home assistant you are ready to create your dashboard. You can do this by going to the <code class=\"language-text\">Overview</code> and click the edit button (it is a pencil).</p>\n<ul>\n<li>You will then go to the add FAB at the bottom to add a card. </li>\n<li>Select sensor and select the 3 entities: door, distance-sensor, and stop-light</li>\n<li>Now you will be able to see the state of these three different entities. </li>\n</ul>\n</li>\n<li>Now it’s time to add the logic to actually make the stop light work again. As previously stated, this logic is now going to be in Home Assistant. That means that we are going to need to add a hand full of automations. You should put an automation that will trigger on the mqtt topic of the distance sensor but only if the door sensor is open.</li>\n<li>Once you have these automations up and running, you’ll need to then set up some kind third party automation. I chose to use IFTTT to make it so that I would get a notification if the Garage Door was left open too long. </li>\n<li>\n<p>To set up IFTTT, you need to do the following</p>\n<ul>\n<li>Register with an IFTTT account on <a href=\"https://ifttt.com\">https://ifttt.com</a></li>\n<li>Add webhook Applet and configure it to send a notification on the webhook of the garage door being left open</li>\n<li>Then add an automation in Home Assistant that will hit that webhook on the trigger of the garage door being open for 10s and there is no change in the stoplight. </li>\n</ul>\n</li>\n<li>Now you have a home assistant client that is set up to correctly change a stoplight and will send you a notification if your garage door has been left open for too long.</li>\n</ol>\n<h3>Thought Questions</h3>\n<ol>\n<li>\n<h4>Which version of Home Assistant did you choose to install? (Docker-based Hass.io, Raspbian-based Hassbian, or install it yourself?) Why did you choose this particular version?</h4>\n<p>I used the Raspbian based Hass.io image. I used this because I was familiar with the installation process. I did try the .vhdx of hass.io but it was having some kernal issues when I was installing it with Hyper-V so I changed to the raspberry pi image.</p>\n</li>\n<li>\n<h4>How should you decide which logic to perform in Home Assistant versus coding the logic directly into the devices? What guiding principles would you establish for future devices?</h4>\n<p>In my mind it matters most about how quickly triggers need to cause things to happen in the system. In this case, where the stoplight needs to change super quickly as things change then the logic needs to be close to the stoplight. The stoplight should probably have the logic inside of it so it is the most repsonsive. However, if something doesn’t need to be super responsive the logic can be in Home Assistant or the like.</p>\n</li>\n<li>\n<h4>What features do you like the most about Home Assistant?</h4>\n<p>The feature I like most about home assistant is the automation part. I really like that you can just set arbitrary triggers and have them set something into motion. This seems like it is extremely extendible. I also really like how you can have conditional triggers as well. It makes it so that the integrations can be much larger.</p>\n</li>\n<li>\n<h4>Please estimate the total time you spent on this lab and report.</h4>\n<p>9 hrs</p>\n</li>\n</ol>\n<h3>Certification of Work</h3>\n<p>I certify that the solution presented in this lab represents my own work. In the case where I have borrowed code or ideas from another person, I have provided a link to the author’s work in the references, and included a citation in the comments of my code. </p>\n<p>— Matthew Robertson</p>\n<h3>Appendix</h3>\n<h4>Appendix 1: DIAGRAMS</h4>\n<p>Logical Layout\n<span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto;  max-width: 590px;\"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/00d6621cb5e9afbe37c0b102bb885ca5/c1478/logical-diagram.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 61.87433439829606%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAYAAABiDJ37AAAACXBIWXMAABYlAAAWJQFJUiTwAAABvUlEQVQoz32TzXLTMBDH83g8Bi/Ql+DAEzDDDU4MvTLDob2E6RO0BVpCGuPSOnGciR3Lsmzrw/5XK6E0FBfN7HhntfvbD60nfd+DZBgGBP2pAAO46hExiYQr3FnRZjxmEhSt9R5M569EWiHeMuStcXep0ODS6mNACjDGgDEGzjmEEKjreg/rlMJ2k+FXXuPzb4HpsrEioFyF/f8rJCE4genr27WBTQXeaXyarXEyW2Ea5y7Zsy2HNsNp29Zeett1aXByW2HO9J/bx5EoWz0lPgTvWz6dnmGZrqGkRLbZgFUVdNfizVWFDwuB9z+5G0VRltiR7HauE7IROEAdUFrDj/kComnQdR1KG0C6kh3ezTjefs3xcVFj6A2kVA5Q2YQ0b4JmWebiiDXxc8JIy95eSOB7VqHoeveqw4EQmPwYK9E0wvlPXFBR4Pj1K6yTBMY5MDcG0ge7MlWxhbGj6J88Qpj9+eUt7pP8EZimKY5evkAczd3CNrZdCiDocrXC+cUFVtbncD/3a2VHcPktwU208cBQerSMobR/ydASrRFVn9jK6Tv8U6GHfjm7RhRnHnhY+thehf0Mf9KYeLDXHwCKL6BkUXn2EAAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Logical Layout\"\n        title=\"Logical Layout\"\n        src=\"/static/00d6621cb5e9afbe37c0b102bb885ca5/b9e4f/logical-diagram.png\"\n        srcset=\"/static/00d6621cb5e9afbe37c0b102bb885ca5/cf440/logical-diagram.png 148w,\n/static/00d6621cb5e9afbe37c0b102bb885ca5/d2d38/logical-diagram.png 295w,\n/static/00d6621cb5e9afbe37c0b102bb885ca5/b9e4f/logical-diagram.png 590w,\n/static/00d6621cb5e9afbe37c0b102bb885ca5/f9b6a/logical-diagram.png 885w,\n/static/00d6621cb5e9afbe37c0b102bb885ca5/2d849/logical-diagram.png 1180w,\n/static/00d6621cb5e9afbe37c0b102bb885ca5/c1478/logical-diagram.png 1878w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        loading=\"lazy\"\n      />\n  </a>\n    </span></p>\n<h4>Appendix 2: Code</h4>\n<p>Available on <a href=\"https://github.com/mattrobertson14/it441-home-assistant\">GitHub</a></p>","frontmatter":{"title":"Lab 5 - Home Assistant","date":"December 02, 2019","description":"Lab 5 for IT441. In this lab, Home Assistant is implemented to run the mosquitto broker and run the garage sensors and actors","github_link":"https://github.com/mattrobertson14/it441-home-assistant"}}},"pageContext":{"isCreatedByStatefulCreatePages":false,"slug":"/lab-5/","previous":{"fields":{"slug":"/lab-4/"},"frontmatter":{"title":"Lab 4 - MQTT Event Hub – Garage Door Sensor"}},"next":{"fields":{"slug":"/final-project/"},"frontmatter":{"title":"Final Project - The Morning Routine"}}}}}