Skip to content

Node-RED for Home Assistant

Node-RED Automations Advanced

Node-RED Automation

Node-RED is a visual programming tool that makes complex automations manageable. Drag nodes, connect them with wires, and build automations that would be impossible (or very tedious) in Home Assistant’s standard automation editor.


FeatureHA AutomationsNode-RED
Learning curveLowMedium-high
Visual editorSimpleAdvanced
DebuggingLimitedExcellent
Loops
VariablesLimitedFlow/Global
JavaScript
Reuse (subflows)
Time-based logicBasicAdvanced

Use Node-RED when you need:

  • Complex logic with many conditions
  • Loops and repeated actions
  • Custom JavaScript code
  • Better debugging and troubleshooting
  • Reusable automation blocks

Stick with HA automations when:

  • The automation is simple (trigger → action)
  • You prefer YAML/UI
  • You want to keep everything in one system

  1. Go to Settings → Add-ons

  2. Click Add-on Store (bottom right)

  3. Search for “Node-RED”

  4. Select Node-RED and click Install

  5. Configure the add-on:

    # Important settings:
    ssl: false # Set to true if you have SSL
    credential_secret: "your-secret-key"
  6. Start the add-on and enable:

    • ✅ Start on boot
    • ✅ Watchdog
    • ✅ Show in sidebar
  7. Open Node-RED via the sidebar

# docker-compose.yml
version: '3'
services:
nodered:
image: nodered/node-red:latest
container_name: nodered
restart: unless-stopped
ports:
- "1880:1880"
volumes:
- ./nodered-data:/data
environment:
- TZ=Europe/Copenhagen

  1. In Home Assistant, click your profile picture (bottom left)

  2. Scroll down to Long-Lived Access Tokens

  3. Click Create Token

  4. Name it “Node-RED”

  5. Copy the token - you can only see it once!

  1. Drag an events: state node onto the workspace

  2. Double-click and click the pencil icon next to Server

  3. Fill in:

    Name: Home Assistant
    Base URL: http://homeassistant.local:8123
    Access Token: [your token from previous step]
  4. Click Add then Done

For extra features like enabling/disabling flows from HA:

  1. Install via HACS:

    • Search “Node-RED Companion”
    • Install and restart HA
  2. Add integration:

    • Settings → Devices & Services → Add Integration
    • Search “Node-RED”

┌─────────────────────────────────────────────────────────────┐
│ FLOW (Tab) │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ SEQUENCE (Connected nodes) │ │
│ │ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ │ │
│ │ │ NODE │───►│ NODE │───►│ NODE │───►│ NODE │ │ │
│ │ └──────┘ └──────┘ └──────┘ └──────┘ │ │
│ │ msg.payload is passed between nodes │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ ANOTHER SEQUENCE │ │
│ │ ┌──────┐ ┌──────┐ │ │
│ │ │ NODE │───►│ NODE │ │ │
│ │ └──────┘ └──────┘ │ │
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
TermDescription
NodeA single building block (trigger, action, logic)
SequenceConnected nodes forming one automation
FlowAll sequences on one tab
msgMessage passed between nodes
msg.payloadDefault data field in the message
ScopeAvailable ToUse Case
msgOnly current sequenceData between nodes
flowAll nodes on same tabShared data on flow
globalAll nodes everywhereShared data across all
// Set variables
flow.set("myVar", "value");
global.set("globalVar", 123);
// Read variables
let x = flow.get("myVar");
let y = global.get("globalVar");

NodeFunctionUse
events: stateTrigger on state changeStart automations
current stateRead current stateConditions
call serviceCall HA serviceActions
wait untilWait for stateDelays with conditions
trigger: stateTrigger with multiple conditionsAdvanced triggers
apiGeneral API accessEverything else

Node-RED flow example

Triggers when an entity changes state:

# Configuration:
Entity: light.living_room
If State: "on" # Optional: Only trigger on this state
For: 00:00:05 # Optional: Only if state holds for 5 sec

Output:

msg.payload = "on"; // New state
msg.data.old_state.state // Old state
msg.data.entity_id // Entity ID

Read state in the middle of a flow (doesn’t trigger itself):

# Configuration:
Entity: binary_sensor.motion_kitchen
If State: "on"
# If state matches → Output 1
# If not → Output 2 (or stop)

Execute actions in Home Assistant:

# Example: Turn on light
Domain: light
Service: turn_on
Entity: light.living_room
Data: {"brightness": 255, "color_temp": 350}

[events: state]──►[call service]
motion_sensor light.turn_on
[events: state]──►[delay]──►[call service]
motion_sensor 2 min light.turn_off
(off)

Flow JSON:

[
{
"id": "motion_on",
"type": "server-state-changed",
"entity_id": "binary_sensor.motion_living_room",
"ifstate": "on",
"wires": [["light_on"]]
},
{
"id": "light_on",
"type": "api-call-service",
"domain": "light",
"service": "turn_on",
"entity_id": "light.living_room"
}
]

Example 2: Conditional Automation (Night Only)

Section titled “Example 2: Conditional Automation (Night Only)”
[events: state]──►[current state]──►[call service]
motion sun.sun light.turn_on
(below_horizon)

The sun entity is used to check if it’s night before turning on the light.

Light that turns off after 5 minutes without motion, but resets if there’s new motion:

[events: state]──►[stoptimer]──►[call service]
motion (on) reset (nothing)
└──────────►[stoptimer]──►[call service]
start 5min light.turn_off

Turn lights on/off based on which rooms have motion:

// Function node to track active rooms
let activeRooms = global.get("activeRooms") || [];
let room = msg.data.entity_id.replace("binary_sensor.motion_", "");
if (msg.payload === "on") {
if (!activeRooms.includes(room)) {
activeRooms.push(room);
}
} else {
activeRooms = activeRooms.filter(r => r !== room);
}
global.set("activeRooms", activeRooms);
msg.activeRooms = activeRooms;
return msg;

Create your own nodes from a group of nodes:

  1. Select the nodes you want to reuse

  2. Menu → Subflows → Selection to Subflow

  3. Name your subflow

  4. The new subflow appears in the palette under “subflows”

  5. Drag it in wherever you need it

Connect sequences across flows without drawing long wires:

Flow 1: Flow 2:
[trigger]──►[link out: "alarm"] [link in: "alarm"]──►[action]

Test your flows without waiting for real triggers:

[inject]──►[rest of your flow]
(manual trigger via click)

Configure inject node with test data:

msg.payload = "on";
msg.data = {
entity_id: "binary_sensor.test",
old_state: { state: "off" }
};

See what’s happening in your flow:

[trigger]──►[debug]──►[action]
└──► Shows msg in Debug panel

Tip: Set debug to “complete msg object” to see everything.


Install via Menu → Manage palette → Install:

PaletteDescription
node-red-contrib-bigtimerAdvanced time-based scheduling
node-red-contrib-stoptimerStart/stop/reset timers
node-red-contrib-weekdayFilter on weekdays
node-red-contrib-time-range-switchRouting based on time
node-red-contrib-schedexSunset/sunrise scheduling
node-red-dashboardBuild dashboards in Node-RED

# Check:
1. All nodes have valid connections
2. No red triangles on nodes (configuration errors)
3. Server connection is configured
4. Access token is valid
  1. Add debug node after trigger

  2. Check that entity_id is correct

  3. Verify that “If State” matches

  4. Check Debug panel for output

# Check access token:
1. Create new token in HA
2. Update server config in Node-RED
3. Deploy all flows
4. Restart Node-RED add-on

PracticeDescription
One tab per areaLiving room, kitchen, bedroom, etc.
CommentsUse comment nodes for explanation
NamingGive all nodes descriptive names
SubflowsReuse logic instead of copy/paste
# Avoid:
- events: all node (uses many resources)
- Polling in loops (use triggers instead)
- Large debug outputs in production
# Use:
- "Modified Flows" deploy type
- Specific entity triggers
- Disable debug nodes when not in use

Node-RED flows are stored in:

# Add-on:
/config/node-red/flows.json
# Docker:
./nodered-data/flows.json

Include this file in your Home Assistant backup!


Ofte stillede spørgsmål

Should I move all my automations to Node-RED?
No! Use Node-RED for complex automations and keep simple automations in HA. There's no reason to make things more complicated than necessary.
Can Node-RED run without Home Assistant?
Yes, Node-RED is a standalone tool. You can use it for other IoT projects, API integrations, and much more. The HA nodes are just an extra module.
What happens to my automations if Node-RED goes down?
Automations in Node-RED stop. That's why it's important to keep critical automations (alarm, security) in Home Assistant itself, or have watchdog enabled on Node-RED.
Can I see Node-RED automations in HA's automations list?
Not directly. With the Node-RED Companion integration, however, you can see and enable/disable flows from HA's UI.

First Automation

Start with HA’s built-in automations.

See guide →


Last updated: December 2025


Kommentarer