loading...
Cover image for How I got from Zero to Hero in Home Automation

How I got from Zero to Hero in Home Automation

martis347 profile image Martynas Kan ・4 min read

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

How one of my drawers looks right now 🙃

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 Single board computer that's running on Ubuntu.
Microcontrollers that I'm using are NodeMCU (You might ask why not arduino? These little babies have built in Wifi + they are pretty cheap!)

Picture of Khadas VIM

Picture of Khadas VIM

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

Diagram for lamp connection

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

How my lights strip looks like

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

Speakers setup

I'm pretty proud of this one. The speakers I'm using are Edifier R2730
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

Overview of the PWA

The central gateway is controlled by my PWA that was built using Vue.js and Vuetify.
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. And after that it's just invoking the microcontrollers.

"An AI-like solution"

"An AI-like solution"

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.

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 for Home Automation and IoT and it seems, that it's popularity is going down these past couple years 😲.

Posted on by:

martis347 profile

Martynas Kan

@martis347

A passionate developer. If I'm not coding at my job right now, it means I'm coding at home.

Discussion

markdown guide
 

I guess you could have a constant ping from the gateway to your local phone IP address for a simple presence detection:) looks good!
Check out Node-RED for more complex gateway flows, it really speeds up some task.

 

Nice setup and nice write up. I'm always curious about how other people tackle their smart home setups. I've shared my experience here too, after the first year of living with Home Assistant - dev.to/jumpalottahigh/living-with-...

 

Isn't it pretty weird that you need to tell Google that you're home?

 

Why do you think that's weird?
It's just a feature to turn music and lights in a single command.

 

I have just been wondering why Google doesn‘t already know you‘re home.

Oh. Of course I could set it up like that, but since I live with my GF, she might already be home, thus I would not even need to turn anything on :)