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

Condition blocks

Reference of Compare, Any / all of, If / else, In range, Device state, Changed, Not repeated and Happened n times, plus values and expressions.

A condition block tests something and sends the message, unchanged, on its yes or no output. Use them to filter and branch. All condition blocks also have an error output for a test that could not be made. This page lists them as the blocks define them, then explains the values, paths and expressions they use.

Compare

Compares one property with a value.

SettingMeaningDefaultValues
propertyWhat is testedmsg.payloada msg., flow., global. or sys. path
opThe comparisoneqsee the operators below
valueWhat it is compared withemptyany value kind; not shown for true, false, null, empty, nempty

A missing property counts as null: gt 30 is then false. Errors: invalid_value (a bad pattern or operator), or the code of a value that could not be worked out.

Operators

Shared by Compare, Any / all of, Device state and Switch:

OperatorTrue when
eq, neEqual, not equal. A number and a number or numeric text compare as numbers ("5" equals 5, true counts as 1); anything else compares by content as JSON.
lt, le, gt, geLess, less or equal, greater, greater or equal. Numbers and numeric text as numbers; two texts alphabetically; any other mix is false.
containsText contains the value; an array has an equal element; an object has a key of that name
regexText (or a number as text) matches the pattern: case-sensitive, at most 64 characters
true, falseExactly the boolean true / false (not 1, not "true")
nullMissing or null
empty, nemptynull, "", [] or {} / anything else
typeThe type is number, string, boolean, array, object or null

Patterns cannot use lookahead, lookbehind or back-references; such a pattern is refused at deploy (regex_unsupported).

Any / all of

Up to 8 comparisons joined by “or” or “and”.

SettingMeaningDefaultValues
modeHow the rows are joinedanyany (or), all (and)
itemsOne comparison per row: property, op, valuenoneup to 8 rows

Rows are checked in order and checking stops once the answer is known. With no rows, any is false and all is true.

If / else

True when an expression is true.

SettingMeaningValues
exprThe expressionrequired, up to 512 characters

no when the result is false, null, 0, "" or not a number; an empty array or object counts as true. Errors: invalid_value (does not compile), type, div_zero, steps, regex, limit.

Example: msg.payload.temperature > 30 && flow.mode == "auto".

In range

Is a number between a minimum and a maximum, with optional hysteresis.

SettingMeaningDefaultValues
propertyThe numbermsg.payloada path
minLower limit, inclusive; empty = noneemptya number
maxUpper limit, inclusive; empty = noneemptya number
hystHow far past a limit the value must go before the answer changes00 or more
keyA separate memory per value of this pathmsg.originator (one per device)a path

Once inside, the answer stays yes until the value drops below min − hyst or rises above max + hyst; once outside, it turns yes again only within min + hyst … max − hyst. Not a number: no, memory unchanged.

Device state

Tests a stored variable (flow., global.) or a platform value (sys.) instead of the message. The message only decides when the test is made.

SettingMeaningDefaultValues
pathWhat is tested, e.g. flow.mode, global.persist:countrequireda sys., flow. or global. path
opThe comparisoneqas above
valueWhat it is compared withemptyany value kind

Changed

yes when a property differs from its value in the previous message of the same key; the first message of a key is yes.

SettingMeaningDefaultValues
propertyThe value watchedmsg.payloada path
keyA separate last value per value of this pathmsg.originator (one per device)a path

Values compare as JSON text: 5 and "5" differ.

Not repeated

yes only if nothing with the same key went through yes within the period.

SettingMeaningDefaultValues
Period (window_ms)How long after a yes the key is held back1 h0 to 7 days; 0 lets everything through
keyKeys counted apartmsg.originator (one per device)a path

Only a yes starts the period; with a 1-hour period a steady stream gives one yes an hour. Use it to stop repeating notifications.

Happened n times

yes when this message makes at least n messages of the same key within the period.

SettingMeaningDefaultValues
nHow many times31 to 1,000
Period (window_ms)Sliding window10 min1 ms to 7 days
keyKeys counted apartmsg.originator (one per device)a path
reset_on_yesStart counting from zero after a yesoffon, off

Memory of condition blocks

In range, Changed, Not repeated and Happened n times remember values per key. On Hermetry the key defaults to the message’s originator, so each device has its own memory; set key to msg.topic (or another path) to share or split it differently. Each block keeps at most 10,000 keys; beyond that the oldest is forgotten. The memory survives restarts. Deploying a change to the block’s settings starts its memory empty. See Counters, statistics and watchdogs.

Values, paths and expressions

Many settings take a value of one of these kinds:

KindExampleMeaning
Number, Text, Yes / no, JSON30, "alarm", true, {"on": true}A fixed value
Variable (path)msg.payload.level, flow.limit, global.persist:site.maxRead when the block runs
Expressionmsg.payload.a + msg.payload.bWorked out for every message
Environment variableA value of the environment
Current timeThe time the message arrives

Paths

  • msg.…: the message. Fields starting with _ belong to the engine and cannot be written; msg.msgType and msg.originator are read-only.
  • flow.…: variables of this flow. global.…: variables shared by all flows of the organisation. Add persist: to use the persistent store (flow.persist:total). The first key starts with a letter or _ and has at most 32 letters, digits or _.
  • sys.…: read-only platform values.
  • Missing paths give null.

Expressions

Up to 512 characters, at most 10,000 evaluation steps.

PartAvailable
Valuesnumbers, "text", true, false, null, [arrays], {objects}, paths
Operators?: || && == != < <= > >= in + - * / % !
Number functionsabs, round(x, decimals), floor, ceil, min, max, clamp(x, lo, hi), sqrt, pow, number, int, fixed, sum, avg, and trigonometric and logarithmic functions (sin, cos, asin, rad, log10 …)
Text functionsstring, len, lower, upper, trim, substr, replace, split, join, contains, starts, ends, matches
Otherkeys, has, now, fmt_time, typeof, exists, default(x, fallback), empty
  • == compares numbers numerically and everything else by type and value; < and > with null are false.
  • Arithmetic on text fails with type, even on numeric text: write number(msg.payload).
  • {{ expression }} in text settings (templates) inserts a value: Level {{ msg.payload.level }} %.