How to setup time constraints for Conditions: delays and timeouts

With Apilio you can add delays and timeouts to some of your Conditions, so you can make your setup smarter:

  • What if you have a presence sensor that only sends the one event when it detects someone, and nothing else? How do you know that nobody is in the room if there is no “idle” event?
  • Or what if you have a sensor that sends lots of false positives. How do you know when it has finally settled on a value?

Apilio is here to help! :robot: :heart:

:point_right: When to add a delay to your Condition

This is useful to prevent any false positives, ensuring you only use information that has not changed for a while.

For example, if you want to track whether your phone is connected to your home wifi. You might want to wait for a few minutes after it disconnects to make sure you have actually left the house and this is not a temporary disconnection from your wifi.

Adding a 5 minute delay to your Condition means that only when your phone has been disconnected from your home wifi for 5 minutes, then you consider your Condition to be true: you are no longer at home.

You could also use this to make sure that your front door has been closed for 20 minutes after you left home, before your alarm is enabled.

:point_right: When to add a timeout to your Condition

This is useful for example for presence sensors, or for any device or service that only has one event to tell you that something has happened. Timeouts ensure that your data is always fresh :baby:

If you only want to consider the information as “current” for example, for 2 minutes after the sensor detected a presence, by adding a timeout Apilio will consider the Condition false after that time. After 2 minutes, the data is too “old” and should not be considered valid for our conditions.

The timeout countdown is reset every time a new event is received.

So a presence sensor will detect something, a variable in Apilio is updated to true (in fact, this variable is always true, because the sensor can only send that one event!). We are watching this variable with a Condition. The condition is only true for the first 2 minutes after the sensor detected something. So if the sensor detected something 10 hours ago, we don’t want to use this information to trigger any logicblocks.

This is very cool, how do I set it up?

When setting up a Condition applied to a Variable, there is an optional section to add delays and timeouts:

And you can also use the condition as a trigger!

If your Condition is set to evaluate any connected logicblock when it changes (this is in fact the default), the Condition will only trigger the logicblock when the Condition changes, taking into account any delays or timeouts set! :star_struck:

image

:bulb: Related articles

1 Like