How I got from Zero to Hero in Home Automation
Tags: iot, smarthome, googleassistant, nodemcu
Published: 2019-02-02 20:42:41

---
title: How I got from Zero to Hero in Home Automation
published: true
description: A brief picture of my Home Automation Platform that I was working on lately
tags: IoT, Smarthome, Google Assistant, NodeMCU
cover_image: https://i.ytimg.com/vi/I1Tvl0bc2Lk/maxresdefault.jpg
---



# How it all started
IoT and Home Automation these few years have been on the rise.

For me everything started some time about 3 years ago when I heard what an Arduino is.
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.
Step by step I was making my room controlled by my smartphone.

![How one of my drawers looks right now](https://i.imgur.com/5jdawom.jpg)
<figcaption>How one of my drawers looks right now 🙃</figcaption>
	
# Let's get technical
## What does the set-up consist of?
* Central gateway that's running my Node.js service
* 2 Lamps controlled by microcontrollers
* 1 Individually addressable LED strip
* A set of speakers
* Everything's controlled by a PWA (Progressive Web App) or by Google assistant

This central gateway is a [Khadas VIM](https://www.khadas.com/vim) Single board computer that's running on Ubuntu.
Microcontrollers that I'm using are [NodeMCU](https://www.nodemcu.com/index_en.html) (You might ask why not arduino? These little babies have built in Wifi + they are pretty cheap!)

![Picture of Khadas VIM](https://forum.khadas.com/uploads/default/original/1X/2356700c782c5efa8db0c1e4e50bea812fc9b63e.png)
<figcaption>Picture of Khadas VIM</figcaption>

## Architecture
As I've mentioned there's a central gateway that takes care of everyting.
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.
Gateway itself is publicly exposed through my router so I could access it from anywhere.

### Lamps
![Diagram for lamp connection](http://fritzing.org/media/CACHE/images/fritzing-repo/projects/i/iot-switch-onoff-220-240v-device-with-nodemcu-5v-r/images/Fritzing/fc584c411b025ee1bd6523709106b2b5.png)
<figcaption>Diagram for lamp connection</figcaption>
There are two primary lamps (one on the wall and another on the ceiling) in my room.
Each lamp is controlled by the NodeMCU using a 220v relay.

### Lights Strip
![How my lights strip looks like](https://s2.gifyu.com/images/ezgif.com-video-to-gife0179c0e5b39833e.gif)
<figcaption>How my lights strip looks like</figcaption>
The control of the lights strip is pretty basic, just a standard hook-up which I don't want to go into detail with.

### Speakers
![Speakers setup](https://i.imgur.com/laPkXCo.jpg)
<figcaption>Speakers setup</figcaption>
I'm pretty proud of this one. The speakers I'm using are [Edifier R2730](https://www.edifier.com/int/en/speakers/r2730db-bluetooth-bookshelf)
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.

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.
So right now there's a NodeMCU that's been taped to my speakers (but it's unnoticable visually) which controls them remotely.

### PWA
![Overview of the PWA](https://s2.gifyu.com/images/ezgif.com-video-to-gif-2e0dac0bb0b0eff44.gif)
<figcaption>Overview of the PWA</figcaption>

The central gateway is controlled by my PWA that was built using [Vue.js](https://vuejs.org/) and [Vuetify](https://vuetifyjs.com/en/).
The PWA is deployed on a free instance of an Azure Web App. 
Every call that goes to the Gateway is proxied through a Node.js service, that runs on the same Web App.
But **why** did I proxy every call? It adds additional overhead and delay for each HTTP call. But there's one catch! For a PWA you **must** serve it on HTTPS and every call must be using **HTTPS** 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.

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

!["An AI-like solution"](https://i.imgur.com/1AraF4i.jpg)
<figcaption>"An AI-like solution"</figcaption>

# Closing words

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.
Me and my Girlfriend are using it every day and I hope to extend it even further.
![](https://i.imgflip.com/2sp4sp.jpg)
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 😁.


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.
For example:
* OTA updates for NodeMCU's
* Playing audio from Youtube though my gateway
* My tablet setup (Yes, I have a tablet mounted on my wall 😬)
* Processing the words received from Google Assistant
* Built-in Alarm Clock


**P.S.** After writing this article I've looked up the [Google Trends](https://trends.google.com/trends/explore?date=today%205-y&geo=US&q=%2Fm%2F02vnd10) for Home Automation and IoT and it seems, that it's popularity is going down these past couple years 😲.