function
Last updated
Last updated
You need this component when you can`t find another one with the needed function. So, you can write this function to the function component. You need to know JavaScript to do this.
Explore Writing Functions Guide.
The change component provides changing a message.
This is a simple flow where a message payload is '1' and the topic is 'Start'.
You can change this payload value or topic in four ways:
1. Set - set a value to a message payload or topic just by setting a new one.
You can see that the first debug component shows the payload value '1', when the second one that goes after the change component shows '2'.
2. Change - change a message due to a specific condition.
Here we set the conditions: if msg.payload = 1 (number type), then change it to '2' (number type); if msg.topic = 'Start' (string tipe), then change it to 'Launch' (string type).
3. Delete - delete a message or a part (a parameter) of the message object.
4. Move - move a value to a new message property, removing the previous one at the same time. (Note: to show explicitly how we moved the value 'Start' from 'topic' to a new property 'name', we changed the output method in the debug components).
The switch component builds different paths due to conditions.
In this example, we imitate two kinds of messages from a sensor - '1' and '23'. Using the change components, we set 'Ok' to the payload after the message '1', and 'Alarm!' after the message '23'.
Imagine that it`s Ok when the sensor sends '1'. For any other number, we have to send an 'Alarm!' message. The switch component may take a message and send it to a route depending on different conditions. In our example - if '1' then to the 'Ok' route, if 'not 1' - to the 'Alarm!' one.
Many condition options in the component properties allow specifying conditions for a message`s further path. Each condition will make a new connection port on the component in turn.
Mapps the payload number due to properties set up. If the payload is not numeric tries to convert it - for example, string type '1' to numeric type '1'.
Choose the msg Property to scale (1). By default, it`s msg.payload.
Choose Action - the type of mapping (2).
Scale the message property - the number will be scaled due to input and target range ratio. For example, if the target range is x10 to the input range so the payload number will change to x10. '5' becomes '50' etc.
Scale and limit to target range - the number scales the same way, but the result will be in the target range. E. g. '12' becomes '120', but the result will be '100' due to the range maximum.
Scale and wrap within the target range - the result will be wrapped within the target range. So '12' becomes '120', but only '20' is wrapped within the target range.
Specify the input range (3).
Specify the target range (4).
You can round the result to the nearest integer (5).
In the example, we will examine the three action types for the input scale 0 to 10 and the target scale 0 to 100.
It can be used for percent converting, for example. Just choose the target range 0 to 100 and Scale the message property action type.
Sets the payload by embedding input values to a template. Useful for composing messages, emails, HTML pages, etc.
Choose the message context (from the component, the flow, or the global context variable) and the message object Property (1) to extract the data from.
In the Template field (2), specify the template for the output message. By default, it proposes you to use a simple expression with dynamic adding of the payload value. E.g., if you write Hello, {{payload}}! and send Bob payload to the component, the result will be Hello, Bob!
Double curly braces are the Mustache syntax for taking a corresponding variable. The template field also takes other valid syntax and allows you to Highlight the Syntax.
Choose Format (3) - if you choose Plain text, the output message will ignore template syntax.
Choose the Output format (4) - you may use the template for generating JSON or YAML content.
Delays each message passing through the node or limits the rate at which they can pass.
There are two modes (Action types) for the component`s properties.
The first mode is Delay each message (1). Allows to set up a delay span for each message that comes through. For example, to avoid flooding your email or a dashboard with messages.
You can set a Fixed delay interval, a Random one between some numbers, or use the msg.delay of each message (2).
Set up the delay interval for each message (3).
In the Rate Limit mode (4), the component limits the number of messages that come through at an interval.
Choose to rate the limit for All messages or For each msg.topic (5). For this second option, you can choose to release the most recent message for all topics or release the most recent message for the next topic.
Set up the Rate (6).
You can optionally discard intermediate messages as they arrive (7).
In the next example, we will inject a message with the array of numbers from 0 to 5, then split it to separate messages for each number and limit their arrival to 1 for a second.
The component sends a message when triggered and then sends the second one on some conditions.
Choose a message value to Send (1). By default, it`s a string type '1'. If you want it to send a message that arrived as a trigger, choose the existing msg object.
There are three modes for the component behavior after the first message sent (2):
wait for - the mode when you specify the time span (3) for the next message (5) release;
wait to be reset - when triggered, the component sends a message and blocks all subsequent ones before receives a reset (7) command. Then sends the message again and so on;
resend it every - when triggered, the component resends the same message in specified intervals (3).
In the wait for mode, you can choose to extend the delay if a new message arrives (4). E.g., the trigger node will 'stay calm' until it receives signals, and it sends an 'alarm' when signals vanish - as it works in watchdog devices.
The interval may be set up by an incoming msg.delay (4).
Specify a second message (5). You may choose to send the second message to a separate output (6).
There are two types of the reset command (7): incoming msg.reset with any value, or you can define the msg.payload value that resets the trigger component.
Choose whether it handles all messages or each one (8).
In the example, we send a message every 1 second, but it blocks all the following messages until we reset the condition by sending msg.reset.
Notice that the blue dot below the trigger component indicates the ongoing condition - in this example, it`s waiting for a reset message.
The component allows you to execute system commands or scripts and take their outputs. For example, you can run a copy command (for Windows) to copy a file to another directory.
Enter a system Command (1).
You may use the msg.payload as the command parameters (2); otherwise, you can write them in extra input parameters (3).
You can also use extra input parameters (3) to add some flags (extra parameters) to the command.
Choose the Output mode (4). In the exec mode, you can see the output after the command is completed; in the spawn mode, you will see the results line by line as the command runs.
Set up Timeutout to limit a command execution time (5).
Here we execute the echo command using the Command field, then extra input parameters field, and the msg.payload as the command parameter:
The exec component has 3 outputs: for a payload (the result of a command execution), for en error information if any, and for execution code (0 for success and any other for failure).
Report by exception (rbe) component passes on data only if the payload changes. For example, you send to a motor the command "on", and the rbe component will block all following "on`s" but will pass the "off" command.
Choose the blocking Mode (1) - there are several of them. The additional blocking properties will appear if you choose other modes.
Choose the Property (2) of the message object that the component passes (and blocks). By default, it`s payload.
In the following example, we send through the rbe component a payload value '1' multiply, but the node passes it only once and then blocks until we send '2'. And vice versa.