Using IFTTT and apilio v2

If you find this post useful, please consider donating some money so I can upgrade and get rid of the ads. Donate here.

Check out the apilio subreddit: https://www.reddit.com/r/apilio/ 

This post is defunct. Use this one: https://iused2besmart.wordpress.com/2019/10/29/the-new-apilio/

I decided to redo my last blog post. It walked through how to setup “if it’s between sunset and sunrise (i.e. it’s “dark” out), and motion is detected by my ring doorbell, then turn on the front porch light and turn it off after 5 minutes”. Unfortunately, if someone walked up to the door 4 minutes after the original motion was detected, the light would still turn off after the original 5-minute delay expired. After much head scratching and thought, I figured out how to address this.

Now, when someone walks up to the door and it’s between sunset and sunrise, I increment a counter, turn on the light, and set the “turn off” action to trigger 5 minutes later. When the 5 minute delay expires, instead of just turning off the light, I decrement the counter then check if it’s “0”. If it’s not, nothing happens. If it’s zero, it turns off the light. This will be a long post and I added screenshots because some people had asked for them when I published my last blog post. Here’s an example of how it works:

Single motion:
Motion_Count = 0

  1. 8:00 PM – Motion detected. Light turns on. Motion_Count gets incremented (so now it’s 1). Set 5 minute delay (delay 1)
  2. 8:05 PM – Delay 1 expires. Motion_Count gets decremented (so now it’s 0). Check if Motion_Count = 0 and turn off the light.

Multiple motions:
Motion_Count = 0

  1. 8:00 PM – Motion detected. Light turns on. Motion_Count gets incremented (so now it’s 1). Set 5 minute delay (delay 1)
  2. 8:03 PM – Motion detected. Light turns on (yes, the light is already on but it’s easier to just turn it on again). Motion_Count gets incremented (so now it’s 2). Set 5 minute delay (delay 2)
  3. 8:05 PM – Delay 1 expires. Motion_Count gets decremented (so now it’s 1). Check if Motion_Count = 0 and do nothing; the light is still on.
  4. 8:07 PM – Motion detected. Light turns on. Motion_Count gets incremented (so now it’s 2). Set 5 minute delay (delay 3)
  5. 8:08 PM – Delay 2 expires. Motion_Count gets decremented (so now it’s 1). Check if Motion_Count = 0 and do nothing; the light is still on..
  6. 8:12 PM – Delay 3 expires. Motion_Count gets decremented (so now it’s 0). Check if Motion_Count = 0 and turn off the light.

This was pretty easy to do but there are a lot of little pieces that need to be setup. It would be nice if apilio could call itself within a logic block but it can’t; it can only call IFTTT.

IFTTT applets needed:

  • Detect motion at the front door – Triggered when the Ring doorbell has detected motion
  • Turn off porch – this is called by apilio and is used to call apilio. It’s an example of “apilio can’t call itself”
  • Increment Motion – this uses a webhooks call apilio to increment Motion_Count
  • Decrement Motion – this uses a webhooks call apilio to decrement Motion_Count
  • Turn off front light – this will actually turn the front light off
  • Turn on front light – this will actually turn the front light on
  • Sunrise – Triggered when Weather Underground detects that it’s sunrise and calls apilio to set “Night” to “false”
  • Sunset – Triggered when Weather Underground detects that it’s sunset and calls apilio to set “Night” to “true”

Apilio stuff:

  • Boolean Variable:
    • Night: is true when it’s between sunset and sunrise
  • Numeric Variables:
    • Motion_Count: incremented when motion detected; decremented when the delay expires
    • Zero: it’s set to “0” because I have to have a variable in the apilio condition instead of just usinga “0”
  • Conditions:
    • Turn_Off: true is motion_count is zero
    • IsItNighttime: true if “Night” is true
  • LogicBlocks:
    • turn_on_porch_light:
      If IsItNighttime=true then
      Trigger IFTTT to call apilio to Increment motion_count
      Trigger IFTTT to turn on the front light
      Sleep 5 minutes (in other words, set a 5-minute delay before continuing)
      Trigger IFTTT to call apilio to decrement motion_count
      Trigger IFTTT to call apilio to run the “turn_off_light” logicblock
      Else
      Do nothing
    • turn_off_light
      If turn_off=true then
      Trigger IFTTT to turn off the front light
      Else
      Do nothing

Create apilio parts

Now let’s create everything. I’ll start with the apilio items:

Boolean Variable: Night
In apilio, create a boolean variable, call it “Night” and set it to “true”. When you create it, you will get links to “Set true” and “Set false”.

  1. Go to https://apilio.com/
  2. Click on “Boolean Variables” on the left
  3. Click on “New Boolean Variable”
  4. Set the “Name” to “Night”; leave “Value” set to “True”
  5. Click “Save”

Picture1.png
night 2.png

Numeric VariableMotion_Count
In apilio, create numeric variable, call it “Motion_Count” and set it to “0”. When you create it, you will get links to “Add” and “Subtract”.
Picture1.png
Picture1.png

Numeric VariableZero
In apilio, create numeric variable, call it “Zero” and set it to “0”. This will always be “0”.
Picture1.png

Condition
Turn_Off
Create a “Condition” in apilio called “Turn_Off”. This condition will return “true” if “Motion_Count” = 0.

  1. Go to https://apilio.com/
  2. Click on “Conditions” on the left
  3. Click on “New Condition for Numeric”
  4. Set the “Name” to “Turn_Off”; set “Variable” to “Motion_Count”; set “must be” to “equal to” and “Secondary Variable” to “Zero”
  5. Click “Save”
    Picture1.png

Condition: IsItNighttime
Create a “Condition” in apilio called “IsItNighttime”. This condition will return “true” if “Night” is “True”

  1. Go to https://apilio.com/
  2. Click on “Conditions” on the left
  3. Click on “New Condition for Boolean”
  4. Set the “Name” to “IsItNighttime”; set “Variable” to “Night”; set “Required State” to “True”
  5. Click “Save”
    Picture1.png

LogicBlock: turn_on_porch_light
Create a logic block that, if “IsItNighttime” is true then increment “Motion_Count”, turn on the front light, wait 5 minutes. When the 5 minutes is up, decrement “Motion_Count” and then turn off the porch light if Motion_Count” is 0. If “IsItNighttime” is false, then nothing will happen:

  1. Go to https://apilio.com/
  2. Click on “Logicblocks” on the left
  3. Click on “New Logicblock”
  4. Set the “Name” to “turn_on_porch_light”
  5. Check “IsItNighttime” under “Conditions”; set “Condition linking” to “Simple AND”
  6. Under “Action Chains” click on “Add IFTTT Action”
  7. Set “IFTTT Webhooks Service Event Name” to “increment_motion”
  8. Under “Action Chains” click on “Add IFTTT Action”
  9. Set “IFTTT Webhooks Service Event Name” to “turn_on_front_light”
  10. Under “Action Chains” click on “Add IFTTT Action”
  11. Set “IFTTT Webhooks Service Event Name” to “decrement_motion”
  12. Click on “Show advanced options” and set “Delay” to “300” seconds (i.e. 5 minutes)
  13. Click on “Add IFTTT Action”
  14. Set “IFTTT Webhooks Service Event Name” to “turn_off_porch”
  15. Click “Save”

Picture1.png

LogicBlock: turn_off_light
Create a logic block that, if “turn_off” is true then call IFTTT to turn off the front light. If “Turn_Off” is false, then nothing will happen:

  1. Go to https://apilio.com/
  2. Click on “Logicblocks” on the left
  3. Click on “New Logicblock”
  4. Set the “Name” to “turn_off_light”
  5. Check “Turn_Off” under “Conditions”; set “Condition linking” to “Simple AND”
  6. Under “Action Chains” click on “Add IFTTT Action”
  7. Set “IFTTT Webhooks Service Event Name” to “turn_off_front_light”
  8. Click “Save”

Screenshot 2019-09-04 17.21.45

Create IFTTT applets

Detect motion at the front door
Triggered when the Ring doorbell has detected motion

  1. Go to https://ifttt.com
  2. Click on “My Applets” then “New Applet”
  3. Click on “this”
  4. Search for and select “ring” then select “New Motion Detected” and select the appropriate device then click “Create trigger”
  5. Click on “that”, search for and select “Webhooks” then select “Make a web request”
  6. Paste the “Evaluate” link from the apilio “turn_on_front_light” logicblock in the “URL” field.
  7. Leave the defaults and click “Create Action” and then “Finish”

Screenshot 2019-09-04 09.47.37

Turn off porch
This is called by apilio and is used to call apilio.

  1. Go to https://ifttt.com
  2. Click on “My Applets” then “New Applet”
  3. Click on “this”
  4. Search for and select “Webhooks” then select “Receive a web request”
  5. Set “Event Name” to “turn_off_porch” then click “Create trigger”
  6. Click on “that”, search for and select “Webhooks” then select “Make a web request”
  7. Paste the “Evaluate” link from the apilio “turn_off_light” logicblock in the “URL” field.
  8. Leave the defaults and click “Create Action” and then “Finish”

Screenshot 2019-09-04 10.53.27

Increment Motion
This uses a webhooks call apilio to increment Motion_Count

  1. Go to https://ifttt.com
  2. Click on “My Applets” then “New Applet”
  3. Click on “this”
  4. Click on “that”, search for and select “Webhooks” then select “Make a web request”
  5. Paste the “Add” link from the apilio “Motion_Count” numeric variable in the “URL” field.
  6. Chenge “your-value-goes-here” to “1”
  7. Leave the defaults and click “Create Action” and then “Finish”

Screenshot 2019-09-04 10.05.56

Decrement Motion
This uses a webhooks call apilio to decrement Motion_Count

  1. Go to https://ifttt.com
  2. Click on “My Applets” then “New Applet”
  3. Click on “this”
  4. Click on “that”, search for and select “Webhooks” then select “Make a web request”
  5. Paste the “Subtract” link from the apilio “Motion_Count” numeric variable in the “URL” field.
  6. Chenge “your-value-goes-here” to “1”
  7. Leave the defaults and click “Create Action” and then “Finish”

Screenshot 2019-09-04 10.16.00

Turn off front light
This will actually turn the front light off

  1. Go to https://ifttt.com
  2. Click on “My Applets” then “New Applet”
  3. Click on “this”
  4. Search for and select “Webhooks” then select “Receive a web request”
  5. Set “Event Name” to “turn_off_front_light” then click “Create trigger”
  6. Click on “that”, search for and select “TP-Link Kasa” and then “Turn off”
  7. Select the correct device and click “Create Action” and then “Finish”

Screenshot 2019-09-04 11.05.50

Turn on front light
This will actually turn the front light on

  1. Go to https://ifttt.com
  2. Click on “My Applets” then “New Applet”
  3. Click on “this”
  4. Search for and select “Webhooks” then select “Receive a web request”
  5. Set “Event Name” to “turn_on_front_light” then click “Create trigger”
  6. Click on “that”, search for and select “TP-Link Kasa” and then “Turn on”
  7. Leave the defaults and click “Create Action” and then “Finish”

Screenshot 2019-09-04 11.15.04

Sunrise
Triggered when Weather Underground detects that it’s sunrise and calls apilio to set “Night” to “false”

  1. Go to https://ifttt.com
  2. Click on “My Applets” then “New Applet”
  3. Click on “this”
  4. Search for and select “Weather Underground”
  5. Select “Sunrise”, update your location if needed, and click “Create Trigger”
  6. Click on “that”, search for and select “Webhooks” and then “Make a web request”
  7. Paste the “Set false” link from the apilio “Night” variable in the “URL” field.
  8. Leave the defaults and click “Create Action” and then “Finish”

Screenshot 2019-09-04 11.18.17.jpg

Sunset
Triggered when Weather Underground detects that it’s sunset and calls apilio to set “Night” to “true”

  1. Go to https://ifttt.com and login
  2. Click on “My Applets” then “New Applet”
  3. Click on “this”
  4. Search for and select “Weather Underground”
  5. Select “Sunset”, update your location if needed, and click “Create Trigger”
  6. Click on “that”, search for and select “Webhooks” and then “Make a web request”
  7. Paste the “Set true” link from the apilio “Night” variable in the “URL” field.
  8. Leave the defaults and click “Create Action” and then “Finish”Screenshot 2019-09-04 11.25.35

Improvement Areas

One way to make this a little better would be to change the “sunset” logic to set “Motion_Count” to “0”. This way you know that everything is set for the night. I’ve had this running for over a month and I haven’t had any issues and, frankly, I’m not sure it’s worth the effort.

I could also simplify this by using “Complex Conditioning Linking” but, after writing this blog post, I just don’t have the energy 🙂 Maybe in a few weeks.

One Reply to “Using IFTTT and apilio v2”

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