<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Martynas Kan</title>
    <description>The latest articles on DEV Community by Martynas Kan (@martis347).</description>
    <link>https://dev.to/martis347</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F55762%2F0c73f09b-44f1-4252-8ea9-8f6b92ad9fef.PNG</url>
      <title>DEV Community: Martynas Kan</title>
      <link>https://dev.to/martis347</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/martis347"/>
    <language>en</language>
    <item>
      <title>How I got from Zero to Hero in Home Automation</title>
      <dc:creator>Martynas Kan</dc:creator>
      <pubDate>Sat, 02 Feb 2019 20:42:41 +0000</pubDate>
      <link>https://dev.to/martis347/how-i-got-from-zero-to-hero-in-home-automation-48jm</link>
      <guid>https://dev.to/martis347/how-i-got-from-zero-to-hero-in-home-automation-48jm</guid>
      <description>&lt;h1&gt;
  
  
  How it all started
&lt;/h1&gt;

&lt;p&gt;IoT and Home Automation these few years have been on the rise.&lt;/p&gt;

&lt;p&gt;For me everything started some time about 3 years ago when I heard what an Arduino is.&lt;br&gt;
Fast forward a year or so, I'm getting better with building stuff using this small micro controller. I have multiple LED strips, temperature sensors, displays and so on.&lt;br&gt;
Step by step I was making my room controlled by my smartphone.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F5jdawom.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F5jdawom.jpg" alt="How one of my drawers looks right now"&gt;&lt;/a&gt;&lt;/p&gt;
How one of my drawers looks right now 🙃


    

&lt;h1&gt;
  
  
  Let's get technical
&lt;/h1&gt;

&lt;h2&gt;
  
  
  What does the set-up consist of?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Central gateway that's running my Node.js service&lt;/li&gt;
&lt;li&gt;2 Lamps controlled by microcontrollers&lt;/li&gt;
&lt;li&gt;1 Individually addressable LED strip&lt;/li&gt;
&lt;li&gt;A set of speakers&lt;/li&gt;
&lt;li&gt;Everything's controlled by a PWA (Progressive Web App) or by Google assistant&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This central gateway is a &lt;a href="https://www.khadas.com/vim" rel="noopener noreferrer"&gt;Khadas VIM&lt;/a&gt; Single board computer that's running on Ubuntu.&lt;br&gt;
Microcontrollers that I'm using are &lt;a href="https://www.nodemcu.com/index_en.html" rel="noopener noreferrer"&gt;NodeMCU&lt;/a&gt; (You might ask why not arduino? These little babies have built in Wifi + they are pretty cheap!)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fforum.khadas.com%2Fuploads%2Fdefault%2Foriginal%2F1X%2F2356700c782c5efa8db0c1e4e50bea812fc9b63e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fforum.khadas.com%2Fuploads%2Fdefault%2Foriginal%2F1X%2F2356700c782c5efa8db0c1e4e50bea812fc9b63e.png" alt="Picture of Khadas VIM"&gt;&lt;/a&gt;&lt;/p&gt;
Picture of Khadas VIM



&lt;h2&gt;
  
  
  Architecture
&lt;/h2&gt;

&lt;p&gt;As I've mentioned there's a central gateway that takes care of everyting.&lt;br&gt;
It's running a basic Node.js Express server and depending on the request a certain microcontroller is called. The communication with microcontrollers uses http in the local network.&lt;br&gt;
Gateway itself is publicly exposed through my router so I could access it from anywhere.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lamps
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Ffritzing.org%2Fmedia%2FCACHE%2Fimages%2Ffritzing-repo%2Fprojects%2Fi%2Fiot-switch-onoff-220-240v-device-with-nodemcu-5v-r%2Fimages%2FFritzing%2Ffc584c411b025ee1bd6523709106b2b5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Ffritzing.org%2Fmedia%2FCACHE%2Fimages%2Ffritzing-repo%2Fprojects%2Fi%2Fiot-switch-onoff-220-240v-device-with-nodemcu-5v-r%2Fimages%2FFritzing%2Ffc584c411b025ee1bd6523709106b2b5.png" alt="Diagram for lamp connection"&gt;&lt;/a&gt;&lt;/p&gt;
Diagram for lamp connection



&lt;p&gt;There are two primary lamps (one on the wall and another on the ceiling) in my room.&lt;br&gt;
Each lamp is controlled by the NodeMCU using a 220v relay.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lights Strip
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs2.gifyu.com%2Fimages%2Fezgif.com-video-to-gife0179c0e5b39833e.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs2.gifyu.com%2Fimages%2Fezgif.com-video-to-gife0179c0e5b39833e.gif" alt="How my lights strip looks like"&gt;&lt;/a&gt;&lt;/p&gt;
How my lights strip looks like



&lt;p&gt;The control of the lights strip is pretty basic, just a standard hook-up which I don't want to go into detail with.&lt;/p&gt;

&lt;h3&gt;
  
  
  Speakers
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FlaPkXCo.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FlaPkXCo.jpg" alt="Speakers setup"&gt;&lt;/a&gt;&lt;/p&gt;
Speakers setup



&lt;p&gt;I'm pretty proud of this one. The speakers I'm using are &lt;a href="https://www.edifier.com/int/en/speakers/r2730db-bluetooth-bookshelf" rel="noopener noreferrer"&gt;Edifier R2730&lt;/a&gt;&lt;br&gt;
The only way to control these is using a remote control that comes with them or using the controls, that are built into the speaker itself.&lt;/p&gt;

&lt;p&gt;My solution was to read the IR code of the remote, save the codes and then repeat them using an IR led with my NodeMCU.&lt;br&gt;
So right now there's a NodeMCU that's been taped to my speakers (but it's unnoticable visually) which controls them remotely.&lt;/p&gt;

&lt;h3&gt;
  
  
  PWA
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs2.gifyu.com%2Fimages%2Fezgif.com-video-to-gif-2e0dac0bb0b0eff44.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs2.gifyu.com%2Fimages%2Fezgif.com-video-to-gif-2e0dac0bb0b0eff44.gif" alt="Overview of the PWA"&gt;&lt;/a&gt;&lt;/p&gt;
Overview of the PWA



&lt;p&gt;The central gateway is controlled by my PWA that was built using &lt;a href="https://vuejs.org/" rel="noopener noreferrer"&gt;Vue.js&lt;/a&gt; and &lt;a href="https://vuetifyjs.com/en/" rel="noopener noreferrer"&gt;Vuetify&lt;/a&gt;.&lt;br&gt;
The PWA is deployed on a free instance of an Azure Web App. &lt;br&gt;
Every call that goes to the Gateway is proxied through a Node.js service, that runs on the same Web App.&lt;br&gt;
But &lt;strong&gt;why&lt;/strong&gt; did I proxy every call? It adds additional overhead and delay for each HTTP call. But there's one catch! For a PWA you &lt;strong&gt;must&lt;/strong&gt; serve it on HTTPS and every call must be using &lt;strong&gt;HTTPS&lt;/strong&gt; as well! And my gateway is just an IP address, thus I had to proxy everyting though the Azure Web App that provides a free SSL certificate.&lt;/p&gt;

&lt;h3&gt;
  
  
  Google Assistant
&lt;/h3&gt;

&lt;p&gt;I actually bought a Google Home mini solely to hook it up to this system. 😄 (But it also works with my phone as well)&lt;br&gt;
The Gateway contains a small AI-like algorithm that is processing the input received from Google Assistant.&lt;br&gt;
This speech input is received with the help of &lt;a href="https://ifttt.com/google_assistant" rel="noopener noreferrer"&gt;IFTTT&lt;/a&gt;. And after that it's just invoking the microcontrollers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F1AraF4i.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F1AraF4i.jpg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;
"An AI-like solution"



&lt;h1&gt;
  
  
  Closing words
&lt;/h1&gt;

&lt;p&gt;I've been working on this system from time to time for over a year now. It actually started as a React Native App which later turned out to be not the best solution.&lt;br&gt;
Me and my Girlfriend are using it every day and I hope to extend it even further.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgflip.com%2F2sp4sp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgflip.com%2F2sp4sp.jpg"&gt;&lt;/a&gt;&lt;br&gt;
It's very satisfying to just say "Hey Google, I'm Home" and then the lights come up, the speakers are playing your favourite radio station and you can just relax and get to coding what you love 😊. Or if's getting late, you're reading your last post on Dev.to and after you decide to get to sleep you don't even have to lift your ass off the bed to turn of the lights and radio 😁.&lt;/p&gt;

&lt;p&gt;There are quite a lot of details/features I did not mention. If this post gets some attention I could create a more technical series about it.&lt;br&gt;
For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OTA updates for NodeMCU's&lt;/li&gt;
&lt;li&gt;Playing audio from Youtube though my gateway&lt;/li&gt;
&lt;li&gt;My tablet setup (Yes, I have a tablet mounted on my wall 😬)&lt;/li&gt;
&lt;li&gt;Processing the words received from Google Assistant&lt;/li&gt;
&lt;li&gt;Built-in Alarm Clock&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;P.S.&lt;/strong&gt; After writing this article I've looked up the &lt;a href="https://trends.google.com/trends/explore?date=today%205-y&amp;amp;geo=US&amp;amp;q=%2Fm%2F02vnd10" rel="noopener noreferrer"&gt;Google Trends&lt;/a&gt; for Home Automation and IoT and it seems, that it's popularity is going down these past couple years 😲.&lt;/p&gt;

</description>
      <category>iot</category>
      <category>smarthome</category>
      <category>googleassistant</category>
      <category>nodemcu</category>
    </item>
  </channel>
</rss>
