Reeve Docs

Docs / Reference

Helpers

A helper is named, persistent automation state, such as a vacation toggle, a guest counter, an "alarm armed" boolean or a tally of how often the door opened today. Helpers let workflows share state across runs without forcing it into the device model, which would tie automation state to the lifecycle of an integration.

A helper is a separate entity and never a device source. It is either attached to a logical device for grouping or standalone.

Types and identity

Type Config Notes
Boolean none
Number { min?, max?, step?, unit? } The range is enforced on write.
Counter { min?, max?, wrapAround?, defaultIncrement? } Atomic increment with clamp or wrap.
DateTime { precision? } (date, minute or second) Stored as Unix seconds. A write accepts whole Unix seconds or an ISO-8601 timestamp between 1970-01-01 and 9999-12-31 UTC.
ExpressionDerived { evaluationDebounceMs } and a result type Re-evaluated when a dependency changes. The result type is required at create.

A wrap-around counter needs both a minimum and a maximum. Configuration validation does not enforce the pairing, and a half-configured range produces a wrong value.

Names are slugs matching ^[a-z0-9_]{1,64}$. The slug cannot change after creation. The display name and the type config can change, and the type can change as described in Type change. Slugs are unique per scope:

Scope Namespace Expression form
Standalone One global namespace ${helper.<name>}
Attached Unique per device, so the same name may recur on different devices ${helper.<device>.<name>}

Deleting a logical device deletes its attached helpers. Expressions that still reference a deleted helper resolve to null and log one warning. Nothing is disabled automatically.

API and permissions

Reading a helper (the list and the single read) needs dashboards.view or helpers.manage, so helper widgets work on a dashboard shared with a viewer. Shared dashboards are visible to every such user, so the read is not narrowed to the helpers a dashboard shows. Changing a value (the value and increment calls the widgets make) needs devices.control or helpers.manage. Creating, editing and deleting helpers and the expression preview need helpers.manage.

Without helpers.manage, a helper attached to a device follows the caller's access to that device:

  • When the device is hidden from the caller, the helper is left out of the list, ?deviceId= of that device lists nothing, and the helper's read and value calls answer 404.
  • When the caller may only view the device, the helper reads normally and its value calls answer 403.

An expression helper is not filtered by the devices its expression reads (known limitation). Helper widgets disable their toggle, slider, input and counter buttons for a user without device control or helper management, and, without helper management, on a helper attached to a device the user cannot control. The Helpers page is gated on helpers.manage.

Endpoint Verb Notes
/api/helpers?deviceId= GET Optionally filtered by attached device
/api/helpers/{id} GET / PUT / DELETE PUT updates the display name and config (and, for an expression helper, the expression and debounce). A different type (with valueJson) or resultType is a type change.
/api/helpers POST Expression helpers supply expressionBody (at most 4096 characters), a required resultType and optionally evaluationDebounceMs
/api/helpers/{id}/value POST Type-checked against the config
/api/helpers/{id}/increment POST Counter only
/api/helpers/preview-expression POST Types and evaluates an expression body without saving
Error code Meaning
helper_invalid_type, helper_invalid_name, helper_invalid_value Failed the type, slug or value check (400)
value_out_of_range A write outside the configured bounds
helper_name_conflict Duplicate slug in the same scope (409)
helper_limit_reached The per-installation cap was hit (400)
not_a_counter Increment called on a non-counter
helper_cycle An expression save would create a dependency cycle (422)
helper_type_change_refused A type change is held up. The body lists the blockers (409).

Type change

A PUT that names a different type on a value helper (Boolean, Number, Counter or DateTime, never to or from ExpressionDerived), or a different resultType on an expression-derived helper, changes the helper's term. A value helper's change must carry valueJson, which is checked as a literal of the new type against the configJson sent with it. A valueJson without a type change, or a type change without one, is refused. Counter and DateTime are both Int, so a change between them is held up only by a node that writes the helper or a trigger that compares its value.

Before it applies a change of term, Reeve checks what depends on the helper and refuses the change with helper_type_change_refused if anything does. The response lists these blockers:

  • A workflow version, current or draft, that reads the helper or writes it with a SetHelperValue or IncrementHelper node. Versions that unfinished runs or parked suspensions are pinned to are checked as well.
  • Unfinished runs and parked suspensions of such a version.
  • A WaitForTrigger node waiting on a trigger that compares the helper's value.
  • A StateChange trigger of an automation that watches the helper and has a non-empty fromValue or toValue. Such a trigger compares the value as text of the old type, which a new type would never match or always mismatch. A trigger with neither value never fires and does not block. A trigger whose configuration cannot be read blocks and is named by its automation.
  • An expression helper that reads this helper and no longer types against the new term, or that declares no result type.
  • A run or suspension whose pin manifest cannot be read.

A change that keeps the term (Counter and DateTime) is not held up by compile checks or by the helpers that read it.

Nothing is rewritten when a change is applied. A value helper emits a value change when the stored text moved. An expression helper keeps its body, is queued for evaluation, and its stored value is reset to null and emitted as a value change. A value write or counter flush that loses a race to a type change is refused, and a flush is dropped.

The check is a snapshot taken before the change commits. A version published, a run admitted or a suspension parked meanwhile is not refused by it. The version is refused at its own next compile or admission, and a run that holds values of the old type fails at the gate or on resume.

Trigger integration

Helper writes go through the device event sink as synthetic events that carry a helper source type, a helper:{id} external id, a value property key, and the previous and new values. An ordinary state-change trigger therefore fires on a helper change. Such a trigger accepts a helper id as an alternative to a device id and then observes only helper events for that id. There is no helper-specific trigger type or realtime channel. The trigger compares the helper's stored value with its target by meaning: two JSON numbers are equal when they are the same number however they are written, and two JSON strings when they decode to the same text, so an escaped "R&B" matches "R&B".

On a helper, the automation form takes the target value by the helper's value type:

Helper value Target input
Boolean helper, or an expression with a Boolean result true or false
Number helper, or an expression with a Number result a number, with the numeric comparisons
Counter helper, or an expression with an Int result a whole number, with the numeric comparisons
DateTime helper a date (and time, by the helper's precision), stored as epoch seconds, with the numeric comparisons
Expression with a String result plain text, stored as a JSON string
Any other expression result the stored value's text as written

A helper the form cannot list (it was removed, or the list could not be loaded) still shows its stored target, and the form says why it cannot be changed there.

Counter coalescing

Increments coalesce in process over a short debounce window. A thousand rapid increments land as original + 1000 with a bounded number of database writes and emitted events. The emitted event carries the value from before the window as the previous value and the final value after it, never the intermediates, so an automation does not see the values in between. Pending increments are held in process memory and are lost if the process restarts before the window closes.

Expression-derived helpers

An expression helper is event-driven and is never polled.

  1. On save, the expression is parsed and its dependencies are stored with the helper. References normalise to colon-separated keys: ${device.kitchen.sensor.temperature} becomes device:kitchen:sensor:temperature, ${deviceRaw.lamp} becomes deviceRaw:lamp and ${helper.vacation_mode} becomes helper:vacation_mode. The expression is also typed against the helper scope. A result that is not the declared type (or, for a nullable declaration, its non-null form) is refused with expression-result-type-mismatch.
  2. When a device or helper it depends on changes, the dependent helper is queued for evaluation.
  3. A worker debounces per helper (trailing edge) and writes only when the value actually changes.
  4. A change cascades. The new value is emitted as a synthetic event, so helpers that depend on this one are queued in turn. Expressions that read now.* are re-evaluated on a clock tick.
  5. A device rename breaks every reference to the old name, so the rename queues every helper registered under the old name, which then reports the unresolved reference. This happens for every committed change of a friendly name. A save that resubmits the unchanged name, a failed save and a rolled-back transaction wake nothing.

Result type

An expression helper declares the term of its result at create. It is Boolean, Int, Number, String or DateTime, any of them nullable (Int?), or a Collection<...> of one whose element may be nullable too (Collection<Int?>?). Json is not a result type. A create without a result type is refused, and an update that names a different one is a type change.

The expression is typed on create, and on an update that changes it or declares the type. An expression that does not type is refused with the typer's rule id and message, and so is one whose result term is not the declared one. A stored expression is not typed again by an update that leaves it unchanged, so a helper whose device was since renamed or deleted can still be renamed. Each evaluation checks the same two things again. A failure records UnresolvedReference or EvaluationError with the reason and keeps the stored value. The value stored is the result's JSON: true or false, a number, a quoted string, a collection's array, or null when a nullable expression computes null.

${helper.x} answers the declared term. A stored value is read in that term's type only (Int as a 64-bit integer, Number as a double, a collection as a list). A stored value off the term fails the read, and a stored null reads only under a nullable declaration.

The device namespaces

${device.<name>.<type>.<member>} (for example ${device.kitchen.sensor.temperature}) answers each capability key of two segments that the device declares, with the term of its kind. It refuses every other path, including the three-segment keys such as outlet.power.power, which are read through deviceRaw. The value is read from the device's canonical state. A declared key with no value reads as absent, and a value off its term fails the read. A device name that two live devices share is refused, and a retired device is not addressable.

${deviceRaw.<name>} answers the raw vendor payload as Json?. Read it through jsonPath(x, "$.path", "Type") or jsonPathText. A device report re-evaluates every helper that reads either namespace. A path nothing answers, such as a device that does not exist or a key nothing declares, records UnresolvedReference.

Cycles

A helper save whose expressions would transitively depend on themselves is rejected before commit with helper_cycle, and the response returns the cycle path. A user rename of a device is rejected only when re-keying its attached helpers creates a cycle or merges separate cycles. A cycle that already exists does not block it. Members of an existing cycle are skipped by the evaluator and keep their last stored value. Helpers that depend on them but are outside the cycle continue to evaluate with that value, or null if there never was one. Breaking the cycle through any member makes the members evaluate again.

Evaluation timing

One evaluation of a helper runs at a time on a replica, and the last request is always evaluated. A request for a helper that is already being evaluated is kept as the newest, and one more pass then runs on freshly read state, however many requests arrived. The debounce is trailing-edge: the first request runs at once, and a request inside the window of the previous evaluation is kept and runs when the window ends. A helper therefore evaluates at most once per window and always ends on the last value, at the cost of up to one window of delay. With a device publishing at high frequency, a 100 ms debounce caps the helper at ten evaluations per second.

Across replicas, each evaluation takes a per-helper advisory lock and reads the helper, the device state and evaluates, compares and writes in one transaction. A second replica evaluating the same helper waits and sees what the first committed, so two evaluations that computed the same new value emit one change event. The change event is emitted after commit.

Configuration

{ "Helpers": { "MaxHelpers": 500, "WorkerMaxParallel": 4, "TimeTickIntervalSeconds": 60 } }

The values shown are the defaults. evaluationDebounceMs defaults to 100 and accepts 0 to 600000. A value outside the range is rejected at save. A replica that does not serve (it is fenced or still loading) dispatches no evaluations.

Frontend surfaces

A Helpers page manages standalone helpers, the logical device page has a linked helpers section, and three dashboard widgets are available: a boolean toggle, a number (slider when bounds are set, otherwise an inline input) and a counter with increment and decrement buttons.

Troubleshooting

Symptom Cause and fix
A helper is refused on save with expression-result-type-mismatch The expression's result is not the declared result type. Declare the type it computes, or change the type through a type change.
A helper expression is rejected on save with a cycle It transitively depends on itself. The returned path names the loop.
An expression helper stops updating on one replica That replica does not serve (fenced or still loading) and dispatches nothing. It catches up once it serves again.
A helper keeps following a device under its old name The rename bypassed change tracking (bulk update or raw SQL), so no replica saw it. Route the write through the normal save path.
Helper creation fails at the limit The per-installation cap (Helpers:MaxHelpers). Raise it or delete unused helpers.
Helpers vanish when a device is removed Attached helpers are deleted with their logical device. References then resolve to null with one log warning.
A counter's intermediate values never reach an automation Coalescing emits only the values before and after the window.
A wrap-around counter drifts to a nonsense value Only one bound was configured. Validation does not catch it.