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:
- Go to IFTTT now and select “create” to start building your own applet (https://ifttt.com/create).
- For the “If this” part, select the Weather Underground service, and Sunset as your trigger.
- 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:
- Review and click complete to finish setting up your applet, you are done!
- 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:
- Create the applet in IFTTT: https://ifttt.com/create
- For the “If this” part, choose Life360, and the trigger You arrive at a specific place:
- For the “then that”, choose Apilio and the action to evaluate the logicblock ‘control_foyer_lights’
- 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:
- The applet I want to create will be: If IFTTT receives the event ‘foyer_light_on’ from Apilio, then turn on my smart plug.
- 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
- As the “then that” part, select TP-Link Kasa, to switch the plug on
To turn my outside lights off:
- The applet I want to create will be: “If IFTTT receives the event ‘foyer_light_off’ from Apilio, then turn off my smart plug”.
- As the “If this” part, select Apilio, and as your trigger Receive an event from Apilio, then choose the event:
- 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.