Turbocharge your IFTTT logic with Apilio.com

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • DBMandrake
    Automated Home Legend
    • Sep 2014
    • 2361

    Turbocharge your IFTTT logic with Apilio.com

    This started out as a query in another thread however after finding a solution that I like I thought the solution itself was worthy of its own thread as it has much broader home automation application than my single light scenario.

    I'm sure many of you use or have tried IFTTT, and while it can connect to a seemingly unlimited number of services, the control logic is a little, well, lacking shall we say. Basically you have input events (triggers) that can then be connected to an action. Some services provide both triggers and actions, some only one or the other.

    So you could have a trigger that says when I enter this area (geofencing) perform that action. (turn on my light) But what if you want to add other conditions such as only turn on the light if its night time when you enter the area ? Sorry, can't do it, even if you have another set of triggers that fire for sunset and sunrise. There is no way to combine different triggers as there is no persistent state that can be shared between triggers, nor any way to cascade or link triggers together or perform logical actions like AND or OR. These and other limitations are very surprising to me, and for many purposes make IFTTT pretty useless.

    However I found a solution that so far, works very well: https://apilio.com/

    This is a free 3rd party service that integrates with IFTTT like any other service provider which provides what I would call "logic middleware". You can create persistent bool/string/numeric variables that can save and accrue state based on triggers being sent to it from other IFTTT services, those variables can be used to create conditions, and those conditions can then be used in logic blocks where you can define an arbitrary set of logical conditions before performing or not performing actions. Those actions then send events back to IFTTT that can then be connected to other services to perform actions such as turn on a light.

    Actual logic block execution/evaluation can either be initiated by an IFTTT trigger directly, or automatically execute when any of the variable conditions changes. More on that later.

    One thing I should note is that prior to October 2019 Apilio relied on the Webhooks API in IFTTT and wasn't directly integrated so many of the posts in their support forum revolve around this now obsolete connection method which I found confusing at first, so if you are browsing their forum or documentation keep in mind that Webhooks aren't needed and are obsolete now, just add it as any other service directly in IFTTT, and you don't need to do anything with the "IFTTT Webhooks Service API Key" in your Apilio account.

    I'll use my own light scenario as a tutorial of how Apilio could be used. I have the following criteria for my porch light:

    1) Turn on at 7am Monday to Friday, but only if I am home, and only if it's dark outside... and set a timer to turn it off again one hour later in case I don't leave the house that day (holiday) and forget to turn it off manually.
    2) Turn off once my phone leaves a 1km radius of the house, regardless of whether it's light or dark outside.
    3) Turn on when my phone comes back within a 1km radius of the house, but only if it's dark outside, and set a timer to turn it off again 10 minutes later.

    Fairly simple logical conditions but as far as I can see totally impossible to achieve natively in IFTTT. So enter Apilio.

    First we need two pieces of persistent state information that automatically update - am I at home, and is it daytime. So first I create two variables in apilio called "at_home" and "daytime":



    I can then update these from IFTTT using triggers. Apilio actually provide sample applets for both of these although you can create your own custom ones. One is the "When I enter an area, update a variable in Apilio to true" applet - I select my location and a radius around it (I used about 1km) and then tell it to assign this to the Apilio variable "at_home". I then do the same with another applet with the same location radius to set the variable to false when I leave the area.

    For daytime they have an applet "Set a variable in Apilio to true on sunrise" which also takes my location and I tell it to update the "daytime" variable, and likewise one that sets the variable to false on sunset. (I think Weather Underground is the source of the sunrise/sunset time) Now we have two variables that are updated in real time when sunrise and sunset occur or when I leave or arrive home.

    From those variables we can now create conditions that can later be tested, and I have the following conditions defined:



    At_Home = "at_home" must be true.
    Daytime = "daytime" must be true.
    Nighttime = "daytime" must be false.

    Leaving_Home and Arriving_Home are interesting because they are not state conditions but state change conditions. This is done by specifying a "modified within" period:



    This means that the condition Arriving_Home is only true for 60 seconds after the variable at_home changes from false to true, and then becomes false again after this.

    [Continued next post due to the silly forum limit of 4 images per post...]
    Last edited by DBMandrake; 28 November 2019, 12:17 PM.
  • DBMandrake
    Automated Home Legend
    • Sep 2014
    • 2361

    #2
    Now that I have the conditions I need I can create an arriving_home logic block:



    The block will perform an action when it is nighttime and I am arriving home - which is during the 60 second period when the at_home variable changes from false to true. I am using a simple AND of these conditions however I could use more complex logic if needed.

    Next are the actions to perform when the logic block evaluates as true, or as false. Both true and false outcomes can have zero, one or more actions performed with optional delays. In this case I perform two actions if the logic block is true, the second with a delay, and no actions if the logic block is false:



    Finally there is a magic setting called "Automatic evaluation". To trigger a logic block to be executed you can choose to explicitly trigger it using an IFTTT trigger, however it is more elegant and flexible IMO to enable this option which then means that any of the conditions that apply in the logic block changing will automatically cause it to be re-executed and re-evaluated without help from IFTTT:



    This means that as soon as IFTTT updates the status of the at_home variable the logic block fires and checks to see if arriving_home is true and nighttime is true. In the case that the nighttime condition is the one that changes and triggers execution of the logic block, arriving_home is not true so nothing is executed.

    I have a similar logic block for leaving_home which I won't show here, it simply matches on the leaving_home condition, and has a single action of Porch_Light_Off.

    For the 7am automatic turn on I have a third logic block called porch_light_morning_timer whose logic conditions are Nighttime AND At_Home, which then runs the Porch_Light_On action and then after an hour delay runs the Porch_Light_Off action. (Although in most cases the Leaving_home logic block will have fired and turned off the light long before then...)

    This logic block does not use the Automatic Evaluation option. Instead I have a Date/Time IFTTT trigger configured for 7am Monday to Friday which simply executes the logic block explicitly.

    To connect the Porch_Light_On and Porch_Light_Off actions in apilio to some service to do something you create a custom IFTTT app, choose apilio for the trigger and you will see the actions listed there, you can then assign the action to your smart device - in my case Kasa to then directly control the TP-Link bulb. Or you could change a scene etc...

    There are still a few things Apilio can't do but even just the addition of combinational logic to existing IFTTT services opens up a world of possibilities and I can see some fairly complex home automation scenarios being relatively easy to put together using Apilio...

    Another feature which I have not tested, is that it's apparently possible to link multiple IFTTT accounts to the same instance of Apilio. This would be particularly useful for Geofencing applications where you may want to geofence both your own phone AND your spouses, for the purpose of turning off heating or lights when nobody is at home, but turning them on when either or both of you are.

    In that scenario you would create a second IFTTT account for your spouse and link it to the same Apilio account, install the IFTTT app on their phone and log into that secondary IFTTT account. Then you would use the geofencing applets in the second IFTTT account to update the state of a second variable such as "spouse_at_home" in the same apilio instance.

    When you have the at home status (as well as arriving and leaving that you can derive from those) of both you and your spouse you can then apply the complex logic necessary to coordinate control of lighting, heating and so on based on whether there are zero, one or two people at home or coming and going...
    Last edited by DBMandrake; 28 November 2019, 12:30 PM.

    Comment

    • DBMandrake
      Automated Home Legend
      • Sep 2014
      • 2361

      #3
      Well that didn't last.

      I got an email from Apilio yesterday saying that they were moving to a paid subscription model as of January 2020!

      To enable full functionality that has until now been free you're looking at $3.90 a month. If you had a big complex whole house control scheme in place it might be worth it but I'm only using it to control one light and I'm already being nickle and dimed by various other services that I rely on...

      So I'll be looking for an alternative. I've found a tutorial on connecting Siri to Kasa via IFTTT, a bit fiddly to set up, but it should allow me to say hands free "Hey Siri turn on the porch light" while arriving home in the car - good enough for me and less battery hungry than geofencing!

      Pity...

      Comment

      • rs1987
        Automated Home Jr Member
        • Nov 2019
        • 44

        #4
        Originally posted by DBMandrake View Post
        Well that didn't last.

        So I'll be looking for an alternative. I've found a tutorial on connecting Siri to Kasa via IFTTT, a bit fiddly to set up, but it should allow me to say hands free "Hey Siri turn on the porch light" while arriving home in the car - good enough for me and less battery hungry than geofencing!

        Pity...
        You can do this with Amazon Alexa. I control all my Kasa plugs and bulbs with the Alexa app, which is available for iphone

        Comment

        • DBMandrake
          Automated Home Legend
          • Sep 2014
          • 2361

          #5
          Originally posted by rs1987 View Post
          You can do this with Amazon Alexa. I control all my Kasa plugs and bulbs with the Alexa app, which is available for iphone
          The Alexa app is not hands free though, so I can't use it while driving.

          Comment

          Working...
          X