2
Choose style:

Author Topic: IFTTT triggers and actions  (Read 6763 times)

0 Members and 1 Guest are viewing this topic.

Offline deyan

  • Newbie
  • *
  • Posts: 8
  • Thanks: 0
  • Registered : 29/09/2016
    YearsYearsYearsYearsYearsYearsYearsYears
IFTTT triggers and actions
« on: October 14, 2016, 05:16:17 pm »
Got my Almond+ yesterday, works nice. Love the rule mechanic, however, the only IFTTT triggers it supports are device connected. Are there any plans to have these updated, it would be the best to me to have a "then" clause called ifttt which allows me to create an IFTTT trigger - for example, if the temp goes below X degrees (zigbee sensor, almond), let ifttt know, ifttt will switch the AC on using my harmony hub.

Offline Ashok

  • Securifi Staff
  • *
  • Posts: 2770
  • Thanks: 3
  • Registered : 25/07/2014
    YearsYearsYearsYearsYearsYearsYearsYearsYearsYears
Re: IFTTT triggers and actions
« Reply #1 on: October 15, 2016, 11:44:14 am »
@ deyan,

Yes, eventually new features/options would be added to our Almond channel.

Offline deyan

  • Newbie
  • *
  • Posts: 8
  • Thanks: 0
  • Registered : 29/09/2016
    YearsYearsYearsYearsYearsYearsYearsYears
Re: IFTTT triggers and actions
« Reply #2 on: October 23, 2016, 02:31:12 am »
I can report that I was able to create a rather dirty workaround that seems to solve the use case described (and any other time-based Almond rule - got it to trigger IFTTT). If anyone interested, will share the scripts. Basically, created a script that reads the rule log and sends a get request to IFTTT (maker channel) once a rule has been executed.

Offline naphtaliq

  • Newbie
  • **
  • Posts: 11
  • Thanks: 0
  • Registered : 15/07/2015
    YearsYearsYearsYearsYearsYearsYearsYearsYears
Re: IFTTT triggers and actions
« Reply #3 on: October 26, 2016, 09:49:39 am »
I can report that I was able to create a rather dirty workaround that seems to solve the use case described (and any other time-based Almond rule - got it to trigger IFTTT). If anyone interested, will share the scripts. Basically, created a script that reads the rule log and sends a get request to IFTTT (maker channel) once a rule has been executed.

Interested, please post

Offline deyan

  • Newbie
  • *
  • Posts: 8
  • Thanks: 0
  • Registered : 29/09/2016
    YearsYearsYearsYearsYearsYearsYearsYears
Re: IFTTT triggers and actions
« Reply #4 on: October 31, 2016, 09:12:24 am »
Here's what I did. The procedure requires basic linux knowlege and SSH access to the router. I cannot guarantee success or be liable for any damages done (just saying).

tl;dr Created a couple of dummy time-based rules, listening for log changes when the rules executed, after up to a minute, sending a notification to IFTTT

0) Create Almond and IFTTT rules
0a) I did create rules of type IF at home and time is 5:00 then switch to home. Then you have to check the rule numbers.
0b) Create the IFTTT rules - in my case
IF Maker Event "lr_ac_heat" THEN /do whatever you want/
IF Maker Event "lr_ac_off" THEN /do whatever you want/

1) Edit the scripts to fit your needs. See rule numbers and modify executeCustomRule.sh. In order to view the rule numbers, wait for the rules to happen, ssh to your router, and execute the following command:
Code: [Select]
cat /tmp/runRule.logIt should print something like this:
Code: [Select]
[2016-10-20 19:35:1.526610340] {PRINT} <================================runRule started=================================>
[2016-10-20 19:35:1.529397551] {PRINT} precisely at
[2016-10-20 19:35:1.529718225] {PRINT} executing Rule 5 for AND condition is success
[2016-10-20 19:35:1.531738481] {PRINT} runRule:setting Device 10 Index 2 to Value true.
[2016-10-20 19:36:1.487648301] {PRINT} <================================runRule started=================================>
[2016-10-20 19:36:1.490216892] {PRINT} precisely at
[2016-10-20 19:36:1.490529432] {PRINT} executing Rule 6 for AND condition is success
[2016-10-20 19:36:1.492501342] {PRINT} runRule:setting Device 10 Index 2 to Value true.
[2016-10-21 5:0:1.774937844] {PRINT} <================================runRule started=================================>
[2016-10-21 5:0:1.777657199] {PRINT} precisely at
[2016-10-21 5:0:1.778833712] {PRINT} executing Rule 5 for AND condition is success
[2016-10-21 5:0:1.779772137] {PRINT} runRule:setting Device 10 Index 2 to Value true.
[2016-10-21 6:0:1.707967205] {PRINT} <================================runRule started=================================>
[2016-10-21 6:0:1.710614894] {PRINT} precisely at
[2016-10-21 6:0:1.711781380] {PRINT} executing Rule 6 for AND condition is success
[2016-10-21 6:0:1.713706465] {PRINT} runRule:setting Device 10 Index 2 to Value true.
2) SSH to your router. Get all of the scripts* (and rename them if needed). Make the scripts executable. In my case
Code: [Select]
chmod +x /root/executeCustomRule.sh
chmod +x /root/ac_heat_on.sh
chmod +x /root/ac_heat_off.sh
3) Create the status file. These are needed in order for the main script to be able to tell if it turned on or off the device. In my case, there is one file in the root directory called living_room_status. It currently has two states - off and heat.
Code: [Select]
echo off > living_room_status

3) Edit your crontab. That was a little tricky since I am not familiar with vi. If you are not either, see Google
Code: [Select]
crontab -eThis opens the crontab in edit mode. You need to add a line that says
*   *   *   *   *   /root/executeCustomRule.sh
This line says to the router that it needs to execute the custom rule script every minute. Don't worry, that should not be resource intensive task.

The scripts:
Here is your IFTTT API key for the maker channel: https://ifttt.com/maker. Replace it in the scripts using text editor.

ac_heat_on.sh

Code: [Select]
#Check which device should be turned on. That gets living_room or bedroom parameter.

case "$1" in
"bedroom") echo "You gave bedroom"
COMMAND="br_ac_heat"
;;
"living_room") echo "You gave living_room"
COMMAND="lr_ac_heat"
;;
*) exit 1
;;
esac

#That sends the command to IFTTT. On success, puts "heat" status in /root/living_room_status or /root/bedroom_status
if wget -O/dev/null http://maker.ifttt.com/trigger/$COMMAND/with/key/YOUR_IFTTT_KEY_HERE; then echo heat > /root/$1_status; fi

ac_heat_off.sh

Code: [Select]
#Check which device should be turned off. That gets living_room or bedroom parameter.
case "$1" in
"bedroom") COMMAND="br_ac_off"
;;
"living_room") COMMAND="lr_ac_off"
;;
*) exit 1
;;
esac

#That sends the command to IFTTT. On success, puts "off" status in /root/living_room_status or /root/bedroom_status
if wget -O/dev/null http://maker.ifttt.com/trigger/$COMMAND/with/key/YOUR_IFTTT_KEY_HERE; then echo off > /root/$1_status; fi


executeCustomRule.sh
Code: [Select]
# Get the last 50 rows in the log. Check for Rule 9 or 10 (in my case). Rule 9 should turn on the device, Rule 10 should turn it off. Only works for the current day, i.e. will not work across days. Puts in ACSTAT variable what should be the status
DATENOW=`date +%F`
ACSTAT=$(tail -n 50 /tmp/runRule.log | grep "executing Rule 9 for AND condition is success\|executing Rule 10 for AND condition is success" | grep ${DATENOW//-0/-} | tail -n 1)

# If Almond rule 9 (turn on the ac) happened and the status of living room AC is off, then turn it on and write in the customRule.log
if echo $ACSTAT | grep "Rule 9"  && cat /root/living_room_status | grep "off"
then
if sh /root/ac_heat_on.sh living_room
then
echo $(date +%F\ %T) $(echo " - Rule 9, AC is off, turning heat on") >>/tmp/customRule.log
fi
fi

# If Almond rule 10 (turn off the ac) happened and the status of living room AC is heat, then turn it off and write in the customRule.log

if echo $ACSTAT | grep "Rule 10" && cat /root/living_room_status | grep "heat"
then
if sh /root/ac_off.sh living_room
then
echo $(date +%F\ %T) $(echo " - Rule 10, AC is heat, turning it off") >>/tmp/customRule.log
fi
fi

#Reset the last rule variable
ACSTAT=0
« Last Edit: November 01, 2016, 02:10:05 am by deyan »

Offline naphtaliq

  • Newbie
  • **
  • Posts: 11
  • Thanks: 0
  • Registered : 15/07/2015
    YearsYearsYearsYearsYearsYearsYearsYearsYears
Re: IFTTT triggers and actions
« Reply #5 on: October 31, 2016, 03:49:12 pm »
LEGEND! :)

Offline Uprising54

  • Newbie
  • Posts: 2
  • Thanks: 0
  • Registered : 30/10/2016
    YearsYearsYearsYearsYearsYearsYearsYears
Re: IFTTT triggers and actions
« Reply #6 on: July 07, 2017, 09:18:12 pm »
@ deyan,

Yes, eventually new features/options would be added to our Almond channel.

@ashok Where are we with these new features/options. So far, the IFTTT integration is fairly limited.

 

Page created in 0.076 seconds with 16 queries.