Not sure where to start? This article introduces the concepts and building blocks of Apilio
The four key concepts of Apilio
So, there are four concepts to master in Apilio: Logicblocks , Variables , Conditions and Actions .
Logicblocks evaluate Conditions to determine which Actions the Logicblock makes happen. So for example, “turn on a dehumidifer if the humidity level is above 90%” represents a conceptual Logicblock, “Turn on a dehumidifier” a conceptual Action and “if the humidity level is above 90%” a conceptual Condition of a Numeric Variable, assuming the Numeric Variable contains the humidity level in %.
In most cases, Logicblocks link Conditions with AND logic only but for more complicated operations, complex logic linking can be used:
- Simple Logiblocks will use AND logic only on Conditions
- Complex Logicblocks will use nested combinations of AND/OR logic on Conditions
There are two operating modes for Logicblocks - Standard Operating Mode and Advanced Operating Mode - the mode needs to be set in Advanced Options.
- Standard Operating Mode will normally evaluate Logicblock(s) when a Condition changes, which in turn is normally caused by a change in variable (like a light measurement going above a certain level, or a door being opened, or someone entering a geofenced area)
- Advanced Operating Mode can be set to evaluate the Logicblock when any connected Variable changes OR to trigger the Action only if the Logicblock evaluation result is different
Execution Mode functionality has recently been added to make the Logicblock Action triggering more flexible, allowing for a fixed delay or user-controlled stopping of the Action within a configurable time period of the Logicblock evaluation.
Variables. There are three types of Variable: Numeric, String and Boolean which are normally used as Condition inputs
- Numeric Variable - used to store numbers
- String Variable - used to store text, like “New York”
- Boolean Variable - used to store True/False information
Conditions are applied to a Variable, or number of Variables, to be used within Logicblock expressions. Conditions can only either be in a True of False state but the determination of the Condition differs with the type of variable:
- A Boolean Variable Condition is, by definition, either True or False
- A String Variable Condition is determined by reference to a “String Compare Reference”, set by the user during the Condition configuration (using either a “Contains” or “Does Not Contain” comparison. So, the String Variable Condition is True if the “String Compare Reference” is contained (or not contained) within the String Variable
- A Numeric Variable Condition is determined by referenced to a “Secondary Numeric Variable”. 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 give the True of False Condition
Time constraints may be added to Conditions to ensure the data is fresh. A time can be set within which the Condition must have changed or a within which a Condition must not have changed.
Actions are web service calls, triggered by the Logicblock after evaluation of the Condition/s. An example of an Action would be “turn on a dehumdifier”. Actions are defined on the basis of the Logicblock evaluation and so there will usually be a Action chain resulting: one Action, or series of Actions, for a true (positive) result and an alternate Action, or series of Actions, for a false (negative) result.
There are a number of advanced options available for the Action webhooks calls, dealt with in the following expert-user article.
Putting it all together in an example
So let’s say, for example, we are trying to trigger an Action at first light to determine it’s daytime, by measuring light level from a light sensor (and yes, we could use a time function from IFTTT to provide this input but hey, this is just an example and can be applied to many, many different situations). And then, if it is daytime we will turn off a farmyard light and open the chicken coop door. If it is not daytime then we will turn on a farmyard light and close the chicken coop door.
Breaking this operation down into the Apilio terms referenced above we will use a Logicblock to evaluate a Condition so that an Action is triggered as soon as it’s first light.
We will need to follow some simple steps:
- Create two Numeric Variables as inputs for the Condition evaluation
- Create a Condition to determine if it’s daytime
- Create a Logicblock to evaluate the Condition and trigger some Actions
- First let’s setup a Numeric Variable called currentLightState and a second Numeric Variable called currentLightStateThreshold which we will use to define a level of light above which we consider it to be past first light. Let’s say the light sensor gives an output in lumens and let’s also say the threshold for daylight is 5 lumens.
- We will then create a Condition, called “Daylight” to monitor currentLightState, compare it with currentLightStateThreshold and provide the input for our Logicblock. The Condition is configured to determine if currentLightState is greater than currentLightStateThreshold - if currentLightState is greater than the threshold the Condition is set to true, else it is set to false.
- We then create a Logicblock to evaluate the “Daylight” Condition.
If the Logicblock evaluates the "Daylight Condition to be true then we will trigger the following Actions:
Use a webhook into IFTTT to turn off the LIFX light bulb in the farmyard
Use a webhook into IFTTT to switch on the motor to open the chicken coop door
If the Logicblock evaluates the "Daylight Condition to be false then we will trigger the following Actions:
Use a webhook into IFTTT to turn on the LIFX light bulb in the farmyard
Use a webhook into IFTTT to switch on the motor to close the chicken coop door
It’s a simple example but hopefully provides a good example of what can be achieved with Apilio. As usual, please let us know if you have any comments or questions.