Robin includes two alternatives with which you may set the automations to decide the flow depending on set rules.
Using the If - else model, you may set a predefined condition under which a set of actions will be performed.
In the example below, the first set of actions will be executed when variable i is true. The second set of actions will be executed in case the variable is false. There is a third set of actions that will be performed if variables’s i value is anything else.
Note that the if statement always need to be followed by the then statement.
if i = 'true' then # Steps to perform if i is true set var to 1 else if i ='false' then # Steps to perform if i is false set var to 2 else # Steps to perform if i has any other value set var to 3 end
Note that any action which provides a boolean variable result can be used within an if conditional using parenthesis ().
In the example below, the file exists action is used.
if(file.Exists File: "C:\file.txt") then # Steps to perform if file.txt exists set filevar to 1 else set filevar to 2 # Steps to perform if file.txt does not end
In order to close the conditional block, the “end” statement is required.
The list below includes the actions that may be used withtin a conditional block. All these actions, measure if the set case is true or false.
Note that in case a conditional block contains both “Else” and “Else if”, the “Else” statement always need to be the last.
In cases that more than one conditions need to be met, nested conditions can be used.
In the example below, the automation monitors if the “NumVar” is bigger than 0 and smaller than 10.
if NumVar > 0 then if NumVar < 10 then # Steps to perform if NumVar is between 0 and 10 set checkNumVar to true end end
The above can also be achieved using the two conditions in one line.
if NumVar > 0 and NumVar < 10 then # Steps to perform if NumVar is between 0 and 10 set checkNumVar2 to 0 end
The above example uses the “AND” operator. Of course, this applies for all the logical operators.
Using the “OR” operator, at least one of the conditions needs to be met.
if NumVar > 0 or NumVar < 10 then # Steps to perform if NumVar is bigger than 0 or smaller than 10 set checkNumVar3 to 0 end
Using the “XOR” operator, one of the conditions needs to not be met.
if NumVar > 0 xor NumVar < 10 then # Steps to perform if NumVar is not bigger than 0 or smaller than 10 set checkNumVar4 to 0 end
Logical Operators are thoroughly explained in the respective topic.
The alternative way to use conditions, is using the “Switch - Case” model.
In the switch - case model you need to set the variable which is calculated, and then set the actions to be performed for each case.
In the example below, the day of week is checked if it is a Weekend and accordingly the automation steps are performed.
switch CurrentDateTime.DayofWeek case = 'Saturday' # Steps to perform during the weekend set DayofWeekVar to 'Weekend_d1' case = 'Sunday' # Steps to perform during the weekend set DayofWeekVar to 'Weekend_d2' default set DayofWeekVar to 'Weekday' # Steps to perform during the weekdays end
A switch statement can have an optional default case, which must appear at the end of the switch. The default case can be used for executing particular actions when none of the cases are true. When the variable being switched on is equal to a case, the statements of that case will execute and all the following cases will be ignored.
As in the “If - else” model, the condition block needs to be closed using the “end” statement.