automate your home using node-red and heroku
published on 19 Nov 2020
written by pranav chakkarwar
4 min to read
this is an outdated solution, take a look at my practical approach to home automation.
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.
final 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!