Quick Answer

Install the Node-RED add-on in HA, add the node-red-contrib-home-assistant-websocket palette, and configure a server connection with your HA Long-Lived Access Token. Then drag an inject node → debug node, hit Deploy, and watch messages flow. Your first real automation (a sunset-triggered light) takes about 20 minutes from scratch.

Table of Contents

  1. Installing the Node-RED Add-on
  2. Connecting to Home Assistant
  3. First Inject → Debug Flow
  4. Turning On a Light via HA REST API
  5. Sunset-Based Flow
  6. Importing and Exporting Flows
  7. Troubleshooting
  8. FAQ

What You Need

Installing the Node-RED Add-on

  1. Go to Settings → Add-ons → Add-on Store
  2. Search for Node-RED (by the community add-on store)
  3. Click Install — wait for it to download (~2 minutes)
  4. In the Configuration tab, set a credential_secret:
    Node-RED add-on configuration
    credential_secret: "your-random-secret-here"
    log_level: info
    ssl: false
    certfile: fullchain.pem
    keyfile: privkey.pem
  5. Enable Start on boot and Show in sidebar
  6. Click Start → Open Web UI

Connecting to Home Assistant

First, install the HA companion nodes inside Node-RED:

  1. In Node-RED: Menu (≡) → Manage palette → Install tab
  2. Search for node-red-contrib-home-assistant-websocket
  3. Click Install and wait for it to complete

Now configure the HA server connection:

  1. Drag any HA node (e.g., "call service") onto the canvas
  2. Double-click it → click the pencil icon next to Server
  3. Set Base URL: http://homeassistant.local:8123
  4. In HA: Profile page → Long-Lived Access Tokens → Create Token → copy it
  5. Paste the token in Node-RED's server config → Save
  6. You should see "Connected" in the server node status

First Flow: Inject → Debug

Import this JSON to create a simple test flow. Click Menu → Import, paste the JSON, and click Import:

Node-RED Flow JSON — Inject to Debug
[
  {
    "id": "n1",
    "type": "inject",
    "name": "Click me!",
    "props": [{"p": "payload"}],
    "repeat": "",
    "once": false,
    "payload": "Hello from Node-RED at {{date}}",
    "payloadType": "str",
    "x": 150,
    "y": 100,
    "wires": [["n2"]]
  },
  {
    "id": "n2",
    "type": "debug",
    "name": "Output",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "x": 350,
    "y": 100,
    "wires": []
  }
]

Click Deploy (top right button). Then click the button on the inject node. You'll see the message appear in the Debug sidebar (🐛 icon, top right). Congratulations — your first Node-RED flow works!

Turning On a Light via HA REST API

This flow calls the HA REST API to turn on a light. Import the JSON below (replace YOUR_TOKEN and light.your_light):

Node-RED Flow JSON — Turn on HA light via REST API
[
  {
    "id": "btn",
    "type": "inject",
    "name": "Turn on light",
    "props": [{"p": "payload"}],
    "payload": "{\"entity_id\": \"light.living_room\"}",
    "payloadType": "json",
    "x": 160,
    "y": 200,
    "wires": [["http_req"]]
  },
  {
    "id": "http_req",
    "type": "http request",
    "name": "HA API",
    "method": "POST",
    "ret": "txt",
    "url": "http://homeassistant.local:8123/api/services/light/turn_on",
    "headers": {
      "Authorization": "Bearer YOUR_TOKEN",
      "Content-Type": "application/json"
    },
    "x": 380,
    "y": 200,
    "wires": [["result"]]
  },
  {
    "id": "result",
    "type": "debug",
    "name": "Result",
    "active": true,
    "x": 580,
    "y": 200,
    "wires": []
  }
]
Better approach: Instead of the HTTP request node, use the call service node from node-red-contrib-home-assistant-websocket. It handles authentication automatically via your server config and is much cleaner.

Sunset-Based Light Flow

This flow turns on a light every day at sunset. It uses the ha-time node which knows your HA location's sunrise/sunset times.

Node-RED Flow JSON — Sunset trigger with call service
[
  {
    "id": "sun_trigger",
    "type": "ha-time",
    "name": "At sunset",
    "server": "YOUR_SERVER_ID",
    "entityId": "sun.sun",
    "property": "next_setting",
    "offset": 0,
    "x": 160,
    "y": 300,
    "wires": [["light_on"]]
  },
  {
    "id": "light_on",
    "type": "api-call-service",
    "name": "Turn on porch",
    "server": "YOUR_SERVER_ID",
    "domain": "light",
    "service": "turn_on",
    "data": "{\"entity_id\": \"light.porch\", \"brightness_pct\": 80, \"color_temp\": 2700}",
    "x": 400,
    "y": 300,
    "wires": []
  }
]

Replace YOUR_SERVER_ID with the ID shown in your server config node (visible when you open any HA node and look at the server dropdown). The flow automatically adjusts sunset time daily based on your HA home location.

Importing and Exporting Flows

To export: Select nodes on the canvas (Ctrl+A for all) → Menu → Export → Clipboard. Copy the JSON to save or share.

To import: Menu → Import → Clipboard → paste JSON → Import.

Your flows are stored at /config/node-red/flows.json inside HA. They're automatically included in HA's backup system. Back up your HA regularly and your Node-RED flows come with it.

Troubleshooting

FAQ

Can I run Node-RED without the HA add-on?

Yes — Node-RED is a standalone app that runs on any Node.js system. Install it on a Raspberry Pi, Linux server, or anywhere. The HA add-on is just the most convenient way to run it alongside HA.

How do I trigger a flow when an HA entity changes state?

Use the events: state node from node-red-contrib-home-assistant-websocket. Configure the entity_id and optionally filter by "from state" and "to state". This triggers your flow whenever the entity state changes.

Is Node-RED better than HA automations?

Not better — different. HA automations are great for straightforward trigger→action rules. Node-RED is better when you need complex branching, data manipulation, external API calls, or visual debugging. Use both.

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.