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

  1. What Node-RED Is
  2. Node-RED vs HA Automations
  3. Installing Node-RED
  4. First Inject → Debug Flow
  5. Turning On a Light via HA API
  6. Sunset-Based Trigger
  7. Importing and Exporting Flows
  8. Troubleshooting
  9. FAQ

What You Need

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:

Many HA power users run both: simple automations in HA's editor, complex flows in Node-RED.

Installing Node-RED

  1. Go to Settings → Add-ons → Add-on Store in Home Assistant
  2. Search for Node-RED and click Install
  3. Enable Start on boot
  4. In the add-on's Configuration tab, set a credential_secret (any random string)
  5. Click Start, then Open Web UI
  6. Inside Node-RED, go to Menu (≡) → Manage palette → Install
  7. 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:

Node-RED Flow JSON — Inject to Debug
[
  {
    "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:

Node-RED Flow JSON — Turn on HA light
[
  {
    "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": []
  }
]
Better approach: Use the 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:

Node-RED Flow JSON — Sunset light trigger
[
  {
    "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

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.