Adding more complex triggers with IFTTT to control your home IoT

IoT HomeI have been using IFTTT for quite a while with my various IoT devices, doing simple things like turning on lights when my garage door opens or when there is motion near my home. One of the great things about IFTTT is its simplicity. If ‘this’ triggering event happens, do ‘that’. This simplicity is also one of the frustrating limitations of doing more complex tasks.

If I want to only turn on the porch lights when it is dark out, but keep them off when it is light, there is no way to do that natively within the system. They have thought about expansion capabilities through the ability to send and receive information from websites that can provide stateful information – IFTTT supports both trigger and response through a capability called webhooks. There are some free services to support this capability that you can experiment, if you don’t want to bring up your own website.

The one I looked at is: apilio.io and there is a good explanation of it on Medium. It is still in beta though.

Apilio has three building blocks:

  • Variables – to contain state information
  • Conditions – to evaluate variables
  • Logicblocks – to determine the actions from a Boolean analysis of the conditions

As an example, I decided to use Apilio with IFFF to turn my lights on when there was motion in front of my house but only when it is dark out. To accomplish this, I had to perform the following steps:

  1. Configure your IFTTT webhook connection on your webhooks settings/documentation page in IFTTT and enter that key into your Apilio profile. This key enables a secure connection between the website and IFTTT.
  2. Next define the variables in Apilio where you would like to store state information. In my case, I created a Boolean variable darkOutside. Note that there are URLs that when accessed will set the variable to True or False. You’ll need these URLs in the next step.
  3. Define two IFTTT rule Applets that set the variable to True at sunset and False at sunrise, using the capabilities of the Weather Underground trigger supported by IFTTT.
  4. Define a condition in Apilio that if darkOutside is True then it returns true, otherwise False. I named it DarkOutsideCondition
  5. Next, I made an Apilio logicblock that performs a simple logical AND operation that if it is triggered and the DarkOutsideCondition is True, it triggers applets back in IFTTT. I called the logicblock lights_on_when_dark. It has a URL to force its evaluation (from the logicblock show command) and a place to store a IFTTT trigger event name, if it is evaluated. One for True (called LightsOn) and another for when it is evaluated False (called LightsOff).
  6. Since I have a Ring doorbell with motion sensing that interfaces with IFTTT, I made an IFTTT Applet for when motion is sensed to initiate the evaluation trigger of the logicblock lights_on_when_dark.
  7. Now I just needed to create 2 more Applets, one to turn on the lights if it gets a webhook event called LightsOn and another if IFTTT gets the webhook event LightsOff that turn the lights on accordingly.

This may seem a complex but really only consists of:

  • a variable, a condition and a logicblock in Apillio
  • five applets in IFTTT:
    • set the darkOutside variable to true at sunset
    • set the darkOutside variable to false at sunset
    • receive a LightsOff trigger and turn the lights off
    • receive a LightsOn trigger and turn the lights on
    • catch the Ring motion sensor trigger and force and evaluation of the lights_on_when_dark logic block.

This is a fairly simple example. There are also some additional examples on the Apilio site, but hopefully this walkthrough will help you get started with enough context to overcome some of the areas that confused me.

I also have a IFTTT applet to turn the lights off at sunrise, just so there is another way to turn the lights off. I should have the ability to add some delay sensing so that I can turn the lights off after they have been on for a defined period (say a half hour), to keep my energy costs down.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s