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.
- 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!)
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.
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.
The control of the lights strip is pretty basic, just a standard hook-up which I don't want to go into detail with.
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.
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.
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.
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.
- 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 😲.