Skip to content
mchristegh edited this page Jul 10, 2026 · 3 revisions

A threshold-counting node for Node-RED that triggers an output after a configured number of messages arrive within a configured time window. It exists to suppress false positives from sensor noise: rather than acting on a single threshold breach, it requires the breach to repeat N times within Y time before firing.

The canonical example: a humidity sensor fluctuates around 55%. Wire it through this node configured as "3 exceedances within 15 minutes" and a single brief spike never triggers — while a genuinely persistent condition still alerts quickly, because the Trigger fires the instant the count is met, never waiting for the window to close.

The three outputs

# Output Fires on
1 Trigger The count reaching the limit within the window. Nothing else.
2 Query An incoming query message, or a Heartbeat tick. Nothing else.
3 Events Every other event, plus a duplicate copy of every Trigger.

Output 1 never carries a blocked or redundant message — anything that didn't truly happen appears only on output 3, tagged msg.ignored: true. The full event vocabulary is on the Events page; the message envelope every output carries is on Output Messages.

The one concept to understand first

The node has two window modes, and they behave very differently:

  • Fixed — one shared clock, anchored to the first message of a cycle. The window expires all at once.
  • Sliding — each message ages out individually, so the count can decay stepwise on its own as messages fall out of the window.

If the node ever seems to "lose count" mysteriously, you are almost certainly in sliding mode and watching correct behavior. Read Window Modes before anything else.

Everything is observable

Like its sibling timer-events, this node treats observability as a design principle. Every counted message, blocked message, expiry, and cooldown transition is a tagged event with a consistent envelope (timerEvent, timerState, count, ignored, source, and more) describing the node's full state at that moment. A command that didn't take effect still produces an event — labeled with what was attempted and tagged ignored: true.

Where to go next

Relationship to timer-events

This node is the sibling of node-red-contrib-timer-events, a countdown timer. The two share the same event envelope property names, command conventions, and output philosophy — downstream function and switch nodes can process both nodes' output with the same code. Where timer-events debounces by ignoring repeat messages during a run, timer-threshold requires accumulation of repeat messages within a window. They compose well: see the wiki examples for both.

License

Licensed under the Apache License 2.0. Copyright (C) 2026 mchristegh.

Clone this wiki locally