vd Brink Home Automations

Home automations with Home Assistant, ESPHome, Node-RED and more tech

Node-RED Cheat Sheet - Basic Nodes

Node-RED examples of basic actions to convert data from one to another format can be found here.

More advanced examples with the function node can be found in the Node-RED function node cheat sheet


Table of Contents


Extract value from JSON

Pass a single entity value, in this case the temperature, from a JSON message.

| | | | |:-----------------------------------------------------------------------------|-------------------------------------------------------------------|-------:| | {
"battery" : 100,
"temperature" : 24.53,
"linkquality" : 60
} | Node-RED change node | 24.53 |
Set [msg].payload
    [msg].payload.temperature

Round a comma value to an integer value

Round a comma value, like temperature, to a rounded integer value.

| | | | |:-----|-------------------------------------------------------------------|----:| | 25,3 | Node-RED change node | 25 | | 25,6 | Node-RED change node | 26 |
Set [msg].payload
    $round(payload, 0)

String to Integer

Convert a string value to an integer.

| | | | |:--------|-------------------------------------------------------------------|------:| | "24.01" | Node-RED change node | 24.01 |
Set [msg].payload
    $number(payload)

Strip topic name

Get only the last part after the ‘/’ from a topic.

| | | | |:-----------------------|-------------------------------------------------------------------|-----------:| | "zigbee2mqtt/contact1" | Node-RED change node | "contact1" |
Set [msg.]measurement
    [expression]msg.topic.$split('/')[1]

Only X messages per Y time unit

With the delay node, you can limit the number of messages which will be sent per time unit (seconds/minutes/hours/days).
Intermediate message will be dropped.

Node-RED delay node

Action   Rate Limit 
         All messages  
Rate     [1] msg(s) [10] [Minutes]
         Drop intermediate messages

You can also combine two delay node, one with 1 messages per 5 minutes and an extra with 10 messages per day to avoid a flood of messages.


Trigger only on rise and fall

The hysteresis node is a node that forwards its incoming message only if the numeric value of the message payload rises above one specified threshold, or falls below another. This node is a combination of the rising edge node and falling edge node

Node-RED hysteresis node

This can be used, for example, to monitor a dryer if the energy consumption is like this.

Grafana graph of the dryer

When the node is defined like this:

Rising threshold   5
Falling threshold  6

A trigger is sent when the graph starts with the spike on the left. The input value changes from 0 to a new value higher than 5.

When the dryer is finished, the value drops below 6 to 0 again the next trigger is sent, and you can notify that the dryer is finished.


Trigger only on passing a value on rise

The rising edge node only passes a value through when an input payload value increases, and passes a defined threshold value.

Node-RED rising edge node

When the node is defined like this:

Threshold  5

A trigger is only sent when the input value changes from a value below 5 to a new value higher than 5.


Trigger only on passing a value on fall

The falling edge node only passes a value through when an input payload value decreases, and passes a defined threshold value.

Node-RED falling edge node

When the node is defined like this:

Threshold  6

A trigger is sent only when the input value changes from a value above 6 to a new value lower than 6.


Table of Content ^

« See also my other Node-RED pages


^^ Top | Homepage | Best Buy Tips | Automation Ideas | Blog posts | Sitemap