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
- Round a comma value to an integer value
- String to Integer
- Strip topic name
- Only X messages per Y time unit
- Trigger only on rise and fall
- Trigger only on passing a value on rise
- Trigger only on passing a value on fall
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
} |
| 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 |
| 25,6 |
| 26 |
Set [msg].payload
$round(payload, 0)
String to Integer
Convert a string value to an integer.
| 24.01 |
Set [msg].payload
$number(payload)
Strip topic name
Get only the last part after the ‘/’ from a topic.
| "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.

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

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

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.

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.

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.
« See also my other Node-RED pages
^^ Top | Homepage | Best Buy Tips | Automation Ideas | Blog posts | Sitemap