Node switch
The switch
node is designed for routing messages based on their content, structure, or other conditions. It is a powerful tool for creating conditional logic in flows.
Settings for the switch
node
1. Name
A field for specifying the name of the node.
The name is displayed in the workspace and helps easily identify the node.
If left empty, the node will be called inject
.
Example:
- Node name:
check status
2. Property
Specifies which property of the message object msg
will be used to check conditions.
Example:
msg.payload
msg.topic
msg.device.temperature
Environment properties (flow
, global
) and JSONata expressions (starting with $
) are also supported.
3. Check
- Check until the first match (Default):
The message is sent only to the first output that meets the condition. - Check all matches:
The message can be sent to multiple outputs if it meets several conditions.
3. Rules
Define the routing logic. Each condition is tied to one of the node's outputs. The message will be sent to the first suitable output.
Available types of conditions:
==
: Checks for equality of value.!=
: Checks for inequality.<
: Checks if the value is less.<=
: Checks if the value is less than or equal to.>
: Checks if the value is greater.>=
: Checks if the value is greater than or equal to.has key
: Checks if the object contains the specified key.between
: Checks if the value is within the specified range (inclusive).contains
: Checks if the string or array contains the specified value.matches regex
: Checks if the string matches the regular expression.equals true
: Checks if the value is equal totrue
.equals false
: Checks if the value is equal tofalse
.equals null
: Checks if the value is equal tonull
.not equals null
: Checks if the value is not equal tonull
.is of type
: Checks if the value is of the specified type (e.g.,string
,number
,boolean
).empty
: Checks if the string, array, or object is empty.not empty
: Checks if the string, array, or object is not empty.else
: Executes if none of the other conditions are met.
Example:
msg.payload
is greater than50
Input
The node accepts the msg
object.
Which specific properties will be checked is set in the Property field.
Output
The node sends the msg
message to the output that matches the specified condition.
If the message does not meet any condition, it is not sent to the outputs.
Usage Examples
Example 1: Filtering temperature data
Task:
Categorize data into three categories: low, normal, and high temperature.
Flow:
[inject] ---> [function] ---> [switch] ---> [debug (low temp)]
| [debug (normal temp)]
| [debug (high temp)]
Settings for the switch
node:
- Property:
msg.payload
- Conditions:
is less than 10
→ Output 1is between 10 and 30
→ Output 2is greater than 30
→ Output 3
Result:
Temperatures will be routed based on their value.