Skip to content

Expressions

An Expression is a shared JavaScript formula defined at the space level. It can be referenced by multiple variables or alarms. This enables centralized management of recurring formulas.

Expressions

Menu: Development → Expressions → New Expression

FieldRequiredDescription
NameYesFormula name (unique within the space)
CodeYesJavaScript code
DescriptionNoDescription

Expressions are used for two different purposes:

Used to calculate a variable’s value. Runs on every read cycle.

TypeDescription
NONENo expression, raw value is used
CUSTOMInline JavaScript specific to the variable
REFERENCEReference to a shared Expression

When REFERENCE is selected, the Expression name is specified in the variable definition. This allows the same formula to be used across dozens of variables.

A custom condition that determines when a variable is logged. If it returns true, the value is logged; if false, it is skipped.

// Only log if value is within a specific range
if (value > 100 && value < 900) {
return true;
}
return false;
// Fahrenheit → Celsius (used across multiple temperature sensors)
return ((value - 32) * 5 / 9).toFixed(1) * 1;
// Convert 0-65535 raw value to 0-100 percentage
return (value / 65535 * 100).toFixed(1) * 1;
// Convert numeric status code to text
var states = {0: "Stopped", 1: "Running", 2: "Fault", 3: "Maintenance"};
return states[value] || "Unknown";

Since Expressions are defined at the space level:

  • When you modify a formula, all variables using it are automatically updated
  • Variables in different projects can share the same formula
  • You can create a formula library to define standard conversions