Node-RED is a visual, browser-based flow programming tool that makes home IoT programming accessible without deep coding knowledge. Running on a Raspberry Pi or any Linux system, Node-RED connects ESP8266/ESP32 devices, MQTT brokers, databases, APIs, and home automation services with a simple drag-and-drop interface. This tutorial helps Indian makers set up and use Node-RED for their smart home IoT projects.
Table of Contents
- What is Node-RED?
- Installing Node-RED in India
- Your First Flow
- MQTT and ESP8266/ESP32 Integration
- Building IoT Dashboards
- India-Specific Automation Flows
- Node-RED with Home Assistant
- Frequently Asked Questions
What is Node-RED?
Node-RED is an open-source flow-based programming tool developed by IBM. It provides a visual editor where you connect “nodes” with wires to create automation flows. Each node represents a function (receive MQTT message, send email, process JSON, control a device). Connecting nodes creates a flow that executes when triggered.
Why Node-RED is popular with Indian IoT developers:
- Visual programming: No deep coding required — drag, drop, and connect
- Free and open-source: Runs on Raspberry Pi, VPS, or any Linux box
- Huge node library: Pre-built nodes for MQTT, HTTP, email, Telegram, WhatsApp, Modbus, databases
- Real-time dashboard: Node-RED Dashboard provides instant charts, gauges, and control panels
- Integrates with Home Assistant, Alexa, Google Home
Installing Node-RED in India
# Install on Raspberry Pi (recommended for Indian homes - low power 24/7 server)
# First install Node.js:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
# Install Node-RED globally:
sudo npm install -g --unsafe-perm node-red
# Start Node-RED:
node-red
# For autostart on boot:
sudo systemctl enable nodered.service
# Install script for Raspberry Pi (easiest):
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
# Access Node-RED UI at:
# http://raspberry-pi-ip:1880
# Install useful nodes:
cd ~/.node-red
npm install node-red-dashboard # UI dashboard
npm install node-red-contrib-mqtt-sparkplug # Advanced MQTT
npm install node-red-contrib-telegrambot # Telegram notifications
npm install node-red-node-mysql # MySQL database
Your First Flow
Let’s create a simple flow: inject a timestamp every 5 seconds and log it:
- Open Node-RED at http://your-pi:1880
- Drag an inject node onto the canvas (from the left panel)
- Double-click the inject node → set Repeat: every 5 seconds
- Drag a debug node onto the canvas
- Connect the inject output to the debug input
- Click Deploy (top right)
- Open the debug panel (bug icon) — see timestamps every 5 seconds
Now let’s add a function node to format the timestamp for India (IST):
// Function node: Format timestamp for India
// Paste this in the Function node:
var d = new Date();
var istTime = new Date(d.getTime() + (5.5 * 60 * 60 * 1000));
var hours = istTime.getUTCHours();
var minutes = istTime.getUTCMinutes();
var seconds = istTime.getUTCSeconds();
msg.payload = "India Time: " +
String(hours).padStart(2,'0') + ":" +
String(minutes).padStart(2,'0') + ":" +
String(seconds).padStart(2,'0');
return msg;
MQTT and ESP8266/ESP32 Integration
// ESP8266/ESP32 MQTT code (publishes sensor data):
#include <PubSubClient.h>
// Publishes to topic: home/sensors/bedroom/temperature
// Node-RED subscribes to this topic and processes data
// Node-RED flow (JSON import):
[
{
"id": "mqtt-in-1",
"type": "mqtt in",
"topic": "home/sensors/+/temperature", // + wildcard
"broker": "mqtt-broker-1",
"name": "Temperature Sensor Input"
},
{
"id": "json-parse",
"type": "json",
"name": "Parse JSON"
},
{
"id": "temp-check",
"type": "function",
"name": "Check Temperature",
"func": "if (msg.payload.temp > 35) {
msg.alert = 'High temperature alert: ' + msg.payload.temp + '°C';
}
return msg;"
}
]
Building IoT Dashboards
// Node-RED Dashboard flow for temperature/humidity display
// Install: npm install node-red-dashboard
// Flow design:
// MQTT In (home/sensors/+/data)
// → JSON Parse
// → Function (extract temp)
// → Gauge node (Temperature gauge, 0-50°C)
// → Chart node (Historical temperature chart)
// Gauge node configuration:
// - Group: Living Room
// - Label: Temperature
// - Range: 0 to 50
// - Colour stops: green (0-25), yellow (25-35), red (35-50)
// Dashboard available at: http://your-pi:1880/ui
// Example Function node for parsing ESP32 JSON payload:
// Input msg.payload: {"temp":28.5,"hum":65,"room":"bedroom"}
var data = msg.payload;
msg.topic = data.room;
// Create separate messages for each sensor:
node.send([
{payload: data.temp, topic: "temperature"},
{payload: data.hum, topic: "humidity"}
]);
India-Specific Automation Flows
Electricity Tariff-Aware AC Control
// Turn off AC during peak tariff hours (7PM-11PM on weekdays) to save on Indian electricity bills
// Triggered: every minute by inject node
// Function node:
var now = new Date();
var istHour = (now.getUTCHours() + 5) % 24;
var istMinute = (now.getUTCMinutes() + 30) % 60;
// IST hour approximation
var isPeakHour = (istHour >= 19 && istHour 0 && now.getDay() < 6;
if (isPeakHour && isWeekday) {
// Raise AC temperature to 26°C to reduce consumption
msg.payload = '{"temperature": 26}';
msg.topic = "cmnd/bedroom_ac/climate";
return msg;
}
Power Cut Recovery
// Subscribe to MQTT topic that ESP32 publishes on startup
// This fires when any ESP device reboots (power cut recovery)
// MQTT topic: home/device/+/startup
[MQTT In] → [Function: Restore device state from context] → [MQTT Out]
// Function node:
var deviceId = msg.topic.split('/')[2];
var savedState = context.global.get(deviceId) || 'off';
msg.payload = savedState;
msg.topic = 'cmnd/' + deviceId + '/POWER';
return msg;
Node-RED with Home Assistant
# Install node-red-contrib-home-assistant-websocket node:
cd ~/.node-red
npm install node-red-contrib-home-assistant-websocket
# Configure HA server in Node-RED:
# - Server: http://homeassistant.local:8123
# - Access Token: (long-lived access token from HA profile)
# Example flow: Call HA service from Node-RED
// Inject → Function → Call Service node
// Call Service node config:
// Domain: light
// Service: turn_on
// Entity ID: light.living_room
// Function node to build service data:
msg.payload = {
entity_id: "light.living_room",
brightness_pct: 75
};
return msg;
# Trigger HA automation from Node-RED:
// POST to HA webhook: http://homeassistant.local:8123/api/webhook/my_webhook_id
Frequently Asked Questions
Is Node-RED better than Home Assistant for Indian smart homes?
They serve different purposes. Home Assistant is a complete smart home platform with device management, mobile app, and hundreds of integrations. Node-RED is a flow programming tool for custom automation logic. Many Indian makers use both — Home Assistant for device management and Node-RED for complex automation flows that HA’s built-in automation editor can’t handle easily.
Can Node-RED run on a cheap VPS server in India?
Yes — Node-RED is lightweight and runs on even a ₹400/month VPS from Indian providers like DigitalOcean Bangalore, AWS Mumbai, or GCP Mumbai region. This gives you cloud-based automation accessible from anywhere, though it introduces cloud dependency unlike a local Raspberry Pi setup.
How do I back up my Node-RED flows in India?
Node-RED stores flows in ~/.node-red/flows.json. Back up this file regularly. For version control, commit it to a private Git repository. Node-RED also has a built-in export function (hamburger menu → Export) to download flows as JSON that can be imported on another instance.
What is the difference between Node-RED and MQTT?
MQTT is a messaging protocol — devices publish and subscribe to topics. Node-RED is a processing platform — it subscribes to MQTT topics, processes the messages (using JavaScript function nodes), and publishes results or triggers actions. Node-RED uses MQTT as one of many input/output channels.
Can Node-RED send WhatsApp messages for Indian home automation alerts?
Node-RED can send WhatsApp messages via the WhatsApp Business API (paid) or unofficial API wrappers. More practically, Telegram notifications are free and commonly used by Indian Node-RED users — the node-red-contrib-telegrambot node is well-maintained and popular.
Add comment