Updated in 2020

As buster is available, I updated this article to support Debian buster instead of stretch.

node red

Node-Red is a nice little tool to build some flows to do stuff. I used it on a raspberry pi to monitor the rack temperature. As it is available on Raspberry pi and has support for the hardware as well, it was a nice solution. Today I like to install it on a Debian Linux LxC container on my Proxmox VE Host . I like to separate the display and alerting from the sensors as I tend to use more than one raspberry to monitor different stuff and not just some temperature sensors of my server room. So here is a short summary on how to install it.

Create the container

How you create a container in a Proxmox VE environment is well documented on the Proxmox website . I created a Debian 9.7 container with a fixed IP and about 1GiB memory and 8GiB Disk space. In fact it uses around 200MiB memory to run the service. This host is only available within my internal server zone and not publicly accessible. If you like, you may run the whole thing on a virtual machine as well. I just prefer LxC as it uses much less resources.

Install the dependencies

To make everything work properly, we have to install some stuff. Currently you should not take the latest nodejs as it is not really working well with that. So I use the official supported LTS version 10 of nodejs to run node-red. There is a setup script that helps setting up nodejs on your system. You have to trust it or do the steps by hand if you like. I recommend reviewing the script before executing it!

curl -sL https://deb.nodesource.com/setup_12.x | bash -
apt-get install -y nodejs

Next we need to install some more tools to make npm modules work or build during installation.

apt-get install -y gcc g++ make

curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg |  apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" |  tee /etc/apt/sources.list.d/yarn.list

apt-get update && apt-get install yarn

Now the container is ready for node red itself.

Install node-red

Now it is time to create a node red user and install the application.

adduser nodered
npm install -g --unsafe-perm node-red

Next we have to make sure the service starts using the user nodered during bootup. To make this possible, just take the following service definition and save it to the file /etc/systemd/system/node-red.service.

# systemd service file to start Node-RED
# modified version of the pi definition
# https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/nodered.service

[Unit]
Description=node-red graphical event wiring tool
Wants=network.target
Documentation=http://nodered.org

[Service]
Type=simple
User=nodered
Group=nodered
WorkingDirectory=/home/nodered

Nice=5
#Environment="NODE_OPTIONS=--max_old_space_size=256"
# uncomment the next line for a more verbose log output
#Environment="NODE_RED_OPTIONS=-v"
ExecStart=/usr/bin/env node-red $NODE_OPTIONS $NODE_RED_OPTIONS

KillSignal=SIGINT
Restart=on-failure
SyslogIdentifier=node-red

[Install]
WantedBy=multi-user.target

To make the service start and use this new file, we have to tell systemd about it. This is done using the following commands.

systemctl daemon-reload
systemctl enable node-red.service
systemctl start node-red.service
systemctl status node-red.service

Use it

Finally you connect to your new system using http://w.x.y.z:1880/ to get to the flow page. You can install some nodes from the web gui like the mattermost and dashboard extensions. I also use mqtt to transport the messages from the raspberries to the central node red server.

Now you are ready to build your self hosted flows. As there is mqtt supported, it gets quite easy to collect any type of data or trigger some actions on devices depending on sensor measurements.

Here is a little screen shot of my alerting flow.

  • Get the temperatures for the three sensors from mqtt
  • Write the temperatures to the dashboard control
  • Build the temperature payload alert message and send it only once for each change
  • Fan out the message to mail, mattermost, mqtt and dashboard toast notification

Node red temperature monitoring