0.60

ReferenceChannelsCalculated channels

Calculated channels

Compute values from other channels with an Arc expression.

A calculated channel computes its values from other channels with an Arc expression. Use a calculated channel to:

  • Scale or convert a sensor value, such as volts to pressure.
  • Combine sensors, such as the pressure drop across a filter.
  • Compare redundant sensors.
  • Set a flag when a condition is true, for alarms and warnings.

How calculated channels work

Synnax does not store the values of a calculated channel. It computes them when you stream or read the channel, and it stops when nothing uses the channel.

  • Past data -> you can read a calculated channel over a past time range. Synnax computes the values from the stored data of the inputs, so each input must have data in that range.
  • Edits -> because Synnax stores no values, an edit also changes all past data. If you change pressure * 3 to pressure * 10, all of the data shows pressure * 10.
  • Samples -> the expression runs once for each new sample of any input, after every input has at least one sample. Each channel name gives one value, and an input with no new sample gives its last value.
  • Data type -> Synnax gets the data type from the value that the expression returns. return 1 gives an int64 channel, and return 1.0 gives a float64 channel.
  • Index -> Synnax creates a virtual index channel named <name>_time for each calculated channel.
  • Chains -> a calculated channel can use other calculated channels as inputs. A chain cannot loop back to itself.

Create a calculated channel

Enterprise
  1. Click the create calculated channel button in the channels toolbar, or run the “Create calculated channel” command in the command palette.
  2. Enter a name.
  3. Write the expression.
  4. Optional: select an operation. For Min, Max, and Average, you can also set a Window and a Reset channel.
  5. Click Create.

Edit a calculated channel

Enterprise

Right-click the channel in the channels toolbar and select Edit calculation. Change the name, the expression, or the operation, then click Save.

Write an expression

An expression is the body of an Arc function. Refer to channels by name, and return the value of the calculated channel. An expression can have many statements.

drop := inlet_pressure - outlet_pressure
return drop * 0.0689

Use an if statement to set a flag:

if tank_pressure > 500.0 {
    return 1
}
return 0
Use case Expression
Scale a sensor return pressure_volts * 250.0
Convert Celsius to Kelvin return temperature + 273.15
Power return voltage * current
Average of three sensors return (temp_1 + temp_2 + temp_3) / 3.0
Pressure drop return inlet_pressure - outlet_pressure

The Arc reference describes operators, variables, and if statements.

Use inputs that share an index

Synnax pairs the samples of the input channels in the order that they arrive. It does not match them by time. When the inputs share an index, each pair of samples has the same timestamp. When the inputs have different indexes, a pair can have samples from different times. For correct results, use inputs that share an index.

Operations

An operation keeps a value across many samples, such as the maximum since a reset. It applies to the result of the expression.

Input channels
Expression
Reset channel
Operation
Output channel
Input channels
Expression
Reset channel
Operation
Output channel
Operation Output
min The smallest value since the last reset.
max The largest value since the last reset.
avg The mean of all values since the last reset.
derivative The rate of change per second. The data type is always float64.

min, max, and avg give one output sample for each group of input samples that Synnax receives, not one for each input sample. They reset in two ways:

  • Window -> the operation resets at the end of each window. A 10-second window gives the average of each 10-second period, not a moving average, and a window of 0 never resets.
  • Reset channel -> the operation resets when a boolean reset channel receives true. A schematic button or an Arc automation can write to the reset channel.

derivative has no window and no reset channel.

Reset example

A max operation on tank_pressure, with a reset channel. Each line is one group of input samples:

Time tank_pressure max output
0 s 50 50
5 s 100 100
10 s 75 100
10.1 s (reset = true) 75 75
15 s 90 90
20 s 110 110

At 10.1 s, the reset channel receives true, and the maximum resets. The operation starts again from the current value, 75.

Operation examples

Use case type duration Reset channel
Average of each 10-second period avg 10s None
Maximum until a button press max 0s reset_max_cmd
Minimum of each cycle min 0s cycle_complete
Rate of change derivative None None

When you read past data, Synnax receives the samples in different groups than it did live. The output of min, max, and avg can then be different from the live output.

Troubleshooting

Calculated channel properties lists each property that you can set.