Remember that a condition in Apilio can only be true or false. If you want to know more about how these work, this article will help.
We will first see how these operators work, review the simple and complex condition and then give you some ideas for bringing your Apilio setups to the next level!
How the logic operators work
Operator names, such as AND and OR are usually written capitalised.
How the logic operator AND works
The AND operator will check if all of the conditions are true and, if they are, return true.
For example:
If Iām home AND my partner is home, then turn on the heater to comfort temperature.
- If Iām home but my partner is not, the heater will not turn on to comfort temperature
- The same will happen if my partner is home but Iām not.
- Only if both of us are home (both those conditions are true), then the heater will be turned on to that temperature.
How the logic operator OR works
The OR operator will check if any of the conditions are true and, in that case, return true.
If we continue with the previous example, maybe I want to turn on the heater to comfort temperature if either Iām home, or my partner is home, or if both of us are home. This is the perfect situation to use the OR operator! Our previous automation would now be the following:
If Iām home OR my partner is home, then turn on the heater to comfort temperature.
- If Iām home but my partner is not, the heater will turn on to comfort temperature
- The same will happen if my partner is home but Iām not.
- And also if both of us are home (both those conditions are true), then the heater will be turned on to that temperature.
This is perfect for keeping both of us toasty warm!
How the logic operator XOR works
This has been implemented following Microsoftās specification for XOR: https://support.microsoft.com/en-us/office/xor-function-1548d4c2-5e47-4f77-9a92-0533bba14f37
The operator XOR:
- results in TRUE when the number of TRUE conditions is odd
- results in FALSE when the number of TRUE conditions is even
So if you have three conditions (odd number) and all of them are true, XOR returns true. But if you only have two conditions (even number), then XOR returns false.
How the logic operator NOR works
NOR results in TRUE if all the conditions are false.
NOR(i_m_home, robin_is_home) returns true when nobody is at home.
NOR is just the opposite of the basic operator OR:
NOR() = NOT(OR())
How the logic operator NAND works
NAND results in TRUE if, and only if, at least one of the conditions is false.
NAND(watered_yesterday, rain_yesterday) will be true if either:
- the plants were watered yesterday and it didnāt rain
- it rained but the plantās didnāt get watered
NAND is just the opposite of the basic operator AND:
NAND = NOT(AND())
But I really want the NOT operator
Good news is NOR and NAND work exactly like NOT() if only used with one element. So if you apply NOR to one condition, youāll get the opposite, making these equivalent to NOT.
How to implement simple and complex conditions in Apilio
In general, the syntax that Apilio uses is similar to the one used in Microsoft Excel products (you can read Microsoft Help articles for AND, OR, XOR).
Simple āANDā Condition Linking
Letās imagine we have setup three conditions: to check if is nighttime, and if Abbie and Bob are, respectively, home. When I create a new logicblock I will see all the available conditions I can choose from, and I can select as condition linking either Simple or Complex.
Conditions are linked together in Logicblocks. In most scenarios, the easy āANDā-linking of conditions is the way to go ā all conditions must be true in order to get a positive result. This can be translated into a sentence like:
IF itās nighttime AND Bob is home AND Abbie is home THEN turn on the heater to comfort temperature
When all of these are true, then the actions for a positive result will run and we will switch on the lights. But this means that Bob will freeze when Abbie is not home at night as the heater will not switch on! And the same will happen when Abbie is alone. Fortunately, we can fix this with some condition linking.
Complex Condition Linking
As we have just seen, the simple AND might not be enough to create your, hereās when the complex condition becomes super useful!
With Apilioās complex condition linking you can:
- Use the OR operator instead of, or in combination with, the AND operator
- Create nested expressions
For example, you could write:
- AND(condition_1,condition_2,condition3). This is equivalent to the simple condition linking.
- OR(condition_1,condition_2,condition3) will return true if any of the 3 conditions is true
- AND(condition_1,OR(condition_2,condition_3)) will return true if condition 1 and either 2 or 3 (or both!) are true.
To improve the earlier example, you can automate a scenario like this:
IF itās nighttime AND (Bob OR Abbie are home) THEN turn on the heater to comfort temperature
You can switch to Complex Condition Linking by selecting the option on any Logicblock. Hereās what it looks like in Apilio:
As you can see, our complex condition is using both AND and OR operators:
AND(it_is_nighttime,OR(is_bob_home,is_abbie_home))
Make sure that you check the box for any relevant condition youād like to use from your listed conditions.
Apilio will parse your condition linking statement on save and will give you an error message in case it cannot match a condition name from your expression with a linked condition!
Example with complex nested conditions
This is a great example from one of our users:
OR(alarm_status_enabled,AND(OR(all_away,alarm_is_scheduled),alarm_status_not_disabled))
Letās imagine that we have a logicblock that is our home security system, and that if evaluated positively, it will run a series of actions such as locking doors, rolling down blinds, turning on a radio, enabling a movement sensor in the backyard, and so on.
Letās unpack what this nested condition does:
This logicblock will run my actions to activate all my home security systems either if my alarm is enabled or in the three following situations:
- The whole family is away and the alarm is not disabled
- The alarm is scheduled to be on and the alarm is not disabled
- The whole family is away and the alarm is scheduled to be on and the alarm is not currently disabled
With this complex condition, Apilio takes care of enabling all the home security system so the family can be certain that even a forgetful member of the family leaves the house empty without enabling the alarm, the security systems will still be enabled.