Node-Red can make your home smart
written by Pranav Chakkarwar
published on 19 Nov 2020
Update
This is an outdated solution. Take a look at my better approach.
Also, Heroku has decided to retire it’s free tier, so it’s not free (as in price) anymore.
Home, Office, Industrial Automation, and control using Node-Red, Heroku, MQTT, Raspberry Pi, other edge IoT devices (like esp8266, Arduino, etc.)
Advantages of using this solution
-
It is an open-source solution (So you are the one in control of the critical internal data, not a multi-national conglomerate).
-
The dashboard is available over the internet but password protected. For more security, we can use a free OpenVPN server (in the cloud or on our Raspberry Pi)
-
It’s free, so why NOT!!! (Except you need to pay for the hardware lol)
-
Your Node JS app will never sleep.
Features
-
Access the Control center from anywhere in the world.
-
Control will be transferred locally to the Raspberry Pi (ex - in case of internet failure)
-
Easily change automation rules or rewire controls with instant deployment.
-
Automation rules can get as complex as you like.
-
It is effortless to integrate third-party APIs like the OpenWeatherMap.
-
AND MUCH MORE TO EXPLORE.
Requirements
Hardware
-
Edge IoT devices (I am using esp-01 for demonstration)
-
Raspberry Pi for local control and override rules (Note: The Raspberry Pi control center can also be accessed remotely on demand)
-
Relay boards or Custom PCB boards
-
And other devices like CCTV’s (optional)
Other requirements
-
App platform to deploy the project (I am using Heroku)
-
MQTT provider. I am using Hive Public MQTT Brokers. Not recommended for final deployments
Initial setup and deployment
-
Fork the Node-Red Repo (This easiest way that I found while writing this post)
-
Recommended settings change for the Node app
-
In the forked repo edit settings.js as requried (located at yourgithubusername/node-red/packages/node_modules/node-red/)
-
Uncomment httpAdminRoot: ‘/admin’,
-
Uncomment and change ui: { path: “ui” }, —> ui: { path: “/” },
-
These edits ensure that the flow editor is available at eg.herokuapp.com/admin
-
Control (Dashboard) is available at appname.herokuapp.com
-
Don’t forget to secure your Node-Red deployment Official Guide
-
We can make our initial deployment to Heroku once the settings.js is updated.
Hinal setup
-
Deploy the app to Heroku using the git deployment method (choose the forked repo)
-
Once the app build is completed, you can access the node-red editor at the /admin path.
-
Gather information and learn to use Node-Red.
-
Next we will install the dashboard and core nodes.
-
Setup the MQTT connections in Node-Red and click deploy in Node-Red.
-
Your Control Center/Dashboard will be accessible at yourappname.herokuapp.com
-
Flash the hardware (in this case esp8266) with MQTTclient program.
-
Test the connection.
-
NOTE that the app is deployed internally in Heroku and will not persist across app failures or reboots. (Read helpful notes for a solution to this problem)
Helpful notes
-
Node-Red can be deployed to IBM Cloud with a few clicks but the app sleeps when using the free plan whereas In Heroku if we add a credit card we can run our app 24x7x365 without spending a single buck If you are not careful with your settings in Heroku your card will be charged
-
Helpful Info about the Heroku free plan
-
Very Imp when using Heroku After every Deploy (In Node-Red NOT IN HEROKU) Make sure that you export the current flow Official Guide. I will update this once I find a better and automatic method.
-
Always secure Node-Red Editor, Dashboard, and other static and node paths Official Guide
-
Setup Guide for Node-Red on Raspberry Pi
-
To make your app persistent across reboots or sleep times, export your node-red flow from the editor and update the flows.json file and the package.json file in the FORKED repo. In Heroku deploy the app again. I am still working on a better and automatic solution to this problem.
-
To prevent the Heroku app from sleeping, send an HTTP request to your app URL using a timestamp node with a 5-15 min interval and an HTTP node.
For any suggestions or queries feel free to send me a message. Now go DIY!