Reeve Docs

Docs / Reference

Expressions

A small infix language available on workflow block input ports. It replaces the three-block "fetch, compare, branch" chain and is not a scripting language. It is small enough to audit by hand and has no reflection or eval surface. The language is closed: there is no hook to register a function, and an unknown name is refused when the expression is typed.

The expr: opt-in

The engine inspects every resolved input value after config merge and upstream binding. A string starting with the literal prefix expr: has the prefix stripped and the remainder evaluated. Anything else is left untouched, including a string that merely contains ${…}, which reaches the block verbatim. The result is a number, string, boolean, null, date-time or Json, and the block's normal port-type coercion takes over.

Json is read only through a projection. A Json or Json? value (a trigger payload key, ${deviceRaw.<name>} in a helper, the result of parseJson) is not a result, an operand or an argument of any other function, so it can neither feed a block nor be compared, not even with null. jsonPath(x, "$.path", "Type") reads a member as a Boolean, Int, Number, String or DateTime, a collection of one of them, or a Map<String,V> of one, and jsonPathText(x, "$.path", "String") reads the selected node as its JSON text, which is how a Json value is compared with a string. A path takes at most 100 000 steps (each selector applied to a node, and each value a wildcard or slice passes over) and its nodes hold at most 16 MiB of JSON; past either limit the call fails as too-large, which the preview shows as an error and a helper records as an evaluation error.

Expressions apply to action-block input ports only. They are not available in trigger configuration, and a sub-workflow's target id may never be an expression.

Grammar

Expression  := Ternary
Ternary     := Coalesce ( "?" Expression ":" Ternary )?
Coalesce    := LogicalOr ( "??" Coalesce )?
LogicalOr   := LogicalAnd ( "||" LogicalAnd )*        LogicalAnd := Equality ( "&&" Equality )*
Equality    := Relational ( ( "==" | "!=" ) Relational )*
Relational  := Additive ( ( "<" | ">" | "<=" | ">=" ) Additive )*
Additive    := Multipl ( ( "+" | "-" ) Multipl )*     Multipl := Unary ( ( "*" | "/" | "%" ) Unary )*
Unary       := ( "-" | "!" ) Unary | Primary
Primary     := Number | String | "true" | "false" | "null" | Variable | FunctionCall | "(" Expression ")"
Variable    := "${" DottedPath "}"                    FunctionCall := IdentSeg "(" ArgList? ")"

Precedence runs lowest to highest: ternary and ?? (both right-associative; a ?? b is b when a is null), ||, &&, ==/!= (strict, no coercion; an Int beside a Number widens), relational (numbers, strings and date-times only), +/- (+ concatenates strings, and converts an Int, Number, Boolean or DateTime beside a String invariantly), *///% (two Int operands stay Int, except that / always gives a Number), unary -/!, then calls and variable resolution.

Limit Value Enforced at On breach
Expression length 4096 characters The preview endpoints and a helper's stored expression 400 before parsing, and the string is never evaluated. An expression in a workflow block's input has no length cap of its own. The size of the definition that holds it bounds it, and the node budget bounds what the parser builds from it.
Recursion depth 32 levels Parser An expression-syntax refusal (a compile diagnostic, or ok: false from the preview), never a stack overflow
Syntax tree size 1000 nodes Parser The same refusal. It bounds a flat chain such as 1+1+1+… that never deepens.

Namespaces

Namespace Shape Notes
device ${device.<name>.<type>.<member>} A helper expression only. The device's canonical capabilities, each with the term of its kind (see helpers). A workflow does not register it, see Device state in a workflow.
deviceRaw ${deviceRaw.<name>} A helper expression only. The device's raw vendor payload as Json?, read through jsonPath or jsonPathText.
trigger ${trigger.<field>} Envelope that fired the workflow. id and firedAt are set by the host on every fire. id is the automation trigger's own id and is identical on every fire of that trigger, so it does not identify a run. The remaining leaves are whatever the workflow's trigger types declare in FirePayloadSchema, and GET /api/expressions/context-schema?scope=workflow:<id> returns exactly that set.
now ${now}, ${now.year}, ${now.hour}, ${now.iso}, … UTC.
now (local) ${now.localyear}, ${now.localhour}, ${now.localdayofweek}, ${now.localiso}, … Household time zone. Both sets derive from one captured instant, so they never skew. The editor's autocomplete offers both sets, iso and localiso as String and every other field as Int.
parameter ${parameter.<name>} Workflow input parameters.
previous ${previous.<nodeId>.<output>} Outputs of nodes that run before this one on the same canvas. The node is named by its id, never its display name; the editor's Insert value writes the reference at the cursor (replacing any selection) and leaves the cursor in the field right after it.
helper ${helper.<name>} or ${helper.<device>.<helper>} Resolves live against helpers. One segment names a helper attached to no device; two name a helper of the live (not retired) device with that friendly name. A path that matches no helper, or more than one, is refused when the expression is checked and reads as absent in a run. Boolean answers as Boolean, Number as Number, Counter as Int, and DateTime as Int, its whole Unix seconds (the term of ${now.epoch}); an expression-derived helper answers the result type it declared (required at create, declared once, never changed), and one that declares none is refused.

What the trigger namespace holds

id and firedAt are always present. The host writes them last, so a value a plugin supplies for either is dropped. Everything else is what the trigger type declares in its FirePayloadSchema, and the editor's autocomplete offers exactly those leaves. A trigger type that declares nothing gets id and firedAt and no other leaves. That applies to Cron, Sun, Webhook, StateChange and the two geofence triggers. Only DeviceEvent and the four camera types declare a schema, so ${trigger.deviceId} does not resolve on a StateChange trigger. The four camera trigger types declare:

Trigger type Fields on top of id / firedAt
CameraObjectDetected deviceId, eventType, eventId, objectClass, zone, confidence
CameraPlateRecognized deviceId, eventType, eventId, plate, plateScore, zone, matched
CameraSoundDetected deviceId, eventType, eventId, soundClass
CameraMotion deviceId, eventType, eventId, stretchId, edge

A declared field is always a present key. Detail the camera did not report is a null, so ${trigger.zone} reads as null. Every payload key reads as Json?: a typed input takes it through a projection, jsonPath(${trigger.zone}, "$", "String"), which fails the node with value-absent on a null and gives null when the projection's term is nullable ("String?"). matched is computed by the trigger against its own plate list and is not a member of the device-event contract. It is constant in the two list modes and only informative in the any-plate mode.

The envelope survives a suspension: the persisted trigger envelope carries the whole payload and not just the id, so ${trigger.zone} still resolves after a WaitForDuration.

The namespace is empty inside a sub-canvas. An IfElse branch, a ForLoop or IterateOver body, a WhileLoop body and a TryCatch branch all start with no trigger and no envelope, so every key reads as null there. A workflow that goes "person detected, then if confidence > 0.9, notify ${trigger.zone}" therefore fails the notify node with value-absent, or sends a null with a nullable projection. Read the field you need in the outer graph and pass it in as an input.

Device state in a workflow

A workflow expression cannot use ${device.*} or ${deviceRaw.*}. They are refused as expression-unknown-namespace when the workflow is compiled. Read device state with a device-property block and reference that node's output (${previous.<nodeId>.Value}). Only a helper expression reads a device directly.

Functions

Calls resolve against a fixed table of overloads. A call that matches no overload is refused when the expression is checked (expression-type-mismatch). A nullable argument matches no overload, except the Json? subject of a projection; give it a default with ?? first.

Function Overloads Notes
min(a, b…) / max(a, b…) Int… → Int; Number… → Number One or more arguments; a mix of Int and Number widens to Number
round(x) Number → Int; Int → Int Half away from zero. There is no digits argument: round(x * 10) / 10 keeps one decimal. overflow when the result does not fit an Int
floor(x) / ceil(x) Number → Int; Int → Int overflow as for round
abs(x) Int → Int; Number → Number overflow for the smallest Int
len(s) String → Int UTF-16 code-unit length
contains / startsWith / endsWith String, String → Boolean Ordinal, case-sensitive
toNumber(x) Int → Number; String → Number? A string is parsed invariantly; null when it is not a finite number
toString(x) Boolean, Int, Number, String or DateTime → String Invariant formatting
toJsonText(x) a value that is not null and not Json → String Canonical JSON text: keys in ordinal order, no white space
parseJson(s) String → Json? json-parse when the text is not JSON; read the result through a projection
jsonPath(x, path, type) Json?, String, String → type path (an RFC 9535 query) and type are string literals. A type that is not a collection needs a path that selects one node. value-absent on a null unless type is nullable; narrowing when the value does not fit type; too-large past the path budget
jsonPathText(x, path, type) as jsonPath, with type a String or a collection of them The selected node as its JSON text

Typing and failures

Every expression is typed before it runs: a workflow's when it is compiled, a helper's when it is saved. A read the scope does not declare, a call or operator with no matching overload, or a result that does not fit the port is refused then, with the rule it breaks (expression-syntax, expression-unknown-namespace, expression-out-of-scope, expression-field-access-invalid, expression-type-mismatch, expression-result-type-mismatch or, for a projection's path or type, json-projection-invalid). A mistyped path therefore does not reach a run.

What only a run can know fails the node with expression-runtime-error and a category: value-absent for a read that did not resolve, overflow, division-by-zero, narrowing, json-parse or too-large. The node's error policy takes over. There is no lenient mode in which such a failure reads as null.

Deferred evaluation

Expression inputs are pre-evaluated before a block runs. The exception is the wait-for-expression block, which needs the literal string so the resumption service can re-run it on every helper-change event or poll tick while the run is suspended.

A block factory opts an input out of pre-evaluation through its raw-expression input set, which is empty by default. A block that stores the expression and re-evaluates it later under its own scheduler must declare its raw-expression input names. A block that only consumes an evaluated result needs to do nothing.

Preview endpoint

POST /api/expressions/preview takes { "expression": "expr:1 + 1", "contextScope": "global" } and answers { "ok": true, "value": 2, "type": "Number", "error": null, "elapsedMicroseconds": 312 }. A failure returns ok: false with error: { message, position, suggestion, ruleId }; a syntax error, a depth or node-count breach among them, answers 200 this way. A request the endpoint cannot take answers 400 before anything is parsed: a missing or malformed body, no expression, an expression over 4096 characters, a body that names contextScope more than once, or a context scope over 256 characters or holding a control character. There is no closest-name suggestion: the message for a bare identifier suggests writing it as ${name}, and a misspelt path is refused when the expression is checked.

The preview reads any helper's value by name, so it requires automations.manage, which can read every helper through a run anyway. GET /api/expressions/context-schema requires automations.manage for a workflow scope and helpers.manage for scope=helper, whose answer lists every standalone helper; the helper editor previews through POST /api/helpers/preview-expression, which also requires helpers.manage.

The preview evaluates outside any run, so it refuses every ${previous.*} and ${parameter.*} read as expression-out-of-scope, and it reports only its first refusal. Both the workflow preview and the helper preview read the now.local* fields in the household's time zone, as a run does. It has no trigger either, so every ${trigger.*} key reads as null there: a projection of one into a type that is not nullable fails with expression-runtime-error, and a nullable one previews as null. For an expression that reads ${previous.*}, ${parameter.*} or ${trigger.*}, the workflow editor shows none of these: not the refusal, not a failed evaluation and not the value a trigger read previews as. It shows what the draft analysis, which compiles the whole graph, refuses in the node's expressions. When the analysis accepts them, the editor says the expression reads values known only when the workflow runs. Until the analysis answers for the draft on screen, a ${previous.<node>.<output>} that names no block wired before the edited one is a warning, not an error ("'Get Property' is the block's name, not its id"): the compiler also reads a node earlier in its order that no wire leads from.

Examples

expr:round(${previous.readHumidity.Value} * 10) / 10               # device state, read through a block; one decimal
expr:${now.localhour} >= 22 || ${now.localhour} < 7
expr:${helper.vacation_mode} == false

Security

Nothing in the engine loads a type, an assembly or a member named by expression text, and there is no dynamic or scripting engine behind it. All functions are pure and synchronous, and none touch I/O, spawn processes or open connections. The grammar has no loops, closures, assignment or regex, and there are no lambdas, user-defined functions or macros. Calls resolve only bare whitelisted identifiers, so a dotted call fails to parse, because . is reserved for variable paths inside ${…}. Depth and node count are capped in the parser, and the evaluator follows the tree's shape, which bounds worst-case stack use. The parser keeps the syntax trees of the 4096 most recently used sources and never caches a syntax error.