Filter

What's the Filter node in Node-RED used for?

The Filter node, previously called "Report by Exception" (RBE), has two modes of operation, called deadband and narrowband. These modes allow users to limit network traffic, write operations to historians, or limit reporting of values outside a range that is worth reporting on. It's very versatile, once you fully understand the node.

The Filter node is part of the core nodes in Node-RED, meaning it is installed by default.

Deadband Mode

In deadband mode, the data transmission is triggered only when the measured value changes beyond a specified threshold value. This threshold value is known as the deadband, and it is used to prevent frequent data transmissions when the value fluctuates around a certain point. The deadband is typically set to a percentage of the measurement range or an absolute value.

For example, if the temperature sensor measures a range of 0-100 degrees Celsius, and the deadband is set to 2 degrees, then the system will only report temperature changes greater than 2 degrees. This helps reduce unnecessary network traffic and save processing power.

Narrowband Mode

In narrowband mode, the data transmission is triggered only when the measured value falls outside a specified range of values. This range is known as the narrowband or hysteresis, and it is used to prevent unnecessary data transmissions when the value fluctuates within a certain range.

For example, if the temperature sensor measures a range of 0-100 degrees Celsius, and the narrowband is set to 5 degrees, then the system will only report temperature changes greater than 5 degrees above or below the last reported value.

Both deadband and narrowband modes are used to optimize data transmission and reduce the number of unnecessary data transmissions.

Examples

Report all changes

With 3 messages send to the filter node; 1, 2, 2, the following flow will send through the first messages, 1 and 2 respectively. Then filter out the last 2 message as no changes were observed since it sent on the previous message.

Report changes, ignore the initial value

With 3 messages send to the filter node; 1, 2, 2, the initial value is used as sentinel value. Each change afterwards is send onwards. In this case printing just 2 once. The first message; 1 is remembered, and the next message afterwards is the only change in the stream of values.

Report changes larger than a certain percentage "Deadband"

If the filter node is configured to "block unless value change is great or equal than" mode with a 50% threshold configured as "compared to last valid output value" and it's send 1, 2, 2, 1 it will send on the messages 2, 1.

The initial message 1 is set as sentinel value. The second message 2 is an increase of 100% against the sentinel which updates the sentinel value to two, and sends it on. The third message is equal to the sentinel value and thus filtered. The last value, 1, is a 50% change compared to the sentinel value of 2 and send forward.

Report only on one specific value

As the filter node can block all messages where the change is too large, it can used to only report a single value when it occurs. For example, to only report integers that are equal to 2, the start value is set to 2 and the change cannot be greater of equal to 1.

Node Documentation

Report by Exception (RBE) node - only passes on data if the payload has changed. It can also block unless, or ignore if the value changes by a specified amount (Dead- and Narrowband mode).

Inputs

payload number | string | (object)
RBE mode will accept numbers, strings, and simple objects. Other modes must provide a parseable number.
topic string
if specified the function will work on a per topic basis. This property can be set by configuration.
resetany
if set clears the stored value for the specified msg.topic, or all topics if msg.topic is not specified.

Outputs

payload as per input
If triggered the output will be the same as the input.

Details

In RBE mode this node will block until the msg.payload, (or selected property) value is different to the previous one. If required it can ignore the initial value, so as not to send anything at start.

The Deadband modes will block the incoming value unless its change is greater or greater-equal than ± the band gap away from a previous value.

The Narrowband modes will block the incoming value, if its change is greater or greater-equal than ± the band gap away from the previous value. It is useful for ignoring outliers from a faulty sensor for example.

Both in Deadband and Narrowband modes the incoming value must contain a parseable number and both also supports % - only sends if/unless the input differs by more than x% of the original value.

Both Deadband and Narrowband allow comparison against either the previous valid output value, thus ignoring any values out of range, or the previous input value, which resets the set point, thus allowing gradual drift (deadband), or a step change (narrowband).

Note: This works on a per msg.topic basis, though this can be changed to another property if desired. This means that a single filter node can handle multiple different topics at the same time.