{"id":117,"date":"2020-11-19T21:36:20","date_gmt":"2020-11-19T21:36:20","guid":{"rendered":"http:\/\/garett-cook.com\/?p=117"},"modified":"2022-05-19T03:20:50","modified_gmt":"2022-05-19T03:20:50","slug":"smart-garage-dashboard","status":"publish","type":"post","link":"https:\/\/garett-cook.com\/index.php\/2020\/11\/19\/smart-garage-dashboard\/","title":{"rendered":"Smart Garage Dashboard"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.cuttingedgeservices.co.uk\/wp\/wp-content\/uploads\/2018\/11\/bigstock-194078320-1024x514.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p>With the number of IOT devices ever increasing, having an easy to use dashboard to both control and visualize the states of IOT devices is an extremely valuable piece to have in any embedded system. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Application<\/h2>\n\n\n\n<p>IOT devices are powerful but not intuitive to use for the average consumer. Creating a dashboard allows the average joe to take full advantage of these devices. For example using a dashboard an average joe can control an IOT security system installed in their house and see whether the doors are locked or potentially lock all the doors in the house at curfew so that teenagers who come home late have to sleep in the garage (true story). <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Materials<\/h2>\n\n\n\n<p>To complete this lab, you will need the following materials:<\/p>\n\n\n\n<p>\u00b7&nbsp; &nbsp; &nbsp; &nbsp; A Raspberry Pi with a bootable SD card<\/p>\n\n\n\n<p>\u00b7&nbsp; &nbsp; &nbsp; &nbsp; A Raspberry Pi power supply<\/p>\n\n\n\n<p>\u00b7&nbsp; &nbsp; &nbsp; &nbsp; A computer with a SD card reader and a MQTT broker installed<\/p>\n\n\n\n<p>\u00b7&nbsp; &nbsp; &nbsp; &nbsp; The three Arduino devices made in <a href=\"http:\/\/aaronnelson95.com\/IT441Lab4.php\">Lab 4<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">References<\/h2>\n\n\n\n<p>The following links may be helpful to compelte this tutorial:<\/p>\n\n\n\n<p>\u00b7&nbsp; &nbsp; &nbsp; &nbsp; <a href=\"http:\/\/aaronnelson95.com\/IT441Lab4.php\">http:\/\/aaronnelson95.com\/IT441Lab4.php<\/a> &#8211; Lab 4 Instructions on how to set up the Mosquitto MQTT broker on a computer and how to develop 3 Arduino devices to communicate with MQTT<\/p>\n\n\n\n<p>\u00b7&nbsp; &nbsp; &nbsp; &nbsp; <a href=\"https:\/\/www.home-assistant.io\/docs\/installation\/hassbian\/installation\/\">https:\/\/www.home-assistant.io\/docs\/installation\/hassbian\/installation\/<\/a> &#8211; Steps on how to install Hassbian on a Raspberry Pi (as well as a link to the latest Hassbian image)<\/p>\n\n\n\n<p>\u00b7&nbsp; &nbsp; &nbsp; &nbsp; <a href=\"https:\/\/www.juanmtech.com\/install-home-assistant-simple-steps\/\">https:\/\/www.juanmtech.com\/install-home-assistant-simple-steps\/<\/a> &#8211; Another helpful guide on installing Hassbian. This one includes more information about personally configuring the image and gaining access to it<\/p>\n\n\n\n<p>\u00b7&nbsp; &nbsp; &nbsp; &nbsp; <a href=\"https:\/\/www.home-assistant.io\/integrations\/switch.mqtt\/\">https:\/\/www.home-assistant.io\/integrations\/switch.mqtt\/<\/a> &#8211; Adding MQTT capabilities to Home Assistant<\/p>\n\n\n\n<p>\u00b7&nbsp; &nbsp; &nbsp; &nbsp; <a href=\"https:\/\/www.home-assistant.io\/docs\/configuration\/devices\/\">https:\/\/www.home-assistant.io\/docs\/configuration\/devices\/<\/a> &#8211; Saving MQTT topics as sensors in Home Assistant<\/p>\n\n\n\n<p>\u00b7&nbsp; &nbsp; &nbsp; &nbsp; <a href=\"https:\/\/www.home-assistant.io\/integrations\/template\/\">https:\/\/www.home-assistant.io\/integrations\/template\/<\/a> &#8211; Working with templates to alter the way MQTT values are written<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Procedures (TAKEN FROM AaronNeilson95.com)&nbsp;<\/h2>\n\n\n\n<p>1.&nbsp; &nbsp; &nbsp; Setup the Door Opener, Echo Sensor, and Stoplight devices from <a href=\"http:\/\/aaronnelson95.com\/IT441Lab4.php\">Lab 4<\/a>. In addition, you should have a Mosquitto MQTT server running. Verify that these devices work together and that they publish data to the following MQTT topics. This information will be used and read by Home Assistant:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Topic<\/strong><\/td><td><strong>Message<\/strong><\/td><td><strong>Description<\/strong><\/td><td><strong>Published By<\/strong><\/td><td><strong>Subscribed By<\/strong><\/td><\/tr><tr><td><strong>device\/doorSwitch<\/strong><\/td><td>Activated<\/td><td>Device came online<\/td><td>Door Opener<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>device\/echoSensor<\/strong><\/td><td>Activated<\/td><td>Device came Online<\/td><td>Echo Sensor<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>device\/stoplight<\/strong><\/td><td>Activated<\/td><td>Device came online<\/td><td>Stoplight<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>garage\/doorSwitch<\/strong><\/td><td>0<\/td><td>Magnets are disconnected<\/td><td>Door Opener<\/td><td>Echo Sensor<\/td><\/tr><tr><td>1<\/td><td>Magnets are connected<\/td><\/tr><tr><td><strong>garage\/echoSwitch\/color<\/strong><\/td><td>g<\/td><td>Distance read is &gt; 35cm<\/td><td>Echo Sensor<\/td><td>Stoplight<\/td><\/tr><tr><td>y<\/td><td>Distance read is 20-35cm<\/td><\/tr><tr><td>r<\/td><td>Distance read is 10-20cm<\/td><\/tr><tr><td>b<\/td><td>Distance read is 0-10cm<\/td><\/tr><tr><td>o<\/td><td>Received \u201c0\u201d from garage\/doorSwitch<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>2.&nbsp; &nbsp; &nbsp; Install the Hassbian operating system by following the instructions at <a href=\"https:\/\/www.home-assistant.io\/docs\/installation\/hassbian\/installation\/\">https:\/\/www.home-assistant.io\/docs\/installation\/hassbian\/installation\/<\/a>.<\/p>\n\n\n\n<p>a.&nbsp; &nbsp; &nbsp; Download the latest Hassbian image and flash the image onto an empty SD card.<\/p>\n\n\n\n<p>b.&nbsp; &nbsp; &nbsp; Insert the card into a Raspberry Pi and either plug it into a monitor with a keyboard and ethernet cable or configure your Pi\u2019s wireless network by altering a file in the boot partition (as explained in the guide).<\/p>\n\n\n\n<p>c. &nbsp; &nbsp; &nbsp; Wait several minutes for the latest version of Home Assistant to be installed. When prompted, you can login to Hassbian with the default username of \u201cpi\u201d and password of \u201craspberry\u201d (or you can SSH right into the Pi with its IP address if you are doing this without extra peripherals). When the installation is finished, you should be able to see some files populated in \u201c\/home\/homeassistant\/.homeassistant\/\u201d.<\/p>\n\n\n\n<p>d.&nbsp; &nbsp; &nbsp; Type in \u201c$ sudo raspi-config\u201d to change the default password. You can also add a wifi network here and adjust other settings. If you would like to set multiple wifi networks for your device (I would highly recommend running it off of a hotspot hosted by the same computer your MQTT server is on), you can set those in the \u201c\/etc\/wpa_supplicant\/wpa_supplicant.conf\u201d file.<\/p>\n\n\n\n<p>e.&nbsp; &nbsp; &nbsp; Using a device on the network, open a web browser and go to \u201chttp:\/\/&lt;YOUR_PI_IP_ADDRESS&gt;:8123\u201d. If Home Assistant appears, set an initial account up to log in with. If it does not appear, follow the troubleshooting steps in the Home Assistant instruction guide. Once you are in, you should see the main Home Assistant page, where you will add cards to for monitoring MQTT data.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/EF85bLH1u8tgH7dynBdfZqQDIy7p1NpaZqg8_TFyU-NeubE2jA-pXF49ucWji6wr_KNmGASFreUFXOisGp8f9XXLETIwUC0VXtM5hWXqqmN4RyaD7nB38VdHXXdzwjgv7BRnXKUl\" alt=\"\"\/><\/figure>\n\n\n\n<p><em>Seeing the Home Assistant page come up is an indication that the installation worked<\/em><\/p>\n\n\n\n<p>3.&nbsp; &nbsp; &nbsp; Add the MQTT Integration to Home Assistant to be able to work with your Mosquitto Server. This can either be done through the UI, or by editing the configuration yaml file for Home Assistant. Change this file with the command \u201c$ sudo nano \/home\/homeassistant\/.homeassistant\/configuration.yaml\u201d (we will be editing this file frequently throughout the lab). Simply insert the code below to connect to Mosquitto hosted at your Mosquitto server\u2019s IP:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td># Sets up the MQTT broker, which in this case is my computer&#8217;s Mosquitto server<strong>mqtt<\/strong>: # The IP of the Mosquitto server<strong>&nbsp;&nbsp;broker<\/strong>: 192.168.137.1 # What the Home Assistant client should check in as<strong>&nbsp;&nbsp;client_id<\/strong>: homeassistant&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&nbsp;&nbsp;discovery<\/strong>:<strong> true<\/strong> # The MQTT Topic to watch (subscribe to)<strong>&nbsp;&nbsp;discovery_prefix<\/strong>: garage&nbsp;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Afterwards, restart home assistant with the command \u201c$ sudo service home-assistant@homeassistant restart\u201d (this will also be done frequently, so memorize this command!). In the browser, under the Configuration tab and then Integrations, you should now see a listing for \u201cMQTT: configuration.yaml\u201d. You can test that this works by going to the Developer Tools tab, selecting MQTT, and then listen to the topic \u201c#\u201d, which should then populate when you use your Arduino devices.<\/p>\n\n\n\n<p>4.&nbsp; &nbsp; &nbsp; Now that Home Assistant is connected to the MQTT server, the topics will be setup as different sensors. In Home Assistant, once a topic receives a different value, the sensor will reflect and also contain that value. This is done by editing the configuration.yaml file again and then restarting the Home Assistant service. You will add the following for each topic you wish to watch:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>sensor<\/strong>: # Directly returns the value of garage\/doorSwitch (a 0 or 1)<strong>&nbsp;&nbsp;&#8211; platform<\/strong>: mqtt<strong> <\/strong><strong>name<\/strong>: &#8220;Door Switch MQTT&#8221;<strong> <\/strong><strong>state_topic<\/strong>: &#8220;garage\/doorSwitch&#8221;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>5.&nbsp; &nbsp; &nbsp; Because the MQTT sends simple values, it may be beneficial to create another sensor that uses a template to assign friendly names to these topics. This will create another sensor device, and will not alter the original MQTT feed. To test the syntax of any template, you can go to the Developer Tools tab of Home Assistant and then select Template. You can examine if your code works like you intend. In addition, under the Developer Tools, you can also select the States tab to view your sensors. As you adjust MQTT values, the state column for the sensor entity will change here. Create an easy to read sensor by following this example:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>sensor<\/strong>: # A template &#8220;adjusts&#8221; the values from a MQTT sensor to make it more readable&nbsp;&nbsp; and user friendly # This makes the Door Switch MQTT either return &#8220;Opened&#8221; or &#8220;Closed&#8221;<strong>&nbsp;&nbsp;&#8211; platform<\/strong>: template<strong> <\/strong><strong>sensors<\/strong>:<strong>&nbsp;&nbsp;<\/strong><strong> <\/strong><strong>door_switch<\/strong>:<strong>&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><strong> <\/strong><strong>friendly_name<\/strong>: &#8220;Door Switch&#8221;<strong>&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><strong> <\/strong><strong>value_template<\/strong>: &gt;-<strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><strong> <\/strong><strong>{% if is_state(&#8216;sensor.door_switch_mqtt&#8217;, &#8216;1&#8217;) %}<\/strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><strong> <\/strong><strong>Opened<\/strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><strong> <\/strong><strong>{% else %}<\/strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><strong> <\/strong><strong>Closed<\/strong><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><strong> <\/strong><strong>{% endif %}<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/OATgvsRle83263cakskMrX8lxqKns7-MYMw9Fcjj1FqPD7iF9kobPwD8KvZO18NVOEaBEMXICcxhdGtR6HAbR8NcxSpJIIt405_e8YDR9n44zSBCFWEl15QvSadbUxFbUGsxtYPl\" alt=\"\"\/><\/figure>\n\n\n\n<p><em>Viewing MQTT Sensor Values in Developer Tools -&gt; States<\/em><\/p>\n\n\n\n<p>6.&nbsp; &nbsp; &nbsp; Now that we have sensors reading data from the MQTT broker, we can add cards to the Overview tab of Home Assistant to view this data easily at a glance. In this tab, click the three dots in the top right corner and select the option to configure the UI. In the bottom right, click the + button to add a card. To display the sensor data plainly, select the Sensor card. The Entity will be the name of your easy to read sensor and you can adjust other properties here. Feel free to test out other cards as well, such as the history graph. When you make changes and add cards here, they are recorded to a JSON stored in \/home\/homeassistant\/.homeassistant\/.storage\/lovelace. Alternatively, you can manually insert card data in the code here.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/A4P9TNrfwdOlrkVZwAWwIVW_sQf0kwBjT--yT9bLUs5zRHgerbVpn5bFSXXHLWlc-OI9w7Ehls9aY08uYExkMmQAj1YZUO5T5RZn_yp2kKmLsYZ-_LOI404rY9xrf6FNPLei9cBj\" alt=\"\"\/><\/figure>\n\n\n\n<p><em>Home Assistant Overview showing Sensor Values, histories, and other cards<\/em><\/p>\n\n\n\n<p>7.&nbsp; &nbsp; &nbsp; Experiment with other sensors devices and cards. For example, I used a \u201cswitch\u201d to listen to a MQTT topic. It also provides a button I can push to post a value into that topic as well, acting as a \u201cmanual override\u201d mode for my garage door switch. I also created a sensor with a template to show whether or not my car is parked in the garage based on sensor readings.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Images of Final Product<\/h2>\n\n\n\n<p><em>Our Mosquitto Server is properly setup from Lab 4. It listens to values passed by the Arduino devices<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/C4cc3OWsb5NLp601wJ1xsf4WDe_mtsKaCTpoCD8thZB8dwMztCtch4IS0EVkzNJuEoaxdhlXA1iFToUNiBLHnpJaOD6n6__kTe9NB2TYnkXOmupK1e2ayMoXOh88W41Yj0dstJuI\" alt=\"\"\/><\/figure>\n\n\n\n<p><em>When our devices are running and the distance from the sensor is relatively close, home assistant shows the current color of the stoplight, if the garage door is opened,<\/em><\/p>\n\n\n\n<p><em>and whether or not the car is likely still at home. Also, the garage door override button lights up, showing it is opened and that we can force it to close.<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/JsluWgy5_y-6mtAbAZfqN4e8voOB2mzPWJXGwcDVg1g4wgKN9Vi5SpguU75AZ9e9PwX4ti2bc242Y9GC76H3g_vBeyyAejOvzUgfvzh7OeDKGHtAlSQIRniIer7El7Bkyt7PBmKh\" alt=\"\"\/><\/figure>\n\n\n\n<p><em>I can also view a detailed history of my sensors and states in Home Assistant<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary With the number of IOT devices ever increasing, having an easy to use dashboard to both control and visualize the states of IOT devices is an extremely valuable piece to have in any embedded system. Application IOT devices are powerful but not intuitive to use for the average consumer. Creating a dashboard allows the &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/garett-cook.com\/index.php\/2020\/11\/19\/smart-garage-dashboard\/\"> <span class=\"screen-reader-text\">Smart Garage Dashboard<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":101,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-117","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-internet-of-things"],"_links":{"self":[{"href":"https:\/\/garett-cook.com\/index.php\/wp-json\/wp\/v2\/posts\/117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/garett-cook.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/garett-cook.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/garett-cook.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/garett-cook.com\/index.php\/wp-json\/wp\/v2\/comments?post=117"}],"version-history":[{"count":1,"href":"https:\/\/garett-cook.com\/index.php\/wp-json\/wp\/v2\/posts\/117\/revisions"}],"predecessor-version":[{"id":118,"href":"https:\/\/garett-cook.com\/index.php\/wp-json\/wp\/v2\/posts\/117\/revisions\/118"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/garett-cook.com\/index.php\/wp-json\/wp\/v2\/media\/101"}],"wp:attachment":[{"href":"https:\/\/garett-cook.com\/index.php\/wp-json\/wp\/v2\/media?parent=117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/garett-cook.com\/index.php\/wp-json\/wp\/v2\/categories?post=117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/garett-cook.com\/index.php\/wp-json\/wp\/v2\/tags?post=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}