Inject

The Inject node is the beginning of many flows that are triggered manually. The box to the left of the node sends a message to connected nodes. For that reason it's often used for debugging too, to inject values at a point of choosing. The message item can be empty too. The message to send defaults to the timestamp as payload and an empty topic.

Message properties can be set to flow, or global variable values, and many other types, including JSONata expressions.

Flows can also be triggered once right after Node-RED starts the flows or with a delay. This is useful to set an initial state from a flow on boot.

An inject node can also start a flow based on a schedule. The schedules have capabilities mimicing cron. In the bottom section of the properties pane the repeat section one can select "at a specific time".

Repeating the measure on an interval is done by selecting "interval" in the "repeat" section. On a schedule requires an input higher than 1 and below 2^31. When the repeat value is 0 or below Node-RED will not display an error.

Examples

Inject on Node-RED start

To setup state when starting Node-RED, the inject node can be set to a zero delay to trigger a flow. When an Inject node is set to run only once, a small '1' is displayed after the label inside the node.

Run a flow daily at midnight

By selecting "at a specific" time in the Repeat section the inject node can generate a message at set times. Useful for data processing at set times.

Do set the correct timezone in the editor settings.

Insert a static string

The Inject node can also set the payload to other input data, for example a static string. Note this string cannot have multiple lines.

"Configure Inject a string for a flow"

Node Documentation

Injects a message into a flow either manually or at regular intervals. The message payload can be a variety of types, including strings, JavaScript objects or the current time.

Outputs

payloadvarious
The configured payload of the message.
topic string
An optional property that can be configured in the node.

Details

The Inject node can initiate a flow with a specific payload value. The default payload is a timestamp of the current time in millisecs since January 1st, 1970.

The node also supports injecting strings, numbers, booleans, JavaScript objects, or flow/global context values.

By default, the node is triggered manually by clicking on its button within the editor. It can also be set to inject at regular intervals or according to a schedule.

It can also be configured to inject once each time the flows are started.

The maximum Interval that can be specified is about 596 hours / 24 days. However if you are looking at intervals greater than one day you should consider using a scheduler node that can cope with power outages and restarts.

Note: The "Interval between times" and "at a specific time" options use the standard cron system. This means that 20 minutes will be at the next hour, 20 minutes past and 40 minutes past - not in 20 minutes time. If you want every 20 minutes from now - use the "interval" option.

Note: To include a newline in a string you must use the Function or Template node to create the payload.