Expression Tags
Expression tags compute their value from a formula evaluated by the Expression Evaluator service. Expressions can reference tags, devices, AI models, and model bindings, use arithmetic and logical operators, and call built-in math and statistical functions.
Expressions are evaluated in one of two ways:
- Reactive: when a referenced tag updates, the expression re-evaluates immediately (within milliseconds). This is the default whenever the expression references at least one tag — through its value, status, or error code.
- Timer-based: if the expression references no tags at all (for example it only references device, model, or binding fields), it evaluates once per second.
Common use cases include:
- Unit conversions (e.g. Celsius to Fahrenheit)
- Scaling raw signals (e.g. 4–20 mA to 0–100%)
- Averaging multiple sensors
- Smoothing noisy readings with time-aware filters
- Computing rate of change for trend detection
- Alarm thresholds with deadband filtering
- Health monitoring (react to device or model failures)
References
Type @ in the expression editor to search and insert a reference. The autocomplete menu shows tags, devices, AI models, and model bindings, each with the fields you can reference.
Every reference has three segments — @[Type:Name:field]:
Status Values
status is a numeric state, not a true/false flag:
Test for the state you actually mean — == 1 for running, == 2 for failed, != 1 for "not running". An expression written as status == 0 to detect a failure never fires, because a failed entity reports 2.
Tag References
Reference a tag's live value, status, or error code:
Referencing a tag through any of these fields makes the expression reactive — it re-evaluates as soon as that tag updates.
Device References
Reference a device's connection status or error code:
A device has no value of its own — status and error code are the only fields it exposes. Use them to publish a health flag for the connection.
Model References
Reference an AI model's status or error code:
Binding References
Reference the raw prediction value from a model output binding. Bindings are identified by their numeric ID, not by a model/output name path:
Binding value references give you access to a model's prediction output without needing an in-memory tag to historize it first.
Arithmetic Operations
Standard math operators are supported:
Comparison Operations
Comparisons return True or False and are commonly used inside conditional expressions:
Logical Operations
Combine conditions with and, or, and not:
Math Functions
Built-in math functions for common calculations:
Statistical Functions
Functions that operate on lists of values:
Random helpers are also available for testing and simulation: random() (float in 0–1), randint(a, b), uniform(a, b), and choice(list).
Filter Functions
Filter functions smooth, transform, or gate input signals. They maintain internal state across evaluations, so each call remembers its previous output.
filter: Exponential Moving Average
filter(value, tau) applies an exponential moving average. The tau parameter is the time constant in seconds. It controls how quickly the output tracks the input, regardless of how often the expression evaluates.
At each evaluation the filter computes: alpha = 1 - e^(-dt / tau), then output = alpha x input + (1 - alpha) x previous. On the first evaluation the output equals the input.
moving_avg: Moving Average
moving_avg(value, window) computes the average of all samples received within the last window seconds.
rate: Rate of Change
rate(value) returns the rate of change of the input in units per second. It only updates when the input actually changes, so repeated evaluations with a stale value don't distort the result.
deadband: Deadband Filter
deadband(value, threshold) only passes through changes larger than threshold. The output holds its last accepted value until the input moves far enough away.
Conditional Expressions
Use Python's ternary syntax for if-else logic:
Practical Examples
Temperature Conversion
Celsius to Fahrenheit:
Scaling and Offset
Convert a 4–20 mA signal to 0–100%:
Average of Multiple Sensors
Device Health Flag
Output 1 while the device connection is up, 0 when it is stopped or failed:
Device Failure Alarm
Raise an alarm only on a genuine failure, so a device you deliberately disabled does not trigger it:
Model Health Check
Output 1 when the AI model is running, 0 when it's stopped or failed:
Alarm with Deadband
High alarm above 95 that ignores input movements smaller than 5 units, so a value hovering around the threshold does not chatter the alarm on and off:
Smoothed Differential
Smoothed pressure differential with a 30-second time constant:
Rate of Temperature Change
Degrees per minute:
Smoothed Deadband
Reduce noise first, then gate small changes:
