The script language

This article explains how to write a script using the script language. If you are looking for information about how to navigate around the script editor page, it is suggested you read Using the script editor and to take a look at the script examples.

The calculation consists of references to the aliases of the sensors added in the sensor list at the left side of the screen, coupled with a reference to the time "[t]" (time is always related to the sensor frequency, so if you have an sensor with a frequency of 10 seconds, 't-3' means current time minus 30 seconds ago). and the equation, defined by the following operators:

Between two values:

For example:  2 + 3,   5 < 7

  • plus = "+"
  • minus = "-"
  • modulo = "%"
  • multiplication = "*"
  • division = "/"
  • booleanAnd = "&&"
  • booleanOr = "||"
  • equals = "=="
  • notEquals = "!="
  • lessThan = "<"
  • greaterThan = ">"
  • lessOrEqual = "<="
  • greaterOrEqual = ">="

For one value/expression:

For example:  sum(sensor[t-1,t]),   cos(5),    10^(sensor[t])

  • sum = "sum"
  • average = "avg"
  • max = "max"
  • count = "count"
  • sin = "sin"
  • cos = "cos"
  • tan = "tan"
  • asin = "asin"
  • acos = "acos"
  • atan = "atan"
  • abs = "abs"
  • e_exp = "e^"
  • ln = "ln"
  • exp10 = "10^"
  • log10 = "10log"
  • round = "round"
  • floor = "floor"
  • ceil = "ceiling"
  • latch = "latch"
  • sqrt = "sqrt"

More unusual options:

"if(predicate){}" Example:  if(S1[t] < 3) {V1[t] = 6}
"if(predicate){}else{}" Example:  if(S1[t] < 3) {V1[t] = 6} else {V1[t] = S1[t]}
"sumif(value, predicate)" Example:  sumif(S1[t-1,t], S1[t-1,t] >= 80)
“countif(value, predicate)” Example:  countif(S2[t-1,t], S1[t-1,t] != 80)
"lasttime(sensor, value)" * Example:  lasttime(S2, 3)
"lasttimebetween(sensor, value1, value2)" * Example:  lasttime(S2, 3, 1)
"duration(sensor, value)"    Example:  duration(S3, 1)
"random(lowervalue, uppervalue)"  Example:  duration(3.44,5.22)

 

*The operators ‘lasttime’ and ‘lasttimebetween’ will produce a ‘0’ if they find no values.

 

For script examples, refer to the article: Script examples.

Have more questions? Submit a request

Comments