If-Then-Else Statements
If, Then, Else actions are used to implement conditional logic in a Routine. This action creates two branches in the Routine logic, as shown in the screenshot below:
All the actions in the left branch are executed if the condition stored in the action passes, and all those in the right branch are executed if the condition fails. There are five different types of conditions that a user can input:
- If Expression Has A Value…: A user inputs an EL expression and a desired value; if the expression evaluates to the value, the condition passes. This is tyically used to test when the result of teh expression is a text value
- If Result Of Expression…: A user inputs an EL expression; if the expression evaluates to true, the condition passes.
- If Result Of Expression Matches A Pattern…: A user inputs an EL expression and a REGEX pattern; if the expression evaluates to a string matching the pattern, the condition passes.
- If A Variable Is Defined…: A user inputs the name of a variable. If a variable with that name has been defined up to that point in the Routine (usually with the Find Action), the condition passes.
- If Collection Is Not Empty…: A user inputs the name of a collection. If that collection is not empty, the condition passes.
EL expressions are covered in detail on the EL Tutorial page, but some example expressions that can be used inside statements 1-3 are:
- ${n:time_formatted(message.time, 'EEE', 'US/Pacific') == 'Sat'}
- ${message.sensor_value < source.our_value and source.flag}