Expression Editor
The expression editor is the text field behind calculated values in dashboards, diagrams and virtual variables. An expression references Device Variables, combines them with arithmetic and logic, and is re-evaluated each time one of those Variables reports a new value. This page is the syntax reference.
Workflow Stage: Visualize
Overview
An expression is a single line of text such as {{temp1}} + {{temp2}}. It can reference any Variable the component has access to, apply the operators and functions listed below, and return a number, a string or a boolean. The result is recomputed whenever a referenced Variable changes, so a widget or diagram element bound to an expression stays current without any further configuration.
Basic Usage
Expressions appear in three places. Dashboard widgets use them for calculated values, conditional formatting and dynamic text. Diagram elements use them for status indicators, calculated displays and conditional visibility. Virtual Variables use them to define a computed data point from existing Variables.
Syntax
An expression combines Variable references, literals, operators and function calls:
{{variable1}} + {{variable2}} * 2
Variables
Reference a Device Variable by wrapping its identifier in double curly braces:
Variable Syntax
{{deviceId.variableId}}
Variable Types
- Number: Numeric values that support mathematical operations
- String: Text values that can be concatenated and compared
- Boolean: True/false values for logical operations
Operators
Arithmetic Operators
| Operator | Description | Example |
|---|---|---|
+ | Addition | {{temp1}} + {{temp2}} |
- | Subtraction | {{temp1}} - {{temp2}} |
* | Multiplication | {{power}} * 1.5 |
/ | Division | {{total}} / {{count}} |
% | Remainder | {{value}} % 10 |
^ | Exponentiation | {{base}} ^ 2 |
Comparison Operators
| Operator | Description | Example |
|---|---|---|
== | Equal to | {{status}} == "online" |
!= | Not equal to | {{status}} != "offline" |
< | Less than | {{temp}} < 75 |
<= | Less than or equal | {{temp}} <= 75 |
> | Greater than | {{temp}} > 85 |
>= | Greater than or equal | {{temp}} >= 85 |
Logical Operators
| Operator | Description | Example |
|---|---|---|
and | Logical AND | {{temp}} > 70 and {{temp}} < 90 |
or | Logical OR | {{status}} == "alarm" or {{status}} == "warning" |
not | Logical NOT | not {{maintenance}} |
Unary Operators
| Operator | Description | Example |
|---|---|---|
- | Negation | -{{value}} |
+ | Positive | +{{value}} |
abs | Absolute value | abs {{difference}} |
sqrt | Square root | sqrt {{area}} |
ceil | Round up | ceil {{value}} |
floor | Round down | floor {{value}} |
Mathematical Functions
Basic Math Functions
min(a, b, ...)- Returns the smallest valuemax(a, b, ...)- Returns the largest valuepow(base, exponent)- Raises base to the power of exponentrandom()- Returns a random number between 0 and 1
Trigonometric Functions
sin(x)- Sine functioncos(x)- Cosine functiontan(x)- Tangent functionasin(x)- Arcsine functionacos(x)- Arccosine functionatan(x)- Arctangent functionatan2(y, x)- Two-argument arctangent
Logarithmic Functions
ln(x)- Natural logarithmlog(x)- Natural logarithm (alias for ln)log10(x)- Base-10 logarithm
Utility Functions
round(x)- Rounds to nearest integersign(x)- Returns -1, 0, or 1 based on signhypot(a, b, ...)- Euclidean distance (hypotenuse)
Logical Functions
Conditional Function
The if function provides conditional logic:
if(condition, value_if_true, value_if_false)
Examples:
if({{temperature}} > 80, "Hot", "Normal")
if({{status}} == "online", 1, 0)
if({{power}} > 100, {{power}} * 0.9, {{power}})
Ternary Operator
You can also use the ternary conditional operator:
{{temperature}} > 80 ? "Hot" : "Normal"
Array Functions
These functions operate on array values:
Array Operations
map(array, expression)- Transform each elementfilter(array, condition)- Filter elements by conditionfold(array, initial, expression)- Reduce array to single valueindexOf(array, value)- Find index of valuejoin(array, separator)- Join array elements into stringlength(array)- Get array length
Constants
The following constants are available in every expression:
Mathematical Constants
PI- π (3.14159...)E- Euler's number (2.71828...)
Boolean Constants
true- Boolean true valuefalse- Boolean false value
Best Practices
Performance
- Keep expressions simple when possible
- Avoid complex nested calculations in frequently updated components
- Use parentheses to clarify operator precedence
Readability
- Use descriptive variable names
- Break complex expressions into multiple simpler ones
- Add comments in dashboard configurations to explain complex logic
Error Handling
- Test expressions with edge cases (null values, zero division)
- Use conditional checks before mathematical operations
- Provide fallback values for unreliable data sources
Examples
Temperature Monitoring
// Temperature status indicator
if({{sensor.temperature}} > 85, "Critical",
if({{sensor.temperature}} > 75, "Warning", "Normal"))
// Temperature in Fahrenheit from Celsius
{{sensor.tempC}} * 9/5 + 32
Power Calculations
// Power efficiency percentage
({{generator.actualPower}} / {{generator.ratedPower}}) * 100
// Total power consumption
{{load1.power}} + {{load2.power}} + {{load3.power}}
// Power factor calculation
{{realPower}} / sqrt({{realPower}}^2 + {{reactivePower}}^2)
Status Logic
// System health indicator
if({{device.online}} and {{device.errors}} == 0, "Healthy",
if({{device.online}}, "Degraded", "Offline"))
// Alarm condition
{{temperature}} > 90 or {{pressure}} > 150 or not {{safety.ok}}
Time-based Calculations
// Runtime hours from milliseconds
{{runtime.totalMs}} / (1000 * 60 * 60)
// Efficiency over time
{{totalOutput}} / {{totalInput}} * 100
Complex Conditional Logic
// Multi-tier alarm severity
if({{criticalAlarms}} > 0, "Critical",
if({{majorAlarms}} > 0, "Major",
if({{minorAlarms}} > 0, "Minor", "Normal")))
// Load balancing calculation
if({{load}} > {{capacity}} * 0.8,
"Reduce Load",
if({{load}} < {{capacity}} * 0.3, "Increase Load", "Optimal"))