Condition Syntax
Telemetry trigger conditions are written like logical statements that are to be evaluated, but without the common “if/then” syntax. The conditions can be complex, including and/or logic, and nested parenthesis.
There is a lot of information below because you can do some quite sophisticated things in triggers. To help you find your way, here’s a handy index (with links):
Class | Subclass | A Few Examples |
---|---|---|
Operands | Literal | Booleans, integers, floats |
Telemetry | event.code, metric.value, status.name | |
Devices | device.id, device.tags["tag_name"] | |
Operators | Arithmetic | + - * / |
Comparison | == != < > <= >= | |
Logical | and, or, not | |
String | contains, startswith, endswith |
To help guide you, there are some condition examples here.
The syntax can be quite complicated and, in fact, there are very additional built-in commands not described in this page. maiLink leverages a 3rd party libary for expression resolution in condition syntax evaluation. The details shown above represent the core features of the condition syntax. There are, however, further ways to construct conditions. maiData has neither used nor tested the additional methods that you can find described at antonmedv’s GitHub page at Expr Library Documentation.
Operands
Conditions are logical statements comprised of operands and operators. The operands allow you to test telemetry messages that are received. They also allow testing of other information about the device.
Literal Operands
Type | Description | Example |
---|---|---|
Boolean | One of: true, false | false |
Integer | An integer value. | 55.3 |
Float | A floating point value. | 55.3 |
String | ASCII characters enclosed in single or double quotes (' ' or " “). | “motor_rpm” |
Array | A list of literal operand values enclosed in square brackets. | [1, 2, 3] |
Range | An inclusive range of integers | 4..45 |
Operands From Telemetry Messages
Operand | Type | Description |
---|---|---|
event.code | string | The code of the event. |
event.text | string | A text blurb that describes the the event. |
event.severity | number | The severity level of the event. |
metric.label | string | The identifier of the metric. |
metric.value | number | The value of the metric. |
status.name | string | The identifier of the status. |
status.value | string | The value of the status. |
Operands From Device Information
Operand | Type | Description |
---|---|---|
device.id | string | The id of the device. This may be useful with the “contains”, “startswith” or “endswith” string operators. |
device.name | string | The name of the device. This may be useful with the “contains”, “startswith” or “endswith” string operators. |
device.status["status_name"] | string | The most recently received status value of status telemetry “status_name”. |
device.tags["tag_name"] | string | The current value of device tag “tag_name”. |
device.type | string | The device model (also known as device type) is defined for the workflow, so is probably not needed as an operand. |
Operators
Arithmetic Operators
maiLink workflows support common arithmetic operators in condition statements:
Operator | Description | Example |
---|---|---|
+ | Addition | metric.value * 3 |
- | Subtraction | metric.value - 3 |
* | Multiplication | metric.value * 3 |
/ | Division | metric.value / 3 |
% | Modulus | metric.value % 3 |
^ or ** | Exponent | metric.value ^ 3 |
Comparison Operators
maiLink workflows support common comparison operators in condition statements:
Operator | Description | Example |
---|---|---|
== | Tests if the values of two operands are equal or not; if yes, the condition becomes true. | event.code == “E1003” |
!= | Tests if the values of two operands are equal or not; if the values are not equal, then the condition becomes true. | status.label != “sw_version” |
< | Tests if the value of left operand is less than the value of the right operand; if yes, the condition becomes true. Intended for metric messages because it is a numeric test. | metric.value < 55 |
> | Tests if the value of left operand is greater than the value of right operand; if yes, the condition becomes true. Intended for metric messages because it is a numeric test. | metric.value > 55 |
<= | Tests if the value of left operand is less than or equal to the value of right operand; if yes, the condition becomes true. Intended for metric messages because it is a numeric test. | metric.value <= 55 |
>= | Tests if the value of the left operand is greater than or equal to the value of the right operand; if yes, the condition becomes true. Intended for metric messages because it is a numeric test. | metric.value >= 55 |
in | Tests if the first operand is an integer within the range of values specified by second operand. | metric.value in 33..166 |
Logical Operators
maiLink workflows support common comparison operators in condition statements:
Operator | Description | Example |
---|---|---|
not or ! | Logical NOT operator. | not (event.code == “E1003”) |
and or && | Logical AND operator. | (event.code == “E1003”) and (event.severity > 50) |
or or || | Logical OR operator. | (event.code == “E1003”) and (event.severity > 50) |
not | Logical NOT operator. | not (event.code == “E1003”) |
String Operators
maiLink workflows support the common string operators in condition statements:
Operator | Description | Example |
---|---|---|
contains | Tests if first operand contains the second operand in its entirety, with identical case. | event.code contains “E10” |
endswith | Tests if end of the second operand is the exact ending of the second operand, with identical case. | metric.label endswith “_rpm” |
in | Tests if the first operand equals an element in an array of strings, with identical case. | status.name in [“SWversion”,“SWoriginal”] |
matches | Tests if the value of first operand is matches the regular expression given as the second operand | event.code matches “^.*_rpm_.*” |
startswith | Tests if end of the second operand is the exact beginning of the first operand , with identical case. | metric.label startswith “airlock_” |
Condition Syntax Examples
These examples show some more complicated types of condition syntaxes.
Type | Example Condition |
---|---|
Event | event.code == “E1003” |
Event | event.code == “E0113” and device.tags[“contract”] in [“Warranty”,“Expired”] |
Event | event.code == “E1003” or event.code == ”E1388” |
Event | event.code in [“E1003”,”E1388”] |
Event | event.code matches “^E1[0-9][0-9][0-9]$” |
Metric | metric.label == “motor_rpm” and metric.value < 55 |
Metric | metric.label == “motor_rpm” and metric.value < 55 and metric.value > 33 |
Metric | metric.label == “motor_rpm” and metric.value < 55 and device.tags[“motor size”] == ”small” |
Status | status.name == “version” and status.value == “1.3.2” |
Status | Status.name == ”version” and status.value != device.tags[“RequiredVersion”] |