View as Markdown

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.

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

OperatorDescriptionExample
+Addition{{temp1}} + {{temp2}}
-Subtraction{{temp1}} - {{temp2}}
*Multiplication{{power}} * 1.5
/Division{{total}} / {{count}}
%Remainder{{value}} % 10
^Exponentiation{{base}} ^ 2

Comparison Operators

OperatorDescriptionExample
==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

OperatorDescriptionExample
andLogical AND{{temp}} > 70 and {{temp}} < 90
orLogical OR{{status}} == "alarm" or {{status}} == "warning"
notLogical NOTnot {{maintenance}}

Unary Operators

OperatorDescriptionExample
-Negation-{{value}}
+Positive+{{value}}
absAbsolute valueabs {{difference}}
sqrtSquare rootsqrt {{area}}
ceilRound upceil {{value}}
floorRound downfloor {{value}}

Mathematical Functions

Basic Math Functions

  • min(a, b, ...) - Returns the smallest value
  • max(a, b, ...) - Returns the largest value
  • pow(base, exponent) - Raises base to the power of exponent
  • random() - Returns a random number between 0 and 1

Trigonometric Functions

  • sin(x) - Sine function
  • cos(x) - Cosine function
  • tan(x) - Tangent function
  • asin(x) - Arcsine function
  • acos(x) - Arccosine function
  • atan(x) - Arctangent function
  • atan2(y, x) - Two-argument arctangent

Logarithmic Functions

  • ln(x) - Natural logarithm
  • log(x) - Natural logarithm (alias for ln)
  • log10(x) - Base-10 logarithm

Utility Functions

  • round(x) - Rounds to nearest integer
  • sign(x) - Returns -1, 0, or 1 based on sign
  • hypot(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 element
  • filter(array, condition) - Filter elements by condition
  • fold(array, initial, expression) - Reduce array to single value
  • indexOf(array, value) - Find index of value
  • join(array, separator) - Join array elements into string
  • length(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 value
  • false - 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"))

Was this page helpful?