How conditions work in Apilio

conditions
conditionals
variables
How conditions work in Apilio
0

#1

Apilio’s conditions are one of the most important parts when it comes to building your automation.

Usually smart home applications allow you to automate actions as a result of an event. But what happens when you only want to activate a specific action in a specific situation? You need to define a more sophisticated condition and this is where Apilio comes in.

Three different types of conditions

Whenever you want to run an automation in Apilio, a logicblock will be triggered for evaluation. Before the logicblock says it’s ok to run the actions, it will check that the specific conditions are met. This means, we are in that specific situation when we want to run our actions.

Conditions can only be either true or false, and are evaluated depending on the type of variable the condition is watching. Since we have three types of variables in Apilio, you can have:

  • Boolean variable conditions
  • String variable conditions
  • Numeric variable conditions

Let’s have a look in detail to understand how Apilio determines the result depending on the variable type:

  • A boolean variable condition will check if a boolean variable is true or false. For example, the boolean variable ‘Nighttime’ can only be true or false, and if we have a condition to check whether it is nighttime, this condition can only result in true (when it is nighttime) or false (during daytime).

  • A string variable condition is determined by comparing a string to a reference string that you must define. You can check whether your string variable contains or does not contain your reference string:
    • If we have a condition to check if a string contains a specific reference string, the condition will be true when the string contains the reference and will be false when it does not. For example, each day we can receive the weather forecast for the day and if we want to check whether the weather today will be humid, we could check if forecast is contained in the string ‘Snow, Rain, Fog’. If the weather is ‘Fog’, this string is contained within the reference string and as a result, the condition is true.
    • If we have a condition to check if a string does not contain a specific reference string, the condition will be true when the string does not contain the reference, and it will be false when the string does contain the reference string.

  • A numeric variable condition is determined by comparing a numeric variable to a numeric reference. The numeric variable can either be equal to, greater than, greater or equal than, less than, less or equal than the secondary numeric variable to check whether if the condition is true of false, just like we just did for string variable conditions.

Time Constraints for conditions in Apilio

When you are setting up any of these conditions, you can optionally add time constraints. This allows you to check how recent the information in a variable is:

  • Use “Unmodified since” to ensure your variable has not changed for a while. If active, Apilio will check update timestamp of the variable and the condition will only be true if your variable has been unmodified for X seconds.
    • This is very useful when you have a variable that can change frequently but that you only care about changes that remain for a certain amount of time.
    • For example, let’s have a variable that stores whether you are connected to your home WiFi. As your connection can drop off sometimes, it is safer to specify a time here, for example, 5 minutes (5*60 = 300 seconds), so that your condition will only count as true after you have been disconnected from the Wifi for at least 5 minutes, to indicate that you are no longer home.
  • Use “Modified within” to ensure the data is fresh: you can check if the value stored in your variable is recent, by setting up a time here. The condition will only be true if the variable has been modified within X seconds.
    • This comes in handy when you have a variable that you might not be resetting back to a base level, but that you are only interested in the value if it has changed recently.
    • For example, you could have a ‘daytime’ variable that is set to true at sunrise. Instead of setting it to false at sunset, you can just check if the value (true) has been stored in the last few hours.

It’s also important to note that Apilio does not currently automatically trigger a re-evaluation when time passes: you must setup an external trigger to do this. If your setup uses for example a logicblock that is evaluated when a connected variable changes, as we have seen with these timing examples above, a variable can remain set to true forever, but the data might have been re-written recently. The condition changing because of the timing conditions does not trigger the logicblock evaluation: the logicblock is watching the variable value, and the variable value has not changed. The timing restriction you have defined is used when checking the conditions in the logicblock to decide whether the action(s) should be run.

Let us know if you are using any of these below, and if you have any tricks of the (Apilio) trade! How are you using these time constraints?


Updating numeric variables via IFTTT
Last modification
Getting started - an introduction to Apilio
Complex condition linking
#2

It’s unmodified since and modified within, not how you describe it.


#3

Thanks for spotting this, we’ll do a quick - ahem - edit.


#4

Thanks a lot! :slight_smile: This is now fixed