It's dark, I'm arriving home, turn lights on....Please

It's dark, I'm arriving home, turn lights on....Please
0

#1

This smart automation was suggested by one of our users and since sharing is caring, here you have all the details to replicate this at your own home.

Imagine that you want to turn on your foyer lights on when it’s dark at night, but only as you get close to your home. You could use this to quietly let your partner know that you are almost there, or for creating anticipation for your waiting-for-their-night-walk pets. And, of course, to light your way in so you don’t step on anything you should not be stepping on!

For this setup, we are going to use the service Life360 to determine that we are close to home and also a TP-Link smart plug where a lamp is connected to, so we can turn it on and off. A variable in Apilio will store whether it is nighttime or daytime, so we can check as a condition when we get home if it is already dark or not.

You could also replicate this with the location service from IFTTT and any other smart light bulb, or smart plug that you have available, following the same steps.

Setting up the variable

We want to create a variable called “nighttime” that is set to true at sunset and set to false at sunrise. In Apilio, create a boolean variable called ‘nighttime’, and set it to false (if it is currently daytime when you are setting up the variable for the first time):

Creating the condition

My condition in Apilio will check whether it is nighttime or not.

We can for example call our condition ‘should_foyer_light_be_on’, and we will use the variable ‘nighttime’ to determine the state of this condition: if it is nighttime (‘nighttime’ is true), then the condition is true as well. If it is daytime (so, ‘nighttime’ is false), then the condition is false, as the foyer light doesn’t need to be automatically switched on at this time.

How to set the variable to true or false via IFTTT

With a couple of applets, we can control when our ‘nighttime’ variable is set to true or false, as follows:

  1. Go to IFTTT now and select “create” to start building your own applet (https://ifttt.com/create).

  1. For the “If this” part, select the Weather Underground service, and Sunset as your trigger.

  1. For the “then that” part, select the Apilio service, and Update a variable in Apilio to true as your action, and then your ‘nighttime’ variable that has to be updated:

  1. Review and click complete to finish setting up your applet, you are done!

  1. To update the variable to false in the mornings, create a new applet just like this one but as your trigger choose the Sunrise trigger from Weather Underground and as your action, choose Update a variable in Apilio to false.

How to create the logicblock

Every time I’m arriving home, I want to check whether it’s dark outside and, if it is, I want to turn my foyer light on. It’s time to define our logic with our logicblock!

We can call the logicblock ‘control_foyer_lights’. It will use the condition ‘should_foyer_light_be_on’, that we created earlier. If the condition is true, my logicblock will trigger the following 2 positive actions:

  • I will turn my foyer light on. For this, the event name that Apilio will send to IFTTT will be ‘foyer_light_on’.
  • 30 minutes later, I will turn my foyer light off. To achieve this, the event name that Apilio will send to IFTTT will be ‘foyer_light_off’. To delay it 30 minutes, I will configure this in the advanced options as 30 minutes * 60 seconds = 1800 seconds.

To trigger my logicblock evaluation, I will setup an IFTTT applet that calls Apilio whenever Life360 says that I’m close to home, as follows:

  1. Create the applet in IFTTT: https://ifttt.com/create
  2. For the “If this” part, choose Life360, and the trigger You arrive at a specific place:

  1. For the “then that”, choose Apilio and the action to evaluate the logicblock ‘control_foyer_lights’

  1. We can complete the applet and it will look like this:

Let’s finish this automation by setting up our actions.

Setting up my actions in IFTTT

Our logicblock has only two actions, both of them are in the positive actions chain. To turn on and off the light, we are controlling this with a smart plug. Apilio takes care of the 30 minutes delay, so that the IFTTT setup is easy-peasy. You will need the following two applets setup, just follow the steps:

To turn on my the foyer light on:

  1. The applet I want to create will be: If IFTTT receives the event ‘foyer_light_on’ from Apilio, then turn on my smart plug.
  2. As the “If this” part, select Apilio, and then the trigger to Receive an event from Apilio, then choose the event name that will be received
  3. As the “then that” part, select TP-Link Kasa, to switch the plug on

To turn my outside lights off:

  1. The applet I want to create will be: “If IFTTT receives the event ‘foyer_light_off’ from Apilio, then turn off my smart plug”.
  2. As the “If this” part, select Apilio, and as your trigger Receive an event from Apilio, then choose the event:
  3. As the “then that”, select TP-Link Kasa to turn it off

And we are done! Now you have a light that will only turn on at night, when you are getting home.

Can you think of other situations where this might come in handy for you? Let us know how you have tweaked this example to suit your smart home needs below.


#2

Hi I m tring to use this logicblock

But I don’t understand this last step:

In IFTTT, I created a Webhooks applet : If Maker Event “lights_on_dark”, then activate a scene in Smartlife app (my lights).

Can You please make me a step-by-step guide


#3

Hey Edoardo,

  1. After a Logicblock is evaluated it may, or may not, run an action - depending upon the result of the Logicblock evaluation
  2. The action described above is to trigger a Webhooks call to IFTTT - this Webhooks call runs a specific IFTTT Maker Event called “lights_on_dark” in IFTTT
  3. The Maker Event is the “IF This” side of the IFTTT Applet and will receive the Webhooks call from Apilio. You’ll see you need a name for the Maker Event in IFTTT as you setup the Webhooks call side of the Applet and that name must be identical in both IFTTT and Apilio for the correct Applet to be triggered. The field in Apilio is called “IFTTT Webhooks Service Event Name”.
  4. The “Then That” side of the IFTTT Applet is activating a scene in Smartlife.

Hope that makes sense.


#4

My problem is that the Webhooks call from Apilio don’t work. there could be a problem on the trigger of Webhooks call? also If I try to test the action from the “show” page of Logicblock it don’t work.


#5

Solved My problem was in the configuration of IFTTT Key.

sorry for disturb


#6

No worries, we’re glad you got it fixed!


#7

Very well described example.
Even though i’m quite familiar with Apilio I always learn more from examples like this from expert like you.
Thank you.