Quick Answer
Node-RED is a visual programming tool that lets you build automation flows by connecting nodes on a canvas. It runs as a Home Assistant add-on and is ideal for complex logic that's awkward in HA's built-in automation editor. Install the add-on, connect to HA via the companion nodes, and drag-and-drop your first flow in minutes.
Table of Contents
What You Need
- A running Home Assistant instance
- Node-RED add-on (free, from HA add-on store)
- node-red-contrib-home-assistant-websocket nodes (installed inside Node-RED)
What Node-RED Is
Node-RED is a flow-based visual programming tool built on Node.js. You drag nodes onto a canvas, wire them together, and deploy the flow. Each node does one thing: inject a timestamp, filter a value, call an HTTP API, send an MQTT message, control an HA entity.
It was originally created by IBM and is now an open-source project under the OpenJS Foundation. It runs on any Node.js system, and for Home Assistant users, there's a first-class add-on that installs in two clicks.
Node-RED vs Home Assistant Automations
HA's built-in automation editor is great for straightforward trigger-condition-action flows. Node-RED excels when you need:
- Complex branching logic — multiple paths based on different conditions
- Data transformation — parsing JSON, doing math, reformatting payloads
- Rate limiting and debouncing — ignore repeated triggers within a time window
- External API calls — weather, stocks, calendar data
- Stateful flows — remember the last value and only trigger on changes
- Visual debugging — see exactly what's flowing through each node in real time
Many HA power users run both: simple automations in HA's editor, complex flows in Node-RED.
Installing Node-RED
- Go to Settings → Add-ons → Add-on Store in Home Assistant
- Search for Node-RED and click Install
- Enable Start on boot
- In the add-on's Configuration tab, set a
credential_secret(any random string) - Click Start, then Open Web UI
- Inside Node-RED, go to Menu (≡) → Manage palette → Install
- Search for and install:
node-red-contrib-home-assistant-websocket
Now configure the HA server connection: drag a "server config" node onto the canvas (or it prompts you when you add any HA node). Set the Base URL to http://homeassistant.local:8123 and add a Long-Lived Access Token from your HA profile page.
First Flow: Inject → Debug
Your first flow should be the simplest possible one to verify Node-RED is working. Import this JSON via Menu → Import:
[
{
"id": "inject1",
"type": "inject",
"name": "Trigger every 10s",
"props": [{"p": "payload"}],
"repeat": "10",
"payload": "Hello from Node-RED",
"payloadType": "str",
"wires": [["debug1"]]
},
{
"id": "debug1",
"type": "debug",
"name": "Show in sidebar",
"active": true,
"tosidebar": true,
"wires": []
}
]
Click Deploy. In the Debug sidebar (🐛 icon), you'll see "Hello from Node-RED" appear every 10 seconds. You can also click the inject node's button to trigger it manually.
Turning On a Light via the HA API
This flow uses an HTTP request to call the HA REST API. Replace YOUR_TOKEN with your Long-Lived Access Token and light.living_room with your light's entity ID:
[
{
"id": "btn1",
"type": "inject",
"name": "Turn on light",
"props": [{"p": "payload"}],
"once": false,
"payload": "{\"entity_id\": \"light.living_room\"}",
"payloadType": "json",
"wires": [["http1"]]
},
{
"id": "http1",
"type": "http request",
"name": "HA API - light on",
"method": "POST",
"ret": "txt",
"url": "http://homeassistant.local:8123/api/services/light/turn_on",
"headers": {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json"
},
"wires": [["debug2"]]
},
{
"id": "debug2",
"type": "debug",
"name": "Response",
"active": true,
"wires": []
}
]
call service node from node-red-contrib-home-assistant-websocket instead of raw HTTP requests. It handles authentication automatically via the server config.
Sunset-Based Trigger
The node-red-contrib-home-assistant-websocket package includes a Sun Events node that fires at sunrise and sunset based on your HA location:
[
{
"id": "sun1",
"type": "ha-time",
"name": "At sunset",
"server": "your_server_id",
"entityId": "sun.sun",
"property": "next_setting",
"offset": 0,
"wires": [["svc1"]]
},
{
"id": "svc1",
"type": "api-call-service",
"name": "Turn on porch light",
"server": "your_server_id",
"domain": "light",
"service": "turn_on",
"data": "{\"entity_id\": \"light.porch\", \"brightness_pct\": 80}",
"wires": []
}
]
This triggers exactly at sunset each day, automatically adjusting for your location and time of year. No hardcoded times needed.
Importing and Exporting Flows
To export a flow: select the nodes you want, then Menu → Export → Clipboard. Copy the JSON.
To import: Menu → Import → Clipboard, paste the JSON, and click Import.
Flows are stored in /config/node-red/flows.json inside HA. Back this up with your HA config backups — it's included automatically if you use HA's built-in backup system.
Troubleshooting
- Entities don’t appear in Home Assistant: Confirm the integration is loaded correctly and double-check that the device is supported by the platform you chose.
- Commands feel delayed: This is usually caused by cloud polling, weak Wi-Fi, or a slow Zigbee mesh rather than Home Assistant itself.
- Things work in the vendor app but not in HA: Re-check credentials, local API permissions, and whether the device is using the correct network path.
- Automations misfire: Open the automation trace in Home Assistant and verify the exact entity IDs and state changes being used.
FAQ
Can Node-RED replace HA automations entirely?
Technically yes, but it's not recommended. HA automations are better integrated with the UI, easier for non-technical users, and supported by blueprints. Use Node-RED for complex flows and HA automations for simple trigger-action rules.
Does Node-RED run locally?
Yes — the Node-RED add-on runs inside your HA instance. All flows execute on your local hardware with no cloud dependency.
How do I debug a flow that's not working?
Add a Debug node after every node in your flow temporarily. You'll see exactly what's passing through each step. The Debug sidebar also shows errors with timestamps.
Can Node-RED read sensor states from HA?
Yes — use the "current state" node from node-red-contrib-home-assistant-websocket to read any entity's state on demand, or the "events: state" node to trigger when a state changes.
SmartWired uses affiliate links. If you buy through our links, we may earn a commission at no extra cost to you. See our Affiliate Disclosure.