This article explains 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 and Essential knowledge for configuring scripts.

The calculation consists of references to the aliases of the sensors added in the sensor list in 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 operators mentioned below.

 

Between two values

Operator

Description

Example 1

Example 2

+ plus 10.5 + 20 S1[t] + S2[t]
- minus 10.5 - 20 S1[t] - S2[t]
* multiplication 10.5 * 20 S1[t] * S2[t]
/ division 10.5 / 20 S1[t] / S2[t]
% modulo 10.5 % 20 S1[t] % S2[t]

^

power

10.5^2

S1[t]^2

== equals 10.5 == 20 S1[t] == S2[t]
!= not-equals 10.5 != 20 S1[t] != S2[t]
greater-than 10.5 > 20 S1[t] > S2[t]
>= greater-or-equal 10.5 >= 20 S1[t] >= S2[t]
less-than 10.5 < 20 S1[t] < S2[t]
<= less-than-or-equal 10.5 <= 20 S1[t] <= S2[t]
&& and (10.5 <= 20) && (20 < 30) ( S1[t] <= S2[t] ) && ( S1[t] > 0 )
|| or (10.5 <= 20) || (20 < 30) ( S1[t] <= S2[t] ) || ( S1[t] > 0 )

 

For one value/expression

Operator

Description

Example 1

Example 2

sum

the sum of all values

sum(10.5)

sum(S1[t-2,t])

avg

the average of all values

avg(10.5)

avg(S1(t-2,t])

max

the max of all values

max(10.5)

max(S1[t-2,t])

count

the number of values

count(10.5)

count(S1[t-2,t])

sumif

the sum of values that meet the condition

sumif(10.5, 10.5 < 12)

sumif(S1[t-2,t], S1[t-2,t] > 10)

countif

the count of values that meet the condition

countif(10.5, 10.5 < 12)

countif(S1[t-2,t], S1[t-2,t] > 10)

tan

the tangent of the value in degrees

tan(10.5)

tan(S1[t])

sin

the sine of the value in degrees

sin(10.5)

sin(S1[t])

cos

the cosine of the value in degrees

cos(10.5)

cos(S1[t])

atan

the arctangent in degrees of the value

atan(10.5)

atan(S1[t])

asin

the arcsine in degrees of the value

asin(10.5)

asin(S1[t])

acos

the arccosine in degrees of the value

acos(10.5)

acos(S1[t])

abs

the absolute of the value

abs(10.5)

abs(S1[t])

e^

power of e

e^(10.5)

e^(S1[t])

ln

natural logarithm

ln(10.5)

ln(S1[t])

10^

power of 10

10^(10.5)

10^(S1[t])

10log

decimal logarithm

10log(10.5)

10log(S1[t])

round

round to nearest integer

round(10.5)

round(S1[t])

floor

round to nearest integer at of below below input

floor(10.5)

floor(S1[t])

ceiling

round to nearest integer at or above input

ceiling(10.5)

ceiling(S1[t])

sqrt

square root (√)

sqrt(10.5)

sqrt(S1[t])

 

Functions

Operator

Description

Example 1

Example 2

random

random floating point value in given range

random(10.5, 20)

-

lasttime

unix timestamp (seconds) of last known occurrence of a value change to given value for given sensor

 

returns 0 if no matching value is found within a 2 week period

-

lasttime(S1, 10.5)

lasttimebetween

unix timestamp (seconds) of last known occurrence of a value change to value within given range for given sensor

 

returns 0 if no matching value is found within a 2 week period

-

lasttimebetween(S1, 10.5, 20)

duration

number of seconds the given value held uninterrupted at its last known occurrence

 

returns 0 if no matching value is found within a 2 week period

returns a value between 0 and the true duration if the last occurrence of a change to the given value took place more than 2 weeks ago and the period when the value held uninterrupted ended less than 2 weeks ago

-

duration(S1, 10)

now

returns the unix timestamp (seconds) of the script execution target time

 

the timestamp will always be equal to the timestamp any output values of this script execution are assigned to

 

this function takes no arguments

now()
now()

 

Control Flow Statements

Statement

Description

Example

if(…) { … }

if statement, only execute code within ‘{' and ‘}’ when the code between ‘(’ and ')’ resolves to boolean true

if ( S1[t] < 0 )
{ S2[t] = 1 }

if(…) { … } else { … }

if-else statement, only execute code within first ‘{' and ‘}’ block when the code between ‘(' and ‘)’ resolves to boolean true, else execute code in second ‘{’ and '}’ block

if ( S1[t] < 0 )
{ S2[t] = 1 }
else
{ S2[t] = 0 }

if (…) { … } else if (…) { … } …

if-else-if statement, couple multiple if statements in sequence; will not evaluate subsequent if conditions when a former if condition evaluated to boolean true; optional final else statement

if ( S1[t] < 0 )
{ S2[t] = 1 }
else if ( S3[t] == 10 )
{ S2[t] = 0 }
else { S2[t] = 2 }

 

Special operators

Operator

Description

Example

//

comment; any characters following the comment operator up to a new line are ignored

if ( IN[t] == 0 ) {
// your code goes here
} // end of the if statement

=

 

assignment; assign a numeric value to a sensor or a local variable

 

an assignment to a sensor requires the sensor alias to be formatted as described above and only accepts "[t]", e.g. assignments to aliases with "[t-1]", "[t-3]", or similar will not be accepted

 

local variable names can be defined according to the grammar outlined below and are instantiated at script execution and lost immediately after execution completion, i.e. local variables are not stored or otherwise persisted

OUT[t] = 10

 

OUT[t] = IN[t-2]

 

myvar = 10

 

myvar = IN[t-2]

 

OUT[t] = myvar

 

Grammar Rules

  • Statements and operators are case-sensitive.

  • Local variables are declared by assigning a value to the new variable, e.g. myvar = 10.

  • Sensor aliases or local variable names:

    • must start with a letter

    • can only contain letters (in either case), numbers, or "_" (underscore)
    • cannot collide with any reserved words (above), regardless of case

  • Whitespaces and new lines can be used at will.

  • Use parentheses to group operations and give precedence, e.g. (2 + 10) * 10.

 

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