I have implemented a securty system that, when any of my Netatmo security cameras detect a person around my house, I get a notification in my mobile and, if this happens after sunset, outside lights are turned on for a few minutes.
Sometimes I plan to be in the garden for some hours and I don’t want notifications to arrive or lights to turn on/off everytime a person (myself or my family) is seen.
Until now, I had a boolean variable called “armed_alarm” and a condition “is_alarm_armed” (if armed_alarm = TRUE). I implemented an Alexa routine which sets “armed_alarm” to TRUE/FALSE when I say “activate / deactivate alarm”. Logicblock which controls notification/lights included that “is_alarm_armed” condition.
Today I have improved that system with the possibility to turn off the alarm for 1, 2, 3, 4 or 6 hours so that I don’t have to reactivate the alarm myself, which is something I tend to forget.
I have replaced “armed_alarm” boolean variable by a numeric variable called “minutes_left_before_alarm_is_back_on”
- If I say “Snooze alarm for 1 hour” Alexa triggers an IFTTT routine which sets “minutes_left_before_alarm_is_back_on” to 60.
- If I say “Snooze alarm for 2 hours”, Alexa triggers an IFTTT routine which sets “minutes_left_before_alarm_is_back_on” to 120.
- If I say “Deactivate alarm”, Alexa triggers an IFTTT routine which sets “minutes_left_before_alarm_is_back_on” to 999999.
- If I say “Activate alarm”, Alexa triggers an IFTTT routine which sets minutes_left_before_alarm_is_back_on" to 0.
In order for “minutes_left_before_alarm_is_back_on” to diminish as time goes by, I have created a new condition called “every_5_minutes” (cada_5_minutos) with a cron condition “*/5 * * * *” (this means “At every 5th minute”). This condition triggers a logicblock which triggers an IFTTT action which performs a mathematical operation: substract 5 to “minutes_left_before_alarm_is_back_on”.
So, for example, if I set “minutes_left_before_alarm_is_back_on” to 120 (2 hours) at 19:03, then it will be 115 at 19:05, 110 at 19:00, 105 at 18:55, etc. Eventually, it will be 0 and then -5, -10, -15, etc.
Note: OK, you are right, it will reach 0 after 117 minutes, not 120 minutes. I don’t care. More precission could be achieved by creating a cron “at every minute” and substracting 1. Or even working with seconds instead of minutes and creating a cron “at every 10th second”, but I want to be nice with IFTTT and Apilio and avoid flooding with events.
The logicblock which sends the notification and turns on the lights when motion is detected is now controlled by a condition which is “minutes_left_before_alarm_is_back_on < 0”. As long as minutes_left_before_alarm_is_back_on is > 0, no notification is sent (or light is turned on at night), and as soon as it becomes negative and motion is detected, notification is sent and light is turned on.
Although I am using this for an alarm, it could be applied to any other action like lights turning on/off when motion is detected/not detected.