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
What You Need
- Home Assistant instance running
- Node-RED add-on (from HA add-on store — free)
- node-red-contrib-home-assistant-websocket (installed inside Node-RED)
- A light entity in HA to control
Installing the Node-RED Add-on
- Go to Settings → Add-ons → Add-on Store
- Search for Node-RED (by the community add-on store)
- Click Install — wait for it to download (~2 minutes)
- In the Configuration tab, set a
credential_secret:Node-RED add-on configurationcredential_secret: "your-random-secret-here" log_level: info ssl: false certfile: fullchain.pem keyfile: privkey.pem
- Enable Start on boot and Show in sidebar
- Click Start → Open Web UI
Connecting to Home Assistant
First, install the HA companion nodes inside Node-RED:
- In Node-RED: Menu (≡) → Manage palette → Install tab
- Search for
node-red-contrib-home-assistant-websocket - Click Install and wait for it to complete
Now configure the HA server connection:
- Drag any HA node (e.g., "call service") onto the canvas
- Double-click it → click the pencil icon next to Server
- Set Base URL:
http://homeassistant.local:8123 - In HA: Profile page → Long-Lived Access Tokens → Create Token → copy it
- Paste the token in Node-RED's server config → Save
- 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:
[
{
"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):
[
{
"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": []
}
]
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.
[
{
"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
- 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 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.