New: the AI firewall watches every module and explains each incident in plain words. See how it works

Counters, statistics and watchdogs

Reference of the blocks that remember – Counter, Delta, Statistics, Watchdog and Start / end – and how block memory behaves on Hermetry.

Some blocks remember earlier messages: a count, the previous value, a window of values, the time of the last message. This page lists those blocks and explains how their memory behaves, which matters when you deploy changes.

How block memory works

RuleDetail
One memory per deviceUnless you set key, these blocks keep a separate memory per message originator: each device has its own count, previous value or watch. Set key to msg.topic or another path to group differently.
Survives restartsMemory and waiting messages are kept by the platform; a restart or a move to another worker does not lose them. Waits re-arm at their original due time.
Reset on settings changeA block keeps its memory across a deploy when its settings did not change. A block whose settings changed starts with an empty memory (messages it was holding are kept). A removed block, or one whose type changed, loses everything.
Kept while pausedA switched-off or paused flow keeps its blocks’ memory; a deleted flow loses it.
SizeAt most 10,000 keys per block; beyond that the oldest key is forgotten. Held messages count against 16 MiB per block.
TestsA test starts from an empty memory, or from a read-only copy of the live memory when you tick Start from the live state and context. A test never changes the live memory.

So: when you change a Statistics window, its averages start from scratch; when you only rewire around it, they continue.

Counter

Counts messages per key, over all time or within a sliding window, and adds the count to the message.

SettingMeaningDefaultValues
nThe count that sends a copy to reached; empty or 0 = neverempty0 or more
window_msCount only the last this long; 0 = all00 to 7 days
reset_at_nStart again from 0 when n is reachedoffon, off
keyEach key has its own countmsg.originatora path
storememory, or persist (kept in the flow’s persistent context)memorymemory, persist

Outputs: out (every message, with msg.count), reached (a copy when the count is n or more). msg.reset = true sets the key’s count to 0. Without reset_at_n, every message from the n-th on also goes to reached.

Example: “3 door openings within 10 minutes”: n 3, window_ms 10 min, reset_at_n on, reached → Raise alarm.

Delta

The difference between a number and the previous number of the same key: consumption from a meter, pulses since the last report.

SettingMeaningDefaultValues
inputThe numbermsg.payloada path
outputWhere the difference is writtenmsg.payload.deltaa path
periodWhere to write the milliseconds since the previous valuenonea path
roundDecimals, applied firstnone0 to 15
on_negativeA drop (counter restart)errorerror (negative_delta), pass (written with its sign), zero
skip_zeroPass a zero delta on unchanged, without writing itoffon, off
keyEach key has its own previous valuemsg.originatora path
seedThe first message’s previous valuenone (delta 0)none, latest (the device’s stored latest value)
seed_keyThe stored key to seed from (seed = latest)up to 128 characters
ts_pathWhere the reading’s time isthe record timea path

Outputs: out, other (no value at the input path), error (not_a_number, negative_delta). After a drop, the new value becomes the baseline in every mode. Delta reads no database per message, so it is the efficient way to compute consumption.

Statistics

Count, sum, average, minimum, maximum, standard deviation, last value and rate over the last values or the last period, per key.

SettingMeaningDefaultValues
propertyThe numbermsg.payloada path
windowcount (the last size values) or time (the last size ms)countcount, time
sizeNumber of values, or the window in ms10count: 1 to 10,000; time: 1 ms to 7 days
outputsWhich figurescount, avg, min, maxany of count, sum, avg, min, max, stddev, last, rate
emiteach message, or once per full window (end_of_window)eacheach, end_of_window
keyEach key has its own windowmsg.originatora path

msg.payload is replaced by the figure (one output chosen) or an object of figures. rate is values per second. A time window holds at most 10,000 values. After switching window to time, set size in milliseconds: the default 10 would be 10 ms. Error invalid_value “not a number”.

Example: hourly average sent once an hour: window time, size 3600000, outputs avg, emit end_of_window.

Watchdog

Notices when messages stop: if no message of a key arrives within the time, it sends a timeout message; when messages come back it reports that too.

SettingMeaningDefaultValues
msHow long a key may be silent1 min100 ms to 7 days
keyEach key watched on its ownmsg.originatora path
repeatSend timeout again every ms while silentoffon, off

Outputs:

  • timeout: a new message (a new run) with msg.payload = the key, msg.topic of the last message, msg.timeout_ms, and the originator of the last message, so Raise alarm works on it.
  • ok: the first message of a key after a timeout, unchanged.

Other messages are not passed on. The watch of a key starts with its first message: a device that never sends is not noticed (use an offline alarm rule for that; see Offline alarms). A late message (after an outage) neither feeds nor fires the watchdog, so a silence alarm is not cleared on old readings. Watching per device needs key set to the device: msg.originator (the default) or msg.metadata.deviceId.

Start / end

Marks the start and the end of a period of activity.

SettingMeaningDefaultValues
msQuiet time after the last message that ends the period1 min0 to 7 days
keyEach key has its own periodmsg.originatora path

Outputs: start (a copy of the first message of a period, at once), end (the last message, ms after it arrived). Messages in between do not go out.

Variables as memory

For values several blocks or flows share, write variables with Set variable or Change and read them with paths:

StoreScopeLimit
flow.xThis flow1 MiB per flow
global.xEvery flow of the organisation4 MiB per organisation
flow.persist:x, global.persist:xThe persistent store of the same scopewithin the same limits

A write over a limit fails with limit and keeps the old value. The editor’s Activity > Data tab shows the values and how full the stores are. See Action blocks.

Timers

For “if nothing cancels it within 10 minutes, do this” across flows, use the Timer action block with a Named timer trigger. See Action blocks and Trigger blocks.