Raspberry Pi: run Node-RED for visual automations
Install Node-RED on a Raspberry Pi and build a visual automation flow. The tool that ties together MQTT, sensors, dashboards, and notifications.
Node-RED is the visual automation tool I default to for home automation projects. You drag nodes onto a canvas, wire them together, and you have an automation. No code editor, no YAML, no fighting with config files.
This tutorial installs Node-RED on a Raspberry Pi and builds a small example: a temperature sensor publishes via MQTT, Node-RED reads it, and Node-RED sends you a Telegram message when the temperature goes above 27 C.
What you need
- Raspberry Pi running Raspberry Pi OS
- Mosquitto MQTT broker already running (covered in the previous tutorial)
Install Node-RED
The recommended way on Raspberry Pi OS Bookworm:
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
This script installs Node.js (if not present), Node-RED, and sets up the systemd service. It takes about 5-10 minutes.
Once installed, enable and start the service:
sudo systemctl enable nodered.service
sudo systemctl start nodered.service
Node-RED listens on port 1880 by default.
Access the editor
Open a browser on any computer on the same network:
http://pi-pihole.local:1880
You should see the Node-RED editor. It is a canvas with a palette of nodes on the left.
The flow: temperature alert via Telegram
Drag these nodes onto the canvas:
- mqtt in (under “input”)
- function (under “function”)
- telegram sender (under “telegram”, you may need to install it first)
If telegram sender is not in the palette, install it:
- Menu (top right) >>
Manage palette>>Install - Search
node-red-contrib-telegram - Install
Configure the MQTT node
Double-click the mqtt in node:
- Server:
localhost:1883 - Topic:
ctrlaltbrian/sensor/temperature - QoS: 0
- Name:
Sensor in
Click Done.
Configure the function node
Double-click the function node. Paste this in the Function editor:
const temp = parseFloat(msg.payload);
if (temp > 27) {
msg.payload = `Temperature is ${temp.toFixed(1)} C, turning on the AC.`;
return msg;
}
return null;
This filters for hot temperatures only. return null discards messages
that do not match.
Click Done.
Configure the Telegram node
You need a Telegram bot first. Talk to @BotFather on Telegram:
- Send
/newbot - Choose a name (e.g. “Pi Alerts”)
- Choose a username (e.g.
pi_alerts_bot) - BotFather gives you a token. Save it.
Get your chat ID. Send a message to your bot, then visit:
https://api.telegram.org/bot<TOKEN>/getUpdates
Look for the chat.id field. That’s your chat ID.
Double-click the telegram sender node:
- Bot: configure a new bot with the token from above
- Chat ID: your chat ID
- Name:
Send alert
Click Done.
Wire it up
Drag from the right edge of mqtt in to the left edge of function. Then from function to telegram sender.
Click Deploy (top right).
Test it
Publish a hot temperature to MQTT:
mosquitto_pub -h localhost -u brian -P your-password -t "ctrlaltbrian/sensor/temperature" -m "29.4"
You should see a Telegram message arrive.
Building a dashboard
Node-RED has a built-in dashboard via node-red-dashboard:
- Menu >> Manage palette >> Install >>
node-red-dashboard - Drag a gauge node from the dashboard palette onto the canvas
- Configure it to read from the same MQTT topic
- Wire the mqtt in to the gauge
- Deploy
Visit http://pi-pihole.local:1880/ui to see the dashboard.
You now have a real-time temperature gauge.
Common Node-RED nodes I use
- mqtt in/out: read and write to MQTT topics
- function: small JavaScript snippet for filtering or transforming
- change: rename, set, delete, move fields in a message
- switch: route messages to different paths based on conditions
- debug: print the message to the debug sidebar
- inject: send a test message on a button click or schedule
- http in/out: HTTP endpoints (e.g. to receive a webhook)
- exec: run a shell command
- telegram sender: send a Telegram message
- email: send an email
With these, you can build:
- “If motion sensor trips between 11pm and 6am, send me a Telegram message.”
- “If the temperature is below 5 C, send me a warning that the pipes might freeze.”
- “If the front door opens, log the time and turn on the entryway light.”
All without writing any Python, Bash, or other glue code.
When Node-RED does not load
- Port 1880 already in use. Another service is using that port. Edit
/lib/systemd/system/nodered.serviceand change the port, then restart. - Memory limit. Node-RED uses a lot of RAM for the editor. On a Pi Zero, the editor will be slow. The Pi 4 with 4 GB is comfortable.
- Permission errors. Node-RED must be run as the
piuser, not root. The install script sets this up; if you changed it, revert.
When to use Node-RED vs. Home Assistant vs. custom Python
- Node-RED: visual, fast to prototype, great for “if X then Y” logic. Not a full home automation system.
- Home Assistant: full home automation system with device integrations, automations, energy monitoring. Heavier, more features, more config.
- Custom Python: maximum flexibility, harder to maintain, great for custom data pipelines.
I run Home Assistant for the main home automation, Node-RED for the visual automations that connect to it, and Python scripts for the data pipeline (e.g. logging to a database). All three on the same Pi.
What to build next
- A multi-sensor dashboard with gauges for temperature, humidity, and pressure.
- A presence detection system (when my phone joins the Wi-Fi, mark me as home).
- A weather-based automation (close the blinds if it’s sunny and the indoor temp is above 24).
The dashboard tutorial is in the book Home Automation with Raspberry Pi. The presence detection version is one of the next tutorials on this site.