<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jordan Rounds on Medium]]></title>
        <description><![CDATA[Stories by Jordan Rounds on Medium]]></description>
        <link>https://medium.com/@jordanrounds?source=rss-669953e65be7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*y9dFypiOkstXMvnNSw9fMQ.png</url>
            <title>Stories by Jordan Rounds on Medium</title>
            <link>https://medium.com/@jordanrounds?source=rss-669953e65be7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 24 May 2026 02:28:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jordanrounds/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Controlling Hue bulbs with Insteon Dimmers using Node Red and Home Assistant]]></title>
            <link>https://medium.com/@jordanrounds/controlling-hue-bulbs-with-insteon-dimmers-using-node-red-and-home-assistant-cf88cfc078a6?source=rss-669953e65be7------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf88cfc078a6</guid>
            <category><![CDATA[home-assistant]]></category>
            <category><![CDATA[home-automation]]></category>
            <category><![CDATA[smart-home]]></category>
            <category><![CDATA[philips-hue]]></category>
            <category><![CDATA[node-red]]></category>
            <dc:creator><![CDATA[Jordan Rounds]]></dc:creator>
            <pubDate>Mon, 17 Aug 2020 22:42:44 GMT</pubDate>
            <atom:updated>2020-08-17T23:28:58.493Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R007_Mm5PsAptU4RCTHFGQ.png" /></figure><p>The house I recently moved into contains 40+ 6&quot; recessed lights all containing incandescent or halogen bulbs ranging from 120 to 150 watts each. Basically they had flood lights installed in the house. These lights were all extremely bright and completely inefficient. I am in the process of replacing all of them with these <a href="https://www2.meethue.com/en-us/p/hue-white-and-color-ambiance-downlight-5-6-inch/5996611U5">Hue Downlights</a>, which are only 9 watts each, and plenty bright at 650 lumens. On top of that I can now control the color or temperature of every light in the house.</p><p>In my previous house I controlled Hue lighting from <a href="https://www.indigodomo.com/">Indigo</a> and used physical <a href="https://www.smarthome.com/products/switchlinc-dimmer-insteon-2477d-remote-control-dimmer-dual-band-white">Insteon dimmers</a>. I want to achieve the same thing in the new house, but using Home Assistant. I feel like I caused myself a bit of headache by wanting to use the Insteon dimmers, because they have lights on them that show the brightness level., and I am not able to handle this light not properly reflecting the brightness of the Hue bulbs being controlled. I also wanted to be able to make them be able to dim or brighten the hue bulbs by holding down the dimmer paddle like intended with standard bulbs.</p><h3>Whats been done so far?</h3><p>I’ve successfully got the Insteon dimmers setup and working with Home Assistant using <a href="https://github.com/TD22057/insteon-mqtt">Insteon-MQTT</a> running in a Docker container. I’m able to control the dimmers through the Home Assistant UI and see their state reflected by interacting with them manually. You can read about how I set this part up here:</p><p><a href="https://medium.com/@jordanrounds/setup-insteon-mqtt-and-integrate-with-home-assistant-f65522686909">Setup Insteon-MQTT and integrate with Home Assistant</a></p><h3>Time to actually control something!</h3><p>My first attempt at making all of this work was by using normal HA automations written in YAML. In the beginning it seemed like this was going to work without any issue. Turning the lights on and off was extremely straight forward. 15 minutes later if thats all I wanted I would have been done.</p><h3>Why it got complicated</h3><p>The Insteon Dimmers when brightening or dimming only send payloads of in UP, DOWN, and STOP. They do not know their actual brightness level, and only report that level after they send STOP. If I actually wanted to change the brightness I needed to kick off a script that would increase or decrease the brightness at an interval until the STOP payload was received. This seemed easy enough, and I did get that working as well. There is even an <a href="https://www.home-assistant.io/cookbook/dim_and_brighten_lights/">example</a> of it in the Home Assistant docs. This is now the point where I&#39;m my own worst enemy and everything fell apart. After the STOP payload came through I&#39;d stop the script, and then the dimmer would report its brightness and since I was changing the light brightness independently of the dimmer brightness things would be out of sync and the light would either brighten or dim to match the dimmer itself. I got it pretty close by adjusting the timing and amount the brightness changed each loop, but it was never quite right. Here&#39;s an example of just the yaml file for brightness changing from the dimmer.</p><pre>- id: dimmer_brightness<br>  alias: &quot;Dimmer Brightness Change&quot;<br>  trigger:<br>    platform: state<br>    entity_id:<br>      - light.dimmer<br>  condition:<br>    condition: template<br>    value_template: &gt;-<br>      {% set manual_state = state_attr(trigger.entity_id, &quot;manual_state&quot;) %}<br>      {% set is_not_manual = (manual_state == &quot;STOP&quot; or manual_state == &quot;None&quot;) %}<br>      {% set dimmer_on = (trigger.from_state.state == &#39;on&#39; and trigger.to_state.state == &#39;on&#39;) %}<br>      {% set from_off_to_on = trigger.from_state.state == &#39;off&#39; and trigger.to_state.state == &#39;on&#39; %}<br>      {% set brightness_change = trigger.from_state.attributes.brightness != trigger.to_state.attributes.brightness %}<br>      {% set needs_update = state_attr(state_attr(&quot;sensor.insteon_map&quot;, state_attr(trigger.entity_id, &#39;address&#39;)), &#39;brightness&#39;) != trigger.to_state.attributes.brightness %}<br>      {{ dimmer_on and brightness_change and is_not_manual and needs_update  }}<br>  action:<br>    - service: light.turn_on<br>      data_template:<br>        entity_id: &gt;-<br>          {% set address = state_attr(trigger.entity_id, &#39;address&#39;) %}<br>          {{ state_attr(&quot;sensor.insteon_map&quot;, address) }}<br>        brightness: &gt;-<br>           {{ trigger.to_state.attributes.brightness }}</pre><p>Does that explain why I felt it got too complicated? I needed to check all sorts of different conditions and try to present that in a sane way through yaml. I started to go slightly crazy. In the end I had 9 yaml files with the different parts of the automations to keep everything in sync.</p><h3>What were my options?</h3><p>I’m sure there are plenty of options, but the two I looked into were <a href="https://nodered.org/">Node Red</a> and <a href="https://appdaemon.readthedocs.io/en/latest/">AppDaemon</a>. My initial instinct was to try and use AppDaemon since I’m relatively comfy writing Python, and it’s a familiar path to have to take from my experiences using Indigo. I ended up deciding to give Node Red a try first though, since the barrier to entry as well as the visual representation was appealing and seemed like it might be easier to manage later once I’ve forgotten how everything works at a later date.</p><h3>So, I Installed and Setup Node Red</h3><p><a href="https://medium.com/@jordanrounds/installing-node-red-in-docker-for-home-assistant-1d56e03b4c5d">Installing Node Red in Docker for Home Assistant</a></p><h3>Adding the Dimmers to HA</h3><p>The dimmers are added pretty much as you’d expect based on how I walked through setting up <a href="https://jordanrounds.com/insteon-mqtt-home-assistant/">insteon-mqtt with home assistant</a>. There are a few differences though, which are the addition of json_attributes_topic which is going to be how we are able to track the manual interactions, as well as the addition of a unique_id for no reason other than I didn&#39;t like the UI complaining to me about it not having one.</p><pre>- name: dimmer_hallway<br>  platform: mqtt<br>  schema: json<br>  state_topic: &quot;insteon/41.b3.5e/state&quot;<br>  command_topic: &quot;insteon/41.b3.5e/level&quot;<br>  json_attributes_topic: &quot;insteon/41.b3.5e/manual_state&quot;<br>  brightness: true<br>  unique_id: 41.b3.5e</pre><p>There will be an additional attribute that will show up called manual_state which will say STOP once you&#39;ve released the dimmer paddle.</p><h3>Creating a Generic HA Config and Node Red Flow</h3><p>My goal was to make it so that for 99% of the use cases I would be able to simply add a new hue bulb and “pair” it to a dimmer switch and have it work with little effort. To do that I ended up with the concept of sync_entity_id, sync_address, address, sync_entites, sync_dimmers, and sync_bulbs.</p><p>There very well may be a much more straight forward way of doing it but I found myself in the situation where I needed a place to store some additional meta data that was manually configured for my lights and dimmers. To do this I heavily utilized the flexibility of customize.yaml.</p><pre>#----------------------------------------------------------<br>#         Hallway Dimmers<br>#----------------------------------------------------------<br>light.dimmer_hallway:<br>  address: 41.b3.5e<br>  is_sync_dimmer: true<br>  sync_entity_id: light.hallway<br>  friendly_name: Hallway Dimmer</pre><pre>light.dimmer_hallway_master:<br>  address: 41.b8.f6<br>  is_sync_dimmer: true<br>  sync_entity_id: light.hallway<br>  friendly_name: Hallway Dimmer Master</pre><pre>#----------------------------------------------------------<br>#          Hallway Bulbs<br>#----------------------------------------------------------<br>light.hallway:<br>  sync_address: 41.b3.5e<br>  is_sync_bulb: true<br>  sync_entities:<br>    - light.dimmer_hallway<br>    - light.dimmer_hallway_master</pre><h3>What are these used for?</h3><p>These probably wont make a ton of sense at the moment but will be more clear once we get into the Node Red flow.</p><p><strong>Dimmers</strong></p><ul><li>address — the actual insteon device address</li><li>is_sync_dimmer — so we know if the dimmer is supposed to talk to a bulb</li><li>sync_entity_id: id of the bulb to reference</li></ul><p><strong>Bulbs</strong></p><ul><li>sync_address — the address of the insteon device to control</li><li>is_sync_bulb — so we know if the bulb is supposed to talk to a dimmer</li><li>sync_entities — list of dimmers to update when the light changes</li></ul><h3>Creating the Flows</h3><p>Now that the Home Assistant configuration is handled its time to create the flow. The main thing to remember here is that the state of the bulb is always the most important truth. By taking this approach we wont end up in any weird update loops and also still have the ability to use any third party apps to control the bulbs and the dimmers will still respond appropriately. You can download the <a href="https://gist.github.com/jordanrounds/ab7edc7dab8abbf03d7ca5d11fb1fb0c"><strong>Entire Node Red Flow</strong></a><strong> </strong>otherwise I’ve broken it up into chunks that are linked to as we go.</p><h3>Bulb Flow</h3><p>Here’s what the flow for the lights changing looks like, and you can download it here: <a href="https://gist.github.com/jordanrounds/35539f1d29f16c5739f593b47e5c2da4">light-flow.json</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NiDSG6sLtHtjSusY.png" /></figure><p>The first thing that happens is we check if the bulb is a sync_bulb, and if it is we move on to a function node which gets the list of sync_entities so that we can update their state.</p><pre>let attrs = msg.data.new_state.attributes;<br>let payload = msg.payload;</pre><pre>if(attrs.hasOwnProperty(&quot;sync_entities&quot;)) {<br>    msg.payload = attrs.sync_entities;<br>    msg.original_payload = payload;<br>    return msg;<br>}</pre><p>Next those entities are piped through the split node, so that we can go get each dimmer individually using its it. The split node sends an individual msg for each entity_id in the sync_entities list. It sets msg.payload to each of those entity_ids, which go through a ha-get-entities node that uses the entity_id as its property its searching on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*mN0ehps3UnrI_QXcXQ3mYw.png" /><figcaption>Dimmer Node</figcaption></figure><p>Finally there is a check using a switch node that looks at the original payload to see if the bulb was turning on or off. From there if its off we turn the dimmer off, and if its on there is one last check to make sure the bulb wasn’t changing state due to a manual interaction with the dimmer.</p><pre>let attrs = msg.payload.attributes;<br>let hasManual = attrs.hasOwnProperty(&quot;manual_state&quot;);</pre><pre>if(!hasManual || hasManual &amp;&amp; attrs.manual_state == &quot;STOP&quot;) {<br>    return msg;<br>}</pre><h3>Dimmer Flow</h3><p>The dimmer flow is similar to the bulb flow but even more straight forward. You can download it here: <a href="https://gist.github.com/jordanrounds/446311d0be02df6507f4a4766e3bb599">dimmer-flow.json</a></p><p>It starts out exactly the same where the first node is looking for events coming from any entity starting with light.dimmer. The next node is a simple switch checking if it is a sync dimmer. The Stop node is the same as the one from the bulb flow, which is checking to make sure the dimmer isn&#39;t being manually interacted with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1O3vwbsPOoSDqL_J.png" /></figure><p>Finally we check if its an on or an off command with the on/off switch node. If its off then we simply turn the bulb off, but if its on we make one check to make sure the bulb is actually off before turning it on. This was done to handle the edge case of using a bulb standalone as well as in a hue light group. Turning the bulb on individually in hand turns on the group as well. When the group turned on it triggered an update of the dimmer from the bulb, and if you don’t check against the light group being on already it would turn on the whole group. (thats confusing, and I’m not sure a better way to explain…)</p><h3>Manual Dimming</h3><p>This is where things started to get a bit more tricky. Now I wanted to actually start handing the manual interaction with the dimmers, meaning if I hold down the dimmer paddle I now want the bulbs to start dimming and then stop when I let off the paddle. That sounds pretty straight forward, but it ends up becoming a bit of a headless interaction because we will be getting zero feedback about state until the paddle is released, so the speed and way it behaves is all based on my best guess and referencing what I used to have when I did a similar thing using <a href="https://www.indigodomo.com/">Indigo</a>. I used the timing from this <a href="https://github.com/nsheldon/Hue-Lights-Indigo-plugin">Indigo Hue Plugin</a>. You can download the flow here: <a href="https://gist.github.com/jordanrounds/fe1bedc8ad22d88e8838e2ceed8028e2">manual-dim-flow.json</a></p><p>For the manual interactions we will be responding directly to the MQTT messages that are coming over the manual_state channel, and the first node will simply be looking for the STOP payload and if it&#39;s received it will kill the 400ms timer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4MwYJAdegHQZpxuqIisFXg.png" /><figcaption>Manual Dimmer Flow</figcaption></figure><p>If the payload is not STOP then it&#39;s a matter of looking up the bulb that listens to this dimmer, by using the dimmer address and looking up the bulb that has that address set as its sync_address. Once the light is found I decided to create a JSON object of &quot;instructions&quot; that will be iterated over by the timer. The below javascript is what is found in the Dim/Brighten function node.</p><pre>let light = msg.payload;<br>let step = 30, max = 20, transition = .4;<br>let curBrightness = 0, nextBrightness = 0;</pre><pre>msg.instructions = { &quot;increase&quot;: true, &quot;transition&quot;: transition, &quot;step&quot;: step, &quot;count&quot;: 0, &quot;max&quot;: max, &quot;brightness&quot;: 0};</pre><pre>//brightness attribute may not exist if brightening from off state<br>if(light.attributes.hasOwnProperty(&#39;brightness&#39;)) {<br>    curBrightness = light.attributes.brightness;<br>}</pre><pre>if(msg.manual_state == &quot;DOWN&quot;) {<br>    nextBrightness = curBrightness - step;<br>    nextBrightness = nextBrightness &lt; 0 ? 0 : nextBrightness;<br>    msg.instructions.increase = false;<br>} else {<br>    nextBrightness = curBrightness + step;<br>    nextBrightness = nextBrightness &gt; 255 ? 255 : nextBrightness;<br>}</pre><pre>msg.instructions.brightness = nextBrightness<br>msg.light = light;</pre><pre>return msg;</pre><p>It creates an instructions object containing properties saying if its increasing or decreasing brightness depending on if manual_state is set to UP or DOWN, how fast the transition is, the step of how much to change the brightness, and the brightness to be set. Next immediately start updating the brightness of the bulb so there isn&#39;t a feeling of delay.</p><p>From here the stoptimer node will get kicked off and it will fire every 400ms. The Update Instructions function node will then use and update that instructions object to increase or decrease brightness appropriately and also killing the timer if the button is held down longer than it takes to completely turn on or off the bulb.</p><pre>let inst = msg.instructions;</pre><pre>inst.count++;</pre><pre>if(inst.count &gt;= inst.max || inst.brightness &gt; 255 || inst.brightness &lt; 0) {<br>    msg.payload = &quot;stop&quot;<br>    return [null, msg]<br>}</pre><pre>if(inst.increase) {<br>    inst.brightness += inst.step;<br>} else {<br>    inst.brightness -= inst.step;<br>}</pre><pre>return [msg, null];</pre><h3>Manual Fast On</h3><p>There is one final interaction that I wanted to handle which is the simple fact that if the light was on and the dimmer was on, and I tapped the dimmer again to increase its brightness all the way to 100% nothing would happen.</p><p>This would come through as a payload mode of normal and a state of ON. You could also add things to this such as support for &quot;fast&quot; which would be a double tap of the switch for an instant on or off message. I decided to handle fast in the same way I handled normal. You can download the flow here: <a href="https://gist.github.com/jordanrounds/586268908aa687929a8b0f789b64cf74">manual-on-off-flow.json</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NANES6KPbmd-0LRL.png" /></figure><p>First uses a get entities node to find the dimmer entity being pressed using its address. Once we’ve got the dimmer, it’s time to figure out if the dimmer was manually pressed and was already on. This is done in the Manual Tap node.</p><pre>let payload = msg.payload;</pre><pre>msg.dimmer = msg.dimmers[0];<br>delete msg.dimmers;</pre><pre>let device_on = payload.reason == &quot;device&quot; &amp;&amp; payload.state == &quot;ON&quot;;<br>let device_off = payload.reason == &quot;device&quot; &amp;&amp; payload.state == &quot;OFF&quot;;<br>let fast = payload.mode == &quot;fast&quot;;</pre><pre>let fast_on = msg.dimmer.state == &quot;off&quot; &amp;&amp; device_on &amp;&amp; fast;<br>let fast_off = msg.dimmer.state == &quot;on&quot; &amp;&amp; device_off &amp;&amp; fast;</pre><pre>let fast_on_from_on = msg.dimmer.state == &quot;on&quot; &amp;&amp; device_on &amp;&amp; fast;<br>let fast_off_from_off = msg.dimmer.state == &quot;off&quot; &amp;&amp; device_off &amp;&amp; fast</pre><pre>let on_from_on = msg.dimmer.state == &quot;on&quot; &amp;&amp; device_on</pre><pre>if(fast_on || on_from_on) {<br>    msg.brightness = payload.brightness;<br>    return msg;<br>}</pre><p>There’s more script there than necessary to solve what I actually needed, but I figured I’d try and capture a few of the various states incase I ever wanted to respond to them differently in the future.</p><h3>Closing Thoughts</h3><p>Overall I’m pretty happy with my setup. It’s certainly not perfect but 99% of the time it works exactly as you’d expect. One major consideration to be made is you really need to commit to the idea that if the mqtt broker, insteon-mqtt, or home assistant isnt reachable the switches will do nothing. I’ve spent some time figuring out the best way to mitigate this, and my current solution is nothing runs on wifi, and everything is connected to a UPS. Obviously if the power goes out so do the lights, but the UPS is in place to prevent something from not rebooting properly during a short power outage as well as piece of mind that something wont get corrupt by shutting down improperly.</p><p>Another is how I’m handling manual dimmer changes. In the current setup the MQTT node is listening to insteon/+/manual_state which is any dimmer in my house. If someone were to manually dim one at the same time as someone else, whoever stops first will stop both lights. After writing this I&#39;m not 100% sure, but there may even be an issue using two switches at the exact same time. I&#39;ve never tested but assume bad things happen. At the end of the day its only myself and my wife living in this house and the likelihood of this happening is slim.</p><p><em>Originally published at </em><a href="https://jordanrounds.com/controlling-hue-bulbs-with-insteon-dimmers-using-node-red-and-home-assistant/"><em>https://jordanrounds.com</em></a><em> on August 17, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf88cfc078a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Installing Node Red in Docker for Home Assistant]]></title>
            <link>https://medium.com/@jordanrounds/installing-node-red-in-docker-for-home-assistant-1d56e03b4c5d?source=rss-669953e65be7------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d56e03b4c5d</guid>
            <category><![CDATA[home-assistant]]></category>
            <category><![CDATA[home-automation]]></category>
            <category><![CDATA[smart-home]]></category>
            <category><![CDATA[node-red]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Jordan Rounds]]></dc:creator>
            <pubDate>Wed, 01 Jul 2020 17:08:30 GMT</pubDate>
            <atom:updated>2020-08-17T23:02:56.993Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*TWqP4JHjcrAl0rmMh8uIpw.png" /></figure><p><a href="https://www.smarthome.com/products/switchlinc-dimmer-insteon-2477d-remote-control-dimmer-dual-band-white">I</a>’ve been trying to figure out a good reliable way to have semi complex automations setup for Home Assistant that I can easily edit and debug. Node Red ended up being the solution I settled on.</p><p>My goal was to be able to control Hue lights with Insteon dimmers where the dimmers aren’t actually connected to the load and communicating via MQTT. This is the second post in a series about that journey. You can find the first post here:</p><p><a href="https://medium.com/@jordanrounds/setup-insteon-mqtt-and-integrate-with-home-assistant-f65522686909">Setup Insteon-MQTT and integrate with Home Assistant</a></p><p>We will walkthrough installing Node Red in Docker and then setting it up to connect to Home Assistant. Finally we will verify that messages are coming through properly.</p><h3>Installing Node Red</h3><p>Being new to Node Red, I had zero idea what I was doing, but knew that I wanted to run it in Docker. I started by looking around at the various Dockerfiles out there and tried to pick the various flows that it seemed like I might need installed. The most important one here being <a href="https://flows.nodered.org/node/node-red-contrib-home-assistant-websocket">node-red-contrib-home-assistant-websocket</a>. I think the only other one I needed was <a href="https://flows.nodered.org/node/node-red-contrib-stoptimer">node-red-contrib-stoptimer</a>. Here’s the Dockerfile I ended up going with:</p><pre>FROM nodered/node-red</pre><pre>RUN npm install node-red-contrib-actionflows \<br>    node-red-contrib-home-assistant-websocket \<br>    node-red-contrib-stoptimer \<br>    node-red-contrib-time-range-switch \<br>    node-red-contrib-timecheck \<br>    node-red-node-timeswitch</pre><p>From there it was just a simple docker-compose file to get up and running.</p><pre>version: &#39;3.7&#39;<br>services:<br>  node-red:<br>    build: .<br>    container_name: &quot;node-red&quot;<br>    environment:<br>      TZ: ${TZ}<br>    image: &quot;nodered/node-red&quot;<br>    restart: unless-stopped<br>    ports:<br>      - &quot;1880:1880&quot;<br>    volumes:<br>      - &quot;data:/data&quot;<br>volumes:<br>  data:<br>    name: node-red_data<br>    driver: local-persist<br>    driver_opts:<br>      mountpoint: ${LOCAL_PERSIST}/node-red/data</pre><p>Run docker-compose up -d and then navigate to the host&#39;s ip on port 1880.</p><h3>Connecting Node Red to Home Assistant</h3><p>The first thing we need to do to connect Node Red to Home Assistant is generate an access token. I decided to at the same time create a new user in Home Assistant specifically for Node Red. I don’t have any real justification for this step other than I liked the separation. So you could totally skip this bit.</p><p>Click Configuration on the left navigation, and scroll down and click Users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ScMefJXGKXG78vbh.png" /></figure><p>Click the add button in the lower right, and create a new admin user for node red.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CjoqY76nw0dbVP0e.png" /></figure><p>After your new user is created click on your current user in the lower left, and click logout. Next login as your node red user. Once logged in again click on the user in the lower left, and scroll down the profile page to the bottom section named Long-Lived Access Tokens and click Create Token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zdIDyqQLpdoRjpS7.png" /></figure><p>You’ll then give your token a name and click Ok.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GF2hr_Ht1Vsl3YOd.png" /></figure><p>Next you’ll see a modal displaying your access token. Be sure to copy and save it somewhere so we can enter it back in Node Red.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-ETKEK7oa9XEf51x.png" /></figure><p>Now its time to go back over to Node Red, and the first thing we will do is drop a server-state-changed node, which is labeled “events: state” from the left hand nodes panel under the Home Assistant section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RvFTNUs0rnXGk7h9.png" /></figure><p>Next double click on the node you added, and you’ll see the configuration for that node. Next to the Server field click the pencil icon to add a new server. Then give your server a name, enter its url, and put that access token we created in there. Finally click the add button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a3FKmTG0gnAAg1RUCvcK1A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KE6OvMvzyRpBGr_VDd0kSw.png" /></figure><p>Now you’ll see the configuration for the node. We are just going to test that everything is working next so you can give it a name, pick an entity (one you can change state easily on), and then uncheck only on state change.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7jnvSKikqVvlxhGw.png" /></figure><p>From here click done and you’ll see the Flow canvas again with our new node. Next to see if everything’s working scroll up to the top of the nodes list on the left and find the debug node. Drop one of those on the canvas. Once its there click and drag from the gray box on the event node to the debug node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xtrwP_hDlIpVa8YcDFkd4g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*Fu8EjSdQTcwo6lns6Llb5A.png" /></figure><p>Finally we can click the Deploy button in the upper right. Click the debug button under it and change the state of the entity through Home Assistant or however you want to change it. Then sit back and watch the messages come through.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YqiTqQ-4VOvrXGAe.png" /></figure><p>Now we’ve got Node Red Setup and working with Home Assistant, and used a debug node to confirm that.</p><h3>Create a Simple Automation to Control a Light</h3><p>This is probably the most basic thing we could do. We will use the dimmer and its payload to then trigger a light to either turn on or off. First lets drop an “events: state” node into the flow, and configure it to be an entity that is the dimmer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O16SWnwUwt-UlFbrZOsrVQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*votKRBR7DUeRAMvIcKam-w.png" /></figure><p>Next add a “call service” node to the flow. Double click it to configure it. W will give it a name of “Light”, set the domain to light, set the service to be turn_{{payload}} , and set the entity id to the light entity you want to control in Home Assistant. The key piece to call out here is the service entry, which is essentially taking the payload from the msg object, which will either be on or off, therefore calling the appropriate service of turn_on or turn_off}.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bsX7KxEXNrEovWUwbOjBHw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*khp3f2uH0tYWF-UPJgD2BA.png" /></figure><p>Finally, make sure to connect the two nodes and then go toggle your dimmer and watch the light turn on and off.</p><h3>What’s Now?</h3><p>From here we can use Node Red for any types of automations that can be imagined. Searching around the internet there are many great examples others have created, and many times provide the flow to be copied and pasted right into Node Red.</p><p>We’ve created this simple automation be the starting point of the automations that will be needed to control Hue lights with Insteon Dimmers coming up next.</p><p><em>Originally published at </em><a href="https://jordanrounds.com/installing-node-red-in-docker-for-home-assistant/"><em>https://jordanrounds.com</em></a><em> on July 1, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d56e03b4c5d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setup Insteon-MQTT and integrate with Home Assistant]]></title>
            <link>https://medium.com/@jordanrounds/setup-insteon-mqtt-and-integrate-with-home-assistant-f65522686909?source=rss-669953e65be7------2</link>
            <guid isPermaLink="false">https://medium.com/p/f65522686909</guid>
            <category><![CDATA[hassio]]></category>
            <category><![CDATA[home-assistant]]></category>
            <category><![CDATA[mqtt]]></category>
            <category><![CDATA[home-automation]]></category>
            <category><![CDATA[insteon]]></category>
            <dc:creator><![CDATA[Jordan Rounds]]></dc:creator>
            <pubDate>Thu, 25 Jun 2020 23:33:14 GMT</pubDate>
            <atom:updated>2020-06-30T21:32:59.358Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hwMS7XIDJnTqXWNf.png" /></figure><p>Recently I moved into a new house. My previous house was mostly Insteon devices and I used <a href="https://www.indigodomo.com/">Indigo</a> running on a Mac Mini as my home automation software. Before moving I had slowly started dabbling with Home Assistant and got a bunch of my Insteon devices communicating with HA via MQTT. This was great as a starting point but now I had two separate automation platforms to deal with and I was slowly moving everything that I could out of Indigo and into HA.</p><p>The move was extremely motivating to completely stop using Indigo because I had to start over anyway. Now the question was what should I use to integrate Insteon with HA. There were a few various options I found, including the built in support in HA, but I settled on <a href="https://github.com/TD22057/insteon-mqtt">Insteon-MQTT</a>. I felt like it gave me the flexibility and control that I was looking for.</p><p>The main Insteon devices that I use are <a href="https://www.smarthome.com/products/switchlinc-dimmer-insteon-2477d-remote-control-dimmer-dual-band-white">dimmers</a> and keypads. I ended up settling on them long ago because I couldn’t find anything that even closely compared to the quality of hardware and I especially like the LED display of the brightness on the dimmers. To kick things off I needed to get a testing device setup.</p><h3>Testing Setup</h3><p>I built this box with a <a href="https://www.homedepot.com/p/2-Device-Drawn-Switch-Electrical-Box-683SP/202056186">metal electrical box</a> and <a href="https://www.homedepot.com/p/HDX-6-ft-13-Amp-3-Prong-Grey-Appliance-Replacement-Cord-HD-588-547/100672804">power cord</a> from Home Depot and installed a keypad and a dimmer. This gave me the flexibility to not completely have to change switches and not have lights work while getting everything setup. All I did different from a normal in-wall install was connected black to black, white to white, ground to ground, and then capped the load with a wire nut. Just be careful to not electrocute yourself and make sure its unplugged before you put a switch in or take one out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6weqYP8dsLOD4rp2K1MahA.png" /><figcaption>Test Switches</figcaption></figure><h3>Insteon-MQTT Install</h3><p>To start with Insteon-MQTT is extremely well <a href="https://github.com/TD22057/insteon-mqtt/blob/master/docs/quick_start.md">documented</a>. They even provide <a href="https://github.com/TD22057/insteon-mqtt/blob/master/docs/hassio_quick_start.md">instructions</a> for setting it up as an add-on in Home Assistant, but I opted for installing it as a Docker <a href="https://hub.docker.com/r/larizzo/insteon-mqtt/">container</a> I could manage myself.</p><pre>version: &#39;3.7&#39;<br>services:<br>  inseon-mqtt:<br>    container_name: &#39;insteon-mqtt&#39;<br>    environment:<br>      TZ: ${TZ}<br>    image: larizzo/insteon-mqtt<br>    restart: unless-stopped<br>    devices:<br>      - /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A403KDY0-if00-port0:/dev/ttyUSB0<br>    volumes:<br>      - config:/config:rw<br>      - data:/data:rw<br>volumes:<br>  config:<br>    name: insteon-mqtt_config<br>    driver: local-persist<br>    driver_opts:<br>      mountpoint: ${LOCAL_PERSIST}/insteon-mqtt/config<br>  data:<br>    name: insteon-mqtt_data<br>    driver: local-persist<br>    driver_opts:<br>      mountpoint: ${LOCAL_PERSIST}/insteon-mqtt/data</pre><p>Here’s the docker-compose.yaml file I use. All you’ll need to do is make sure the paths to your volumes are correct, and the devices definition which is pointing to the Insteon PLM thats connected to the computer running Docker. Once you have everything configured you’ll just need to run docker-compose.</p><pre>docker-compose up -d</pre><p>At this point the container will be up and running but you wont have any devices or the PLM configured. Inside of the config directory that you had mapped as a volume you will find a file called <em>insteon_mqtt.yaml</em></p><h3>Config Setup</h3><p>If you open the <em>insteon_mqtt.yaml</em> file you’ll see that its wonderfully populated and commented out showing examples for configuring each type of device as well as examples for integrating into Home Assistant.</p><h3>PLM</h3><p>The first thing we need to do is setup the <a href="https://www.smarthome.com/products/powerlinc-modem-insteon-2413u-usb-interface-dual-band?pr_prod_strat=description&amp;pr_rec_pid=5084181397637&amp;pr_ref_pid=5084181037189&amp;pr_seq=uniform">Insteon PLM</a>. Below is an example of my config for the PLM.</p><pre>insteon:<br>  # Serial device:<br>  # USB PLM modem<br>  port: &#39;/dev/ttyUSB0&#39;<br>  baudrate: 19200<br><br>  # PLM modem Insteon hex address<br>  address: 3C.4D.74<br><br>  # Device database file storage location.<br>  storage: &#39;data&#39;<br><br>  # Automatically refresh device states and databases (if needed) at<br>  # startup.  This may be slow depending on the number of devices.<br>  startup_refresh: False</pre><p>The only things you’ll probably need to modify to get the PLM working is the port, which points to <em>/dev/ttyUSB0 </em>and is also what we defined in the devices section of the docker-compose file. Next you’ll need to enter in whatever the actual address is of your PLM which you should find on the back of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-sCZ1iQSIqEDK4zDvEPwtw.png" /><figcaption>Insteon PLM address location</figcaption></figure><h3>Devices</h3><p>Now that we have the PLM setup its time to add our devices. For now I’m just adding a single dimmer but you could just add the addresses of all your Insteon devices in here right now. Insteon dimmers normally have an address sticker on the front of them.</p><pre>devices:<br>    # Dimming devices (outlets, wall switches, lamp modules, etc).<br>    dimmer:<br>      - 41.ad.4f: &#39;dimmer&#39;</pre><p>You’ll be putting the address first followed by a colon and then a string for the name of the device.</p><p>If for some reason you don’t know the address of the device you are able to get it by looking at the logs of insteon-mqtt as long as the device is powered and sending a command. If you are in this situation, restart the docker container after configuring the PLM and go checkout the logs to get your addresses. When I went through this process I used a label maker to add new address stickers to all of my dimmers.</p><h3>MQTT</h3><p>Next we need to configure MQTT. You’ll need at a minimum the address to your broker and the port. Optionally if you have authentication turned on the username and password.</p><pre>mqtt:<br>  broker: 192.168.1.123<br>  port: 1883<br>  <br>  # Optional broker login data.<br>  username: yourusername<br>  password: yourpassword</pre><p>Once the broker is setup you can take a look at the topics for Dimmers and any of the other supported types of Insteon devices you might need. Below is an example of what my dimmer topics look like.</p><pre>dimmer:<br>    state_topic: &#39;insteon/{{address}}/state&#39;<br>    state_payload: &gt;<br>       { &quot;state&quot; : &quot;{{on_str.upper()}}&quot;, &quot;brightness&quot; : {{level_255}}, &quot;reason&quot; : &quot;{{reason}}&quot;, &quot;mode&quot; : &quot;{{mode}}&quot;, &quot;address&quot; : &quot;{{address}}&quot; }<br><br>    manual_state_topic: &#39;insteon/{{address}}/manual_state&#39;<br>    manual_state_payload: &#39;{ &quot;manual_state&quot; : &quot;{{manual_str.upper()}}&quot;, &quot;address&quot; : &quot;{{address}}&quot; }&#39;<br><br>    on_off_topic: &#39;insteon/{{address}}/set&#39;<br>    on_off_payload: &#39;{ &quot;cmd&quot; : &quot;{{value.lower()}}&quot; }&#39;<br><br>    level_payload: &gt;<br>       { &quot;cmd&quot; : &quot;{{json.state.lower()}}&quot;,<br>         &quot;level&quot; : {% if json.brightness is defined %}<br>                      {{json.brightness}}<br>                   {% else %}<br>                      255<br>                   {% endif %} }<br>                   <br>    scene_topic: &#39;insteon/{{address}}/scene&#39;<br>    scene_payload: &#39;{ &quot;cmd&quot; : &quot;{{value.lower()}}&quot; }&#39;</pre><p>It’s very close to the defaults except I’ve included <em>reason, mode, </em>and <em>address </em>in the state payload as well as uncommented the <em>manual_state</em> topic and payload, which will send dimming start and stop payloads.</p><h3>Restart, Join, Pair, and Refresh!</h3><p>At this point all the configuration we need for insteon-mqtt is complete. Before we do anything else go ahead and restart the container.</p><pre>docker-compose restart</pre><p>Once the container is back up we need to go through the process of <em>joining</em>, <em>pairing</em>, and <em>refreshing</em> all the devices. This <a href="https://github.com/TD22057/insteon-mqtt/blob/master/docs/mqtt.md">process</a> can be done from the command line or using MQTT. I chose to do it via the command line using docker exec, and I wrote a simple bash script to help keep it simple.</p><p>While it isn’t necessary I did also choose to factory reset all my dimmers before adding any of them. This can be done by pulling out the small button below the dimmer button, wait ten seconds, and then press in and hold it until the switch stops beeping and then a couple seconds later you’ll hear a double beep confirming that the reset was successful. You can find the instructions in the <a href="http://cache.insteon.com/documentation/2477D-en.pdf">manual</a> as well.</p><h3>Using MQTT</h3><p>The topic would be:</p><pre>insteon/command/aa.bb.cc</pre><p>The payload would be one of these three:</p><pre>{ &quot;cmd&quot; : &quot;join&quot;}<br>{ &quot;cmd&quot; : &quot;pair&quot;}<br>{ &quot;cmd&quot; : &quot;refresh&quot;}</pre><h3>Using Docker Exec</h3><p>You can join and pair each device using the appropriate commands, and when done call the refresh-all command. Alternatively you could call refresh on each one individually.</p><pre>docker exec -d your_instance_name insteon-mqtt /config/insteon_mqtt.yaml join aa.bb.cc<br><br>docker exec -d your_instance_name insteon-mqtt /config/insteon_mqtt.yaml pair aa.bb.cc<br><br>docker exec -d your_instance_name insteon-mqtt /config/insteon_mqtt.yaml refresh-all</pre><h3>Bash Script</h3><p>Lets call this script <em>insteon-mqtt.sh. </em>Make sure that the file’s permissions are executable, and then type <em>./insteon-mqtt.sh</em> on the command line.</p><pre>#!/bin/bash<br>INSTANCE_NAME=&#39;insteon-mqtt&#39;<br>CONFIG_FILE=&#39;/config/insteon_mqtt.yaml&#39;<br>LINE=&#39;-------------------------------------&#39;<br><br>echo &#39;Insteon MQTT Management&#39;<br>echo<br>echo &#39;What would you like to do?&#39;<br>echo $LINE<br>echo &#39;1) Join Device&#39;<br>echo &#39;2) Pair Device&#39;<br>echo &#39;3) Refresh All Devices&#39;<br>echo &#39;4) Refresh Device&#39;<br>echo $LINE<br><br>read -p &#39;Choose option: &#39;<br>echo<br><br>if [ ${REPLY} -eq 1 ]; then<br>  echo &quot;Joining Device&quot;<br>  echo $LINE<br>  read -p &#39;Device Address (aa.bb.cc): &#39; address<br>  echo<br>  echo &quot;Joining Device: $address&quot;<br>  docker exec -d $INSTANCE_NAME insteon-mqtt $CONFIG_FILE join $address<br>  #docker exec -d $INSTANCE_NAME kill -HUP 1<br>elif [ ${REPLY} -eq 2 ]; then<br>  echo &quot;Pairing Device&quot;<br>  echo $LINE<br>  read -p &#39;Device Address (aa.bb.cc): &#39; address<br>  docker exec -d $INSTANCE_NAME insteon-mqtt $CONFIG_FILE pair $address<br>  #docker exec -d $INSTANCE_NAME kill -HUP 1<br>elif [ ${REPLY} -eq 3 ]; then<br>  echo &quot;Refresh All Devices&quot;<br>  echo $LINE<br>  docker exec -d $INSTANCE_NAME insteon-mqtt $CONFIG_FILE refresh-all<br>elif [ ${REPLY} -eq 4 ]; then<br>  echo &quot;Refresh Device&quot;<br>  echo $LINE<br>  read -p &#39;Device Address (aa.bb.cc): &#39; address<br>  echo<br>  echo &quot;Refreshing Device: $address&quot;<br>  docker exec -d $INSTANCE_NAME insteon-mqtt $CONFIG_FILE refresh $address<br>else<br>  echo &quot;Please enter a valid option.&quot;<br>fi<br>exit 1</pre><h3>Testing MQTT</h3><p>Now that everything should be added, paired and ready to go its probably worth testing it out before trying to put everything in Home Assistant. Home assistant has some built in MQTT debugging under the Developer Tools.</p><figure><img alt="Screen of the Home Assistant MQTT Developer Tools" src="https://cdn-images-1.medium.com/max/1024/1*XzPPClBUmmgmW_xkJtJs9w.png" /><figcaption>Home Assistant MQTT Developer Tools</figcaption></figure><p>I prefer to use <a href="http://workswithweb.com/mqttbox.html">MQTTBox</a> which is a free download. It allows for subscribing or publishing to multiple topics easily, and keeps your setup saved for later.</p><figure><img alt="Screen showing using MQTTBox to test MQTT" src="https://cdn-images-1.medium.com/max/1024/1*v18st2hpNYxVp0-vEq6YoA.png" /><figcaption>MQTTBox</figcaption></figure><p>Once you are subscribed to your topic using the correct address of your device you should start to see messages coming through when you turn it on or off. If you aren’t seeing messages coming through, be sure to double check the address of your device is correctly entered in the <em>insteon_mqtt.yaml</em> file, and in the topic you are subscribed to.</p><p>Additionally its always worth checking in on the logs from insteon-mqtt. They are extremely verbose and helpful.</p><pre>docker-compose logs</pre><h3>Adding to Home Assistant</h3><p>Finally we need to add these devices into Home Assistant using MQTT Templates. Luckily there are very clear examples inside the insteon_mqtt.yaml file. Under the MQTT sections of each device type you will find examples and instructions for adding them to Home Assistant. We will be using the Dimmer as our example.</p><pre>light:<br>  - platform: mqtt<br>    schema: json<br>    name: &quot;insteon 1&quot;<br>    state_topic: &quot;insteon/aa.bb.cc/state&quot;<br>    command_topic: &quot;insteon/aa.bb.cc/level&quot;<br>    brightness: true</pre><h3>So what now?</h3><p>At this point we’ve successfully gotten an Insteon dimmer to communicate over MQTT and be integrated into Home Assistant. You can now automate and interact with that switch like any other dimmer that would have been added over Z-Wave or some other protocol.</p><p>I didn’t end up stoping at this point though. In my old setup with Indigo, my Insteon dimmers controlled my Hue bulbs, and the Hue bulbs would update the state of the LED on the dimmers to reflect their brightness.</p><p>Soon I’ll walk through what that process looked like and explain the different approaches I took until finally settling on Node Red being how I managed the automation.</p><p><em>Originally published at </em><a href="https://jordanrounds.com/insteon-mqtt-home-assistant/"><em>https://jordanrounds.com</em></a><em> on June 25, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f65522686909" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Home Assistant + NGINX + Lets Encrypt in Docker]]></title>
            <link>https://medium.com/@jordanrounds/home-assistant-nginx-lets-encrypt-in-docker-439f9b20ea9a?source=rss-669953e65be7------2</link>
            <guid isPermaLink="false">https://medium.com/p/439f9b20ea9a</guid>
            <category><![CDATA[home-assistant]]></category>
            <category><![CDATA[hassio]]></category>
            <category><![CDATA[dns]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Jordan Rounds]]></dc:creator>
            <pubDate>Sun, 19 Apr 2020 23:27:26 GMT</pubDate>
            <atom:updated>2020-04-19T23:27:26.257Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dro9WLmWFD5DsKwX9lAn0A.png" /></figure><p>If you start looking around the internet there are tons of different articles about getting this setup. They all vary in complexity and at times get a bit confusing. I’ve gone down this path before without Docker setting up an Ubuntu instance on Digital Ocean and installing everything from scratch. It was a complete nightmare, but after many many hours or days I was able to get it working. Once I started to understand Docker and had everything running locally at home it seemed like it would be a much easier to maintain there.</p><p>I ditched my Digital Ocean droplet and started researching how to do this in Docker on my home server. There was one requirement, which was I need a container that supported the <a href="https://certbot-dns-dnsimple.readthedocs.io/en/stable/">DNSimple DNS plugin</a> since I host my sites through <a href="https://dnsimple.com/r/1c01efec46ca9d">DNSimple</a>. It turns out there is an absolutely beautiful container linuxserver/letsencrypt that does everything I needed. It supports all the various plugins for certbot.</p><h3>Prerequisites</h3><p>The first thing I did was add an A record with the actual domain (example-domain.com), and a wildcard subdomain (*.example-domain.com) to DNS and pointed it at my home ip. I then forwarded ports 80 and 443 to my home server.</p><h3>docker-compose.yaml</h3><p>Below is the Docker Compose file I setup. Its pretty much copy and paste from their example. The main things to point out are: SUBDOMAINS=wildcard, VALIDATION=dns, and DNSPLUGIN=dnsimple.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8c537ba340c7b4d24997d410fce02e6/href">https://medium.com/media/a8c537ba340c7b4d24997d410fce02e6/href</a></iframe><p>Once that’s saved, you just need to run docker-compose up -d</p><h3>DNSimple Configuration</h3><p>After the container is running you’ll need to go modify the configuration for the DNSimple plugin and put your token in there. To get this token you’ll need to go to your DNSimple Account page and click the Automation tab on the left. Then under API Tokens you’ll click the new button, give it a name, and copy the token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h313F9y7cUrzSnwX0LQlbw.png" /></figure><p>Now that you have the token your going to navigate to config/dns-conf/dnsimple.ini which is wherever you pointed your volume to and paste that token in replacing the default one thats in there. Once you’ve saved that file you can then restart the container with docker-compose restart At this point you should now be able to navigate to your url and will be presented with the default page.</p><h3>NGINX Subdomain Config</h3><p>Next thing I did was configure a subdomain to point to my Home Assistant install. I used the default example that they provide in the documentation for the container and also this <a href="https://blog.linuxserver.io/2019/04/25/letsencrypt-nginx-starter-guide/">post</a> with a few minor changes/additions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1abc75e3495054855ccd37975c819cd6/href">https://medium.com/media/1abc75e3495054855ccd37975c819cd6/href</a></iframe><p>I’ll call out the key changes that I made. For server_name you can enter your subdomain.*. Next you’ll need to add proxy_set_header Upgrade $http_upgrade; and proxy_set_header Connection “upgrade”;. Then finally you’ll need to change your.ip.here to be the internal IP of the machine hosting Home Assistant. Once this is all setup the final thing left to do is run docker-compose restart and you should be up and running.</p><h3>But my IP is dynamic and changes</h3><p>Your home IP is most likely dynamic and could change at anytime. Obviously this will cause issues, and everything we’ve setup will break since that A record will no longer point to the correct place. DNSimple provides an easy solution to this problem. They provide a <a href="https://developer.dnsimple.com/ddns/">shell script</a> for updating DNS with your current IP using the same token approach that the dns plugin for DNSimple that Certbot uses.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce00203d14614fc490575ee176a8f424/href">https://medium.com/media/ce00203d14614fc490575ee176a8f424/href</a></iframe><p>For TOKEN it’s the same process as before. I’m pretty sure you can use the same one generated previously, but I chose to generate a new one. The ACCOUNT_ID I grabbed from the URL when logged into DNSimple. ZONE_ID is obviously the domain being updated. The RECORD_ID I found by clicking on edit for a DNS record, and then pulling the ID from the URL.</p><h3>Automate the Script</h3><p>Once I got that script sorted out, I needed a way to get it to run regularly to make sure the IP was up to date. I opted for creating a Docker container with this being its sole responsibility. Obviously this could just be a cron job you ran on the machine, but what fun would that be?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9dee3fc984518b6d2d52b68347dd7791/href">https://medium.com/media/9dee3fc984518b6d2d52b68347dd7791/href</a></iframe><p>I created the Dockerfile from alpine:3.11. I installed curl so that the script could execute the command. Under /etc/periodic/15min you can drop any scripts you want run and cron will kick them off. I copied the script in there, and then finally need the container to run the command crond -l 2 -f. Thats really all there is to it, so all that was left was to run docker-compose build and then docker-compose up -d and its up and running.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=439f9b20ea9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Smart Home Docker Setup]]></title>
            <link>https://medium.com/@jordanrounds/smart-home-docker-setup-8601fc511f39?source=rss-669953e65be7------2</link>
            <guid isPermaLink="false">https://medium.com/p/8601fc511f39</guid>
            <category><![CDATA[smart-home]]></category>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[home-assistant]]></category>
            <dc:creator><![CDATA[Jordan Rounds]]></dc:creator>
            <pubDate>Sun, 19 Apr 2020 22:02:38 GMT</pubDate>
            <atom:updated>2020-06-05T15:06:40.247Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JUOITpaBdlrMP9D__-K5Fw.png" /></figure><p>Previously I wrote about setting up Home Assistant running in Docker along with Portainer to provide a GUI for management. Since then I’ve spent a fair amount of time coming up with a setup that is something I’m comfortable with and feel is able to be easily maintained. I’m assuming that I’ve gone through a lot of steps that are similar to what others have.</p><p>I got up and running with simple docker run <a href="https://docs.docker.com/engine/reference/run/">commands</a> that were cobbled together from random posts and examples across the internet. I would run the container with its various command line options and tweaking until it worked. Once I got something solid I would copy that into some of my notes so I had it for later. This whole process felt disorganized and likely to end up in a sad failure when I tried to come back to any of it months later when I would have inevitably forgotten how and why I had done anything.</p><p>I then realized that there was docker-compose which initially was quite confusing. Reading the documentation made it seem like it was meant for managing multiple container docker applications, but I only needed one container and initially thought this was an issue. Turns out just because it can support multiple doesn’t mean you cant just run one container. <a href="https://docs.docker.com/compose/compose-file/">Docker Compose</a> files provided a so much nicer and organized approach to setting up the configuration and running a container.</p><h3>Where I stored all of my Docker stuff</h3><p>In /home/docker is what I settled on. Within that directory I created a new directory for each of my containers, and their associated mounts, configs, etc. This ended up looking similar to:</p><pre>/home<br>   |__ /docker<br>         |__ /mosquitto<br>               |__ /config<br>               |__ /log<br>               |__ /data<br>         |__ /portainer<br>         |__ /samba   </pre><p>This seemed easy to wrap my head around, find my data, and navigate.</p><h3>docker run vs. docker-compose up</h3><p>Heres and example of the docker run command to bring up my mosquitto container.</p><pre>sudo docker run -it --name mosquitto -p 1883:1883 -p 9001:9001 -v /home/docker/mosquitto:/mosquitto/config -v /home/docker/mosquitto/data:/mosquitto/data -v /home/docker/mosquitto/log:/mosquitto/log eclipse-mosquitto</pre><p>Now compare that to what it looks like in a docker compose file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b6b2349083364c0bae39eaecf05130d6/href">https://medium.com/media/b6b2349083364c0bae39eaecf05130d6/href</a></iframe><p>Both of these are doing the same thing, but obviously the Docker Compose file is far easier to read.</p><h3>Understanding Volumes</h3><p>So now that I’ve settled on using Docker Compose and it appealing to my need for organization the next step was figuring out what all those -v or volume options actually meant. Since it was just copy paste to start I had no idea what was going on. Realistically it was creating those directories local to where I ran docker compose and persisting the data on the host’s file system. This seemed great at first but requires that that directory structure had to be the same if you were to move the containers to a different host, which is less than ideal.</p><p>It turns out if you don’t declare them Docker takes care of it for you and just creates its own. This led to me to start understanding what <a href="https://docs.docker.com/storage/volumes/">volumes</a> were in Docker, which you can find in:</p><pre>/var/lib/docker/volumes</pre><p>Docker will just give them random names and create them. You also have the option of specifying a volume and giving it your own name, which can also be done in the Docker Compose file.</p><pre>volumes:<br>   data_vol:<br>      name: my-named-volume</pre><p>Doing this will give you named volumes managed by Docker. This seemed like a solid solution, except that everything is then located in /var/lib/docker/volumes It was pretty annoying bouncing over to that directory to change config files, and then back to /home/docker/. This felt like the “right” thing to do, and the proper Docker pattern to follow, but I didn’t like it.</p><h3>Introducing local-persist</h3><p>I was talking with a friend and he told me he had found this Docker volume plugin called <a href="https://github.com/MatchbookLab/local-persist">local-persist</a>. This changed things up quite a bit. I was now able to persist data in a local directory but still have named volumes. The real kicker was that I felt like I still doing things the “right” way. I now had the ability to persist data locally and maintain named volumes. If I removed the volume my data lived on. If I wanted to point those volumes at an external source like my NAS, I now had that option. That original <a href="https://hub.docker.com/_/eclipse-mosquitto">Mosquitto</a> Docker Compose file now turned into this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/145bf3fc2db50377c670fe3934ba8983/href">https://medium.com/media/145bf3fc2db50377c670fe3934ba8983/href</a></iframe><p>That $LOCAL_PERSIST environmental variable is set in /etc/environment to LOCAL_PERSIST=”/home/docker/.local-persist”. This made it easy for me to use it across multiple Docker Compose files.</p><h3>In Conclusion</h3><p>I now feel like I have a pattern of setting up Docker containers using Docker Compose using the local-persist plugin that makes me feel like I’m in control and have something I can easily maintain and move around if I chose to. Everything I have talked about here was learned over the course of a couple weeks and is just my opinion. It’d be great to hear from others what their approach is.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8601fc511f39" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intel NUC + Home Assistant Supervised]]></title>
            <link>https://medium.com/@jordanrounds/intel-nuc-home-assistant-supervised-7cc52d81744a?source=rss-669953e65be7------2</link>
            <guid isPermaLink="false">https://medium.com/p/7cc52d81744a</guid>
            <category><![CDATA[smart-home-automation]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[smart-home]]></category>
            <category><![CDATA[home-assistant]]></category>
            <category><![CDATA[hassio]]></category>
            <dc:creator><![CDATA[Jordan Rounds]]></dc:creator>
            <pubDate>Wed, 08 Apr 2020 23:24:08 GMT</pubDate>
            <atom:updated>2020-04-09T14:44:46.533Z</atom:updated>
            <content:encoded><![CDATA[<h3>Intel NUC + Home Assistant</h3><p>I’ve been running Home Assistant on a Raspberry Pi 4 for around 7 months or so, and have been very happy with it. That being said there were things that were a bit frustrating, such as slow reboot times, and the constant fear of killing the micro sd card. A friend of mine moved his setup over to a NUC (mini pc or whatever it’s called) and had nothing but great things to say, so I decided to make the move.</p><p>I’m going to walk through the steps I took to build and setup the NUC, enable SSH, install Docker and Portainer, and finally get Home Assistant running. I opted for Home Assistant “<a href="https://github.com/home-assistant/supervised-installer">Supervised</a>” <a href="https://www.home-assistant.io/blog/2020/01/29/changing-the-home-assistant-brand/">(formerly Hassio)</a>, not Home Assistant Core, so that I would continue to have the ease of updates, and add ons that I’ve become accustomed to.</p><h3>Putting together the NUC</h3><p>I went around in circles trying to figure out what hardware to buy. Do I want an i3, i5, or i7? Should I get an 10th, 8th, or older generation? Should I just go with the <a href="https://www.amazon.com/dp/B07DKNPPHZ/ref=cm_sw_r_cp_api_i_J.AyEbFP7WV8H">same machine</a> my friend used? At the end of the day I decided to get some current powerful hardware that would allow for me to easily run Home Assistant and any other number of services I might want, as well as just have a more future proof machine to mess with. Heres the hardware I ended up choosing:</p><ul><li><a href="https://www.amazon.com/gp/product/B08357VWB2">Intel Nuc 10 (NUC10i7FNH1)</a></li><li><a href="https://www.amazon.com/gp/product/B01N2VUOBJ">Kingston HyperX Impact 16GB Memory</a></li><li><a href="https://www.amazon.com/gp/product/B07M7Q21N7">Samsung 970 EVO Plus SSD 500GB — M.2 NVMe</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qBQj4SR1JOhk-nwh1aBKwA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iaRiTjvz_pTMMIINkmp-dg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FX-37RWlcyhoZSoVZF0pkg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pgnENBJZ46-ZBBybdD8yyw.jpeg" /></figure><p>First we need to flip the NUC over and remove the 4 screws that hold the cover on, and gently pull the cover off.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kr03R_PKljTVVP96xalaYg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_DjPfxARMdAfS6OPYJf1rw.jpeg" /></figure><p>Next we can install the ssd drive. To do this we will remove the screw back by the usb ports on the rear. Once the screw is out you can slide the ssd drive in and tighten the screw back down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*trL6dGVIvKgiaYbIg5Niyg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z9QK9tre4d223hy31foLhg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BJYEbknmG2di_uNMpEmI_Q.jpeg" /></figure><p>Finally we need to install the Memory. Just slide each module in with the top angled up and then gently push down until it snaps in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H4oGUCzlnuZ7yA0Y7MysTQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35d7E-2oQPX8O3UCXSU9ig.jpeg" /></figure><p>At this point all thats left to do is screw the cover back on, and plug in the power, monitor, and keyboard.</p><h3>Updating the BIOS</h3><p>Since we are starting fresh I figured it wouldn’t hurt to update the bios to the latest version. Obviously this can fail and the whole thing could be bricked, but I was feeling lucky enough. (this step could be skipped)</p><p>To start with go to the <a href="https://downloadcenter.intel.com/search?keyword=bios+aptio">intel download center</a>. Change the operating system to OS Independent and look for the bios for your model of NUC. In this case mine was <a href="https://downloadcenter.intel.com/download/29458/BIOS-Update-FNCML357-">BIOS Update [FNCML357]</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IOAzDfIaKx_7AwVmj-S7mQ.png" /></figure><p>You’ll want to download the FN0039.cap file. The method we’ll be using to do the update is the power button method. The instructions can be found <a href="https://downloadmirror.intel.com/29458/eng/NUC-AptioV-BIOS-Update-Readme.pdf">here</a>, but it’s a pretty straight forward procedure.</p><p>Start off by grabbing a USB drive and it’ll need to be formatted. I used Disk Utility on MacOS and formatted it to MS-DOS (FAT). Once thats done put the .cap file you downloaded on the USB drive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YRndNIhLZTU_uwGSH7BiNQ.png" /></figure><p>With the NUC powered off completely insert the USB Drive. Next, you will hold down the power button for 3 seconds after which it will turn red and you can release it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ASnydDcsp7ARX19TaT1X-w.jpeg" /></figure><p>The NUC will then boot and you’ll be presented with a screen of different options. You’ll want to pick “Update Bios” and therefore can press F7 on the keyboard. Next you’ll be presented with a screen to choose the flash drive, then the .cap file. You’ll see instructions for navigating the screens at the bottom.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fI-Jpvj6aF8jHnISyj_xIw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9hlbmSi-Ei0TDR1GLYKpeA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A4T-JZ-p3ME8Mr0K0itpRg.jpeg" /></figure><p>Eventually you’ll make it through the screens where it’ll ask you to confirm the BIOS update, the NUC will reboot, and you will then see the Flash Update screen showing you the progress of the update.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FyfruGGDkucI1HJeeJQpiA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hsDUtLtvs_AlmUyu-2Id3w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5xzO64D2-WgQLHJI5Ds9CA.jpeg" /></figure><h3>Installing Ubuntu 18.04.4</h3><p>Next we will be downloading ubuntu, imaging a usb drive, and installing the operating system. I opted for the desktop minimal version just to give myself something to mess around with. We will be downloading two things: <a href="https://ubuntu.com/download/desktop">Ubuntu</a> and <a href="https://www.balena.io/etcher/">Balena Etcher</a>. Once they are both downloaded get Etcher installed and opened up. First you’ll select the image for Ubuntu, next you’ll select the USB drive, and then click flash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V4TP3AXKwL3XwKAemMZRwA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x4sC-G1KACONzso2Z6e0nw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*La5Jkl3yecaCu2BUng6uKA.png" /></figure><p>After Ether is finished you can remove the USB drive from the computer and insert it into the NUC with the power off. Now we will do the same thing we did when updating the BIOS and hold down the power button for 3 seconds and then release it. Next you’ll see the same screen from updating the BIOS but this time you will be pressing F10 which will take you to the boot menu. Choose your USB drive, then at the next screen select “Install Ubuntu.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tie8jAp6mqQlD4ezKuqOjg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wyfeYhCTEIzaJDkOy9FA7A.jpeg" /></figure><p>Now all you’ll have to do is walk through Ubuntu’s installer screens and then we are good to go!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jpnpogMHM0UUfwgN_rYOEQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FhWwiG1LM4g_6OJ4nUvMkg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a5Xr5nuo5pENhA2wxRuetw.jpeg" /></figure><h3>Enable SSH</h3><p>I suppose getting SSH working isn’t completely essential but it sure is handy to be able to sit at a laptop and just ssh into the NUC. Also, it’s also pretty straight forward, so why not?</p><pre>sudo apt update</pre><pre>sudo apt install openssh-server<br>(press y)</pre><pre>sudo systemctl enable ssh</pre><pre>sudo ufw allow ssh</pre><pre>sudo ufw enable</pre><p>This should have enabled ssh, and allowed traffic over port 22 through the firewall.</p><h3>Install Docker</h3><p>I chose to install Docker <a href="https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository">using the repository</a> as it’s the recommended method.</p><pre>sudo apt-get update</pre><pre>sudo apt-get install \<br>    apt-transport-https \<br>    ca-certificates \<br>    curl \<br>    gnupg-agent \<br>    software-properties-common</pre><p>Install Docker’s official GPG key and verify the fingerprint (0EBFCD88)</p><pre>curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -</pre><pre>sudo apt-key fingerprint 0EBFCD88</pre><p>Setup the stable repository.</p><pre>sudo add-apt-repository \<br>   &quot;deb [arch=amd64] https://download.docker.com/linux/ubuntu \<br>   $(lsb_release -cs) \<br>   stable&quot;</pre><p>Install Docker Engine</p><pre>sudo apt-get update<br>sudo apt-get install docker-ce docker-ce-cli containerd.io</pre><h3>Install Portainer</h3><p>Installing Portainer is not necessary but is extremely useful as it gives you an actual GUI to interact with Docker. If you are new to Docker like me this will be extremely helpful. First you will create a volume for the portainer data and then create the container.</p><pre>docker volume create portainer_data</pre><pre>docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer</pre><p>Once this is complete you can navigate in your browser to the NUC’s IP address port 9000. (ie: 192.168.7.4:9000) From there you will be prompted to create the admin account, then choose the Docker environment you want to manage, which is “Local.” After connecting to local you will be logged in and presented with a screen similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jHT8yIvr3QzEe3bvdYUNVQ.png" /><figcaption>Portainer Home</figcaption></figure><p>From here you will be able to navigate around to view your containers, volumes, etc.</p><h3>Installing Home Assistant — Finally!</h3><p>So looking around the internet there didn’t seem to be a ton of tutorials installing what was called Hassio in Docker. I found one <a href="https://www.smarthomebeginner.com/install-hass-io-on-docker-linux/"><em>here</em></a> and <a href="https://dew-itwebservices.com.au/installing-and-running-hassio-in-docker-on-an-intel-nuc/"><em>here</em></a>. They are both pretty similar but out of date, since the URL to the repo has changed. The new repo for Home Assistant Supervised lives <a href="https://github.com/home-assistant/supervised-installer">here</a>. It took me a while to figure out what changed, what the correct URL was, etc. Because of the name changes I even glazed over the <a href="https://www.home-assistant.io/hassio/installation/#alternative-install-home-assistant-supervised-on-a-generic-linux-host">official documentation</a> not realizing it was exactly what I needed. Run the commands listed below and Home Assistant will be installed and running in its various Docker containers.</p><pre>sudo su</pre><pre>add-apt-repository universe</pre><pre>apt-get install bash jq curl avahi-daemon dbus software-properties-common apparmor-utils apt-transport-https ca-certificates network-manager socat</pre><pre>systemctl disable ModemManager </pre><pre>systemctl stop ModemManager</pre><pre>curl -sL https://raw.githubusercontent.com/home-assistant/supervised-installer/master/installer.sh | bash -s -- -m intel-nuc -d /home/docker/hassio</pre><p>There are two things to call out:</p><ul><li>-m is the machine type (in our case intel-nuc)</li><li>-d is me saying I want the default data storage location</li></ul><p>There are a few other options for the installer that are explained on the Github <a href="https://github.com/home-assistant/supervised-installer">page</a>.</p><p>You will then need to navigate to (your-nuc-ip:8123) and you’ll be prompted to setup your user for Home Assitant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iGZ7tkvftur5x-ej9U7iKw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NCST14ESNSgwIt5nCt7Dmg.png" /></figure><h3>In Conclusion</h3><p>The whole setup process is definitely a bit more complex than installing Home Assistant on a Raspberry Pi, but now that I’m setup on the NUC everything is so much more snappy and I feel like I’m more in control and have options I didn’t know existed. That control definitely comes with quite the learning curve, but if you’re patient and willing to do some reading its totally worth it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7cc52d81744a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding Sonoff Basic R2 flashed with Tasmota to Home Assistant]]></title>
            <link>https://medium.com/@jordanrounds/adding-sonoff-basic-r2-flashed-with-tasmota-to-home-assistant-2f5721e93001?source=rss-669953e65be7------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f5721e93001</guid>
            <category><![CDATA[home-assistant]]></category>
            <category><![CDATA[home-automation]]></category>
            <category><![CDATA[tasmota]]></category>
            <category><![CDATA[smart-home]]></category>
            <category><![CDATA[sonoff]]></category>
            <dc:creator><![CDATA[Jordan Rounds]]></dc:creator>
            <pubDate>Mon, 16 Dec 2019 22:54:59 GMT</pubDate>
            <atom:updated>2019-12-16T22:54:59.851Z</atom:updated>
            <content:encoded><![CDATA[<p>I used a couple Sonoff Basics to automate my Christmas lights this year. I setup a few automations based on how we wanted them to turn on and off. We are going to walk through manually adding a <a href="https://amzn.to/2sY3XNM">Sonoff Basic R2</a> flashed with the <a href="https://github.com/arendst/Tasmota">Tasmota</a> software without using auto discovery. Then we will setup a basic automation. If you haven’t already flashed and configured Tasmota you might want to checkout my article about that first.</p><p><a href="https://medium.com/@jordanrounds/sonoff-basic-r2-tasmota-aa6f9d4e033f">Sonoff Basic R2 + Tasmota</a></p><h4>Switch Template:</h4><p>The template is pretty straight forward, and you can reference the docs for adding an <a href="https://www.home-assistant.io/integrations/switch.mqtt/">MQTT Switch</a> and all the different configuration options that are available. You can copy the template below into <em>config/configuration.yaml</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d43350888749a1b02b24484ba865b745/href">https://medium.com/media/d43350888749a1b02b24484ba865b745/href</a></iframe><p>This switch template is assuming you used the same topic formatting in my other article. Be sure your topics match what you configured in the Tasmota web ui.</p><h4>The Automation</h4><p>This automation will turn on the lights in the morning around when I get up, then shut them off again around work. They then come on at night and shut off around bed time.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/805c87d15b471ed65a10d4ab3a66f648/href">https://medium.com/media/805c87d15b471ed65a10d4ab3a66f648/href</a></iframe><p>If you were using this automation for outdoor lights you might want to use the <a href="https://www.home-assistant.io/cookbook/automation_sun/">trigger</a> for sunrise and sunset.</p><pre>trigger:<br>  platform: sun<br>  event: sunrise</pre><h4>Wrapping Up</h4><p>All thats left to do at this point is to check the config, and if there are no errors then restart Home Assistant. In the left nav click on Configuration and then Server Control. You’ll see this screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WZ3Ec6r8-G1kUlYhsnsFxg.png" /></figure><p>Once you’re here click the Check Config button and give it a minute. You should see a Configuration valid message. If not you will see errors telling you the lines that have the issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zyn5-jnXlSCb2Wq5gWr5VA.png" /></figure><p>After the configuration is validated, click the restart button down at the bottom to restart Home Assistant.</p><p>Now you’re set to go with some automated Christmas lights.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f5721e93001" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sonoff Basic R2 + Tasmota]]></title>
            <link>https://medium.com/@jordanrounds/sonoff-basic-r2-tasmota-aa6f9d4e033f?source=rss-669953e65be7------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa6f9d4e033f</guid>
            <category><![CDATA[sonoff]]></category>
            <category><![CDATA[esp8266]]></category>
            <category><![CDATA[home-assistant]]></category>
            <category><![CDATA[tasmota]]></category>
            <category><![CDATA[mqtt]]></category>
            <dc:creator><![CDATA[Jordan Rounds]]></dc:creator>
            <pubDate>Fri, 13 Dec 2019 21:53:51 GMT</pubDate>
            <atom:updated>2019-12-16T22:56:35.288Z</atom:updated>
            <content:encoded><![CDATA[<h3>Sonoff Basic R2 + Tasmota (no solder)</h3><p>This is a walkthrough of flashing a Sonoff Basic R2 device with the <a href="https://github.com/arendst/Tasmota">Tasmota</a> firmware so that it can connect to an MQTT broker.</p><p>I decided to write this because I wanted an easy way to automate my Christmas lights through Home Assistant. Doing this for the first time offered many different paths and the internet is full of a bunch of tutorials. Mainly I wanted to put together a clear end to end of everything needed and how to do it using macOS. All setup and screenshots will be done using macOS Catalina. The one assumption made is that you’ve already got an MQTT broker setup.</p><h4><strong>Hardware used:</strong></h4><p><a href="https://amzn.to/2P9lQlG">USB Serial Adapter</a></p><p><a href="https://amzn.to/2LXk6Kj">Jumper Wires</a> or <a href="https://amzn.to/34a059s">Header Pins</a></p><p><a href="https://amzn.to/2sY3XNM">Sonoff Basic R2</a></p><h4><strong>Software used:</strong></h4><p><a href="https://github.com/marcelstoer/nodemcu-pyflasher">NodeMCU PyFlasher</a></p><p><a href="https://www.ftdichip.com/Drivers/VCP.htm">FTDI VCP Drivers</a></p><p><a href="https://github.com/arendst/Tasmota/releases">tasmota.bin</a></p><p><a href="http://workswithweb.com/mqttbox.html">MQTTBox</a></p><h3>Start with the Software</h3><h4>Download Tasmota</h4><p>You can download the latest version of Tasmota from the <a href="https://github.com/arendst/Tasmota/releases">releases page</a> on Github. The current version as of writing this is <a href="https://github.com/arendst/Tasmota/releases/tag/v7.1.2">v7.1.2</a>. Scroll down through the list and download the file named tasmota.bin towards the end of the list of files.</p><p><em>Note: There are others you can use most of which are in various different languages. An explanation of the different versions is on the release page if you are interested. Once downloaded set that to the side for now.</em></p><h4>Let’s download and install PyFlasher.</h4><p><a href="https://github.com/marcelstoer/nodemcu-pyflasher/releases">Here</a> you will find the releases page on Github. Go ahead and grab the latest release, which currently is <a href="https://github.com/marcelstoer/nodemcu-pyflasher/releases/tag/v4.0">V4.0</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J-lFgU-BV3BhlOrgGxR0fA.png" /><figcaption>Drag, Drop, Done</figcaption></figure><h4>Next download the <a href="https://www.ftdichip.com/Drivers/VCP.htm">driver</a> for the USB Serial Adapter from FTDI.</h4><p>Be sure to pick the right one for the operating system you are on. Installing this on macOS is fairly straight forward with one gotcha.</p><p>During the installation you are going to have to allow the install through Security &amp; Privacy within System Preferences. Under the general tab there is a section labeled “Allow apps downloaded from.” Here you will see a button to click to allow the new driver install. Without doing this the USB Serial Adapter will never show up.</p><p>You should see a notification like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0uxnBP8ozx3oiqu2K8xRgw.png" /><figcaption>Click Open Security Preferences</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*suA-NY-nbIpCsIB5mmV_dw.png" /><figcaption>Click the lock in the lower left and enter your password. Then click the Allow button.</figcaption></figure><h3>Moving on to prepping the Sonoff R2</h3><h4>Rip everything apart!</h4><p>First step is to take the caps off the left and the right side of the R2. Then you are going to push the back plastic through the openings on the left and right to detach the top from the bottom.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Oj2Z_pfM_FT28NJiGX5qfQ.jpeg" /><figcaption>Step 1: Remove the left and right caps</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GELmuPFQVm3EUeZPpp9vEQ.jpeg" /><figcaption>Step 2: Remove the front from the back.</figcaption></figure><p>Once thats all done you will just be needing the board and can set everything else off to the side.</p><h4>Next let’s get the USB to serial adapter ready.</h4><p>Make sure the little black jumper is connecting the 3v3 pin to the JP pin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f9GdpiCVU5X8MZv3HGbrKw.jpeg" /><figcaption>Make sure we have the correct voltage set for the Sonoff R2</figcaption></figure><p>Go ahead and connect your four jumper wires to the remaining pins, which are RXD, TXD, GND, and VCC.</p><p><em>Note: If you don’t have jumper wires and want to use the cable that came with the serial adapter, you could alternatively insert some header pins into the female end of that cable and have the same setup as below.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_SOYauZ62RCNmHgemkt6Cw.jpeg" /><figcaption>Jumper wires connected.</figcaption></figure><p>Through the back of the board insert the jumper wire pins into the appropriate holes. They are as follows from the serial adapter to the R2 board.</p><ul><li>GNG → GND</li><li>VCC → 3V3</li><li>TXD → RX</li><li>RXD → TX</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gO95JftySPuc_OJK934j4A.jpeg" /><figcaption>Jumper wires through the back of the board.</figcaption></figure><p>If you have the serial adapter plugged in you should see the R2 start to light up and flash green. Now turn the board over and let it rest on the jumper wires.</p><h3>Flashing time!</h3><h4>Get the R2 into programming mode.</h4><p>Everything is now set to begin flashing the board.</p><ol><li>Unplug the serial adapter.</li><li>Hold down the tall black button.</li><li>Plug in the serial adapter.</li><li>Release the button.</li></ol><p>The ESP8266 chip on the R2 board will now be in programming mode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*my4lxeu3RR_vMqAI0TJM0A.jpeg" /><figcaption>Finger + Button</figcaption></figure><h4>Flashing Settings</h4><p>Open up NodeMCU PyFlasher.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8aKNiM_Fl_5an-aFb_UWdg.png" /></figure><p>First click the select box for Serial port and look to see that your serial adapter shows up.</p><p><em>Note: If it doesn’t show up try pressing the refresh button to the right. If it still doesn’t show up, try restarting your computer to fix the issue.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mlfEM8sKaNck3WHGsYUN4g.png" /><figcaption>usbserial-AC01A7BM is our serial adapter</figcaption></figure><p>Click the browse button and select the location where you downloaded tasmota.bin. Next select the following settings.</p><ul><li>Baud rate: 115200</li><li>Flash mode: Dual Output</li><li>Erase flash: yes</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VxfkQMDGHzQ6D_zZ4m8kjw.png" /><figcaption>All the proper settings</figcaption></figure><p>After you have everything set, click the Flash NodeMCU button and wait until it tells you to restart the R2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HAjPX9eqMX17YooDK-eauQ.png" /><figcaption>Success!</figcaption></figure><p>At this point unplug the serial adapter and plug it back in to get the R2 to reboot.</p><h3>Time to Configure Tasmota</h3><h4>Setup Wifi</h4><p>Open the wifi settings on your phone. Look for a network being broadcast thats named tasmota-xxxx where xxxx will be some numbers. Tap on that network and you should be prompted with a wifi configuration screen.</p><p>Next you can tap the Scan for wifi networks link and then select your network from the list that shows up or directly enter the ssid into the AP1 SSId field. Then enter your password in the AP1 Password field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*ukS4Iv7pbQJ3WbH0W7Oaqw.png" /></figure><p>Once you have everything entered tap on the Save button and you will see a screen telling you the R2 is restarting and connecting to your network.</p><h4>Get the IP Address</h4><p>After the Sonoff R2 restarts and connects to your network you’ll need to get its ip address.</p><p><em>Note: This can be done through your router or an ip scanner application. It will show up with a hostname of tasmota-xxxx just as it did when we connected to it through wifi in the previous step.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*AtMMRAbH64T5BPPGfA8PDg.png" /></figure><p>The photo here is an example of what I saw when looking for the newly connected wifi device inside of my Eero App.</p><h4>Open Tasmota</h4><p>In your browser put in the ip address and you will see the main page for your R2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ASMXxeRKao_Fj_AlUw9Zmg.png" /></figure><p>Next click on Configuration and then Configure MQTT and you will see a screen like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JnzjHBKLad-l_P1CAD-P9A.png" /></figure><p>Start by entering in the hostname or ip of your MQTT broker. Optionally a different port, username and password. The topic should be a unique identifier for your R2, so go ahead and change the default of Tasmota to whatever you’d like to name it.</p><p>At this point you could simply save and the Sonoff R2 would now be sending and receiving MQTT messages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gZ5kRrrAm7iVu1Pos_Ne8g.png" /><figcaption>Example of my settings</figcaption></figure><p><em>Note: I did make the conscious choice to configure my Tasmota flashed devices manually with Home Assistant and not use the auto discovery feature for no other reason that I wanted complete control and the auto discovery scares me. I also added Tasmota to the beginning of the full topic and all future devices I add will use Tasmota as the root of their topics as well.</em></p><h4>What will the topics look like?</h4><p>You’ve defined your unique %topic% and the %prefix% will be one of 3 things: cmd, stat, and tele. Cmd is for issuing commands or asking for status. Stat will report back status or configuration messages. Tele will report telemetry info.</p><p>In my case an example topic would be:</p><pre>tasmota/stat/sonoff_basic</pre><p>The payload might look like:</p><pre>{“POWER”:”ON”}</pre><p><em>Note: I used </em><a href="http://workswithweb.com/mqttbox.html"><em>MQTTBox</em></a><em> to do my testing.</em></p><h4>Optional Configuration</h4><p>I also went into Configuration → Configure Other and changed the Friendly Name to be the same as the Topic name that I configured in MQTT.</p><p>The final thing I did was set the PowerRetain option in the console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gSHBs5Znk8UOVZ3JB-r3Ug.png" /></figure><p>From the main menu click on Console. In the input type “PowerRetain ON” and press return. The state of the power messages will now be retained and anytime something such as Home Assistant connects to the broker they will know the last state of the device.</p><h3>Putting it Back Together</h3><p>So, I chose to add the R2 to an <a href="https://amzn.to/36yYiMU">extension cord</a>, but you could easily do the same thing to add it directly to the cord of anything you want to plug into an outlet. I used an extension cord since this is going to control my Christmas lights and I’d like to reuse it for other things once Christmas is over.</p><p>First go ahead and pop the R2 board back into the plastic enclosure. Set it in the base and snap the top on. The first time I did this I attached the cord before doing this and then realized I had to take the whole thing apart again.</p><p>Next let’s get the extension cord ready. You’ll need a <a href="https://amzn.to/34kN6le">wire stripper</a> and a scissors or knife.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HwJoTSo-jiWUH66e-zbKpA.jpeg" /><figcaption>Supplies</figcaption></figure><p>Start off by cutting the extension cord. I cut mine near the plug and gave it enough length that the R2 will rest on the ground. You can make the cord whatever length you’d like so if you want a 1 foot cord just cut off the excess.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E1KUyLrj-XuZpwoLy2N4gg.jpeg" /><figcaption>Cut and stripped</figcaption></figure><p>Once you have it cut, take a scissors or knife and cut between the two wires about a half inch or so. Then take the wire stripper and strip about 1/4&quot; off. It really doesn’t need to be much.</p><p><em>Note: You might be wondering which wire goes in L (load) and which goes in N (neutral). If you look and feel the cord you’ll notice that one side is smooth and one is ribbed or not smooth. The not smooth one will be inserted into N.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XGohWaW9fu2G1MQpG-CI8Q.jpeg" /></figure><p>Insert the male end or piece of the cord with the actual plug in the end of the R2 that says Input. Then tighten it down with a small flat head screwdriver.</p><p>Ribbed Wire → N</p><p>Smooth Wire → L</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kMPhzYfU9B9uv6qnTmX1GQ.jpeg" /><figcaption>Tight but not too tight.</figcaption></figure><p>Do the same with the other end of the extension cord on the Output side of the R2. Once both parts of the cord are secured put the caps on either side and tighten down the screws included in the box with a small phillips screwdriver.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LgnYqAyJu1_VKOHpMpouQw.jpeg" /></figure><p>Now go plug it in and you are set to go!</p><h3>Wrapping Up</h3><p>These are all the steps for setting up the Sonoff R2 using Tasmota and getting it talking with your MQTT broker. At this point you can integrate and control it however you would like either via its web interface or over MQTT. In another article I’ll show how to manually add these devices to Home Assistant, and setup some basic automations.</p><p><a href="https://medium.com/@jordanrounds/adding-sonoff-basic-r2-flashed-with-tasmota-to-home-assistant-2f5721e93001">Adding Sonoff Basic R2 flashed with Tasmota to Home Assistant</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa6f9d4e033f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>