Node RED setup - ahpohl/smartmeter GitHub Wiki
Overview
From the Node-RED website: "Node-RED is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways. It provides a browser-based editor that makes it easy to wire together flows using the wide range of nodes in the palette that can be deployed to its runtime in a single-click."
I have chosen Node-RED for this project because it makes it very easy to glue together the different components that make up the complete Smartmeter. The Node-Red MQTT client subscribes to the smartmeter/state
topic and forwards the Smartmeter json string to the PostgreSQL client node. The flow optionally subscribes to the smartmeter/status
topic and sends an email alert when the online/offline status changes.
Installation
Arch Linux package:
$ yaourt -S nodejs-node-red
Enable the systemd unit file.
$ systemctl enable nodejs-node-red
$ systemctl start nodejs-node-red
We need some extra nodes, i.e. the PostgreSQL client and email client. Although it is easy to install the nodes with the palette manager in the web gui, it is also possible to install them directly with npm:
$ npm install @digitaloak/node-red-contrib-digitaloak-postgresql
$ npm install node-red-node-email
Restart Node-RED. The web interface is now available at http://YOUR-IP-ADDRESS:1880/.
Configuration
Import the Smartmeter flow directly from the command line:
$ cd /usr/share/smartmeter/nodejs
$ curl -X POST http://YOUR-IP-ADDRESS:1880/flows -H 'content-type: application/json' -d @node-red-flow
Alternatively import the Smartmeter flow using the gui. Depending if your Node-RED is on a remote host you might need to copy/paste the flow from the command line:
$ cat /usr/share/smartmeter/nodejs/node-red-flow.json
Now paste the complete json string into the import dialog and click Import
and hit Deploy
. If you are on the same host you can upload the json file directly.
Next click on the smartmeter/state
MQTT node and enter the password "mqtt" for user "mqtt":
Last but not least click on the postgresql
node and enter the credentials "nodejs" with password "nodejs" into the dialog fields as shown: