Hi,
I'm trying to figure out what's the correct way of passing values to IFTTT maker channel. I've got this to work.
define LowBatt notify .*:[Bb]attery.* {system ("curl -X POST https://maker.ifttt.com/trigger/{'low_battery'}/with/key/xxxxxxxxxxxxxxxxxxxxxxxx")}
( i just changed the " to ' for the event)
I intend to add an IF later to only notify on low battery readings but i'm testing with any value first.
But i'm having trouble knowing what to do with the request when passing values. IFTTT says it can be passed like this
curl -X POST -H "Content-Type: application/json" -d '{"value1":"123","value2":"456","value3":"789"}' https://maker.ifttt.com/trigger/{event}/with/key/xxxxxxxxxxxxxxxxxxxx
I'd like to pass the notify values (i.e $NAME, $EVTPART0 etc) as value1,value2..... I tried changing all the " to ' but got a bad request.
- First I would try to find the correct curl syntax in the shell / comand-line, without using any variables.
- For the next step in testing I would set some sample variables in the shell (export NAME=value1, etc), and rewrite the curl command to use them.
- Note that in the shell no variable evaluation takes place if the argument is enclosed in ', one of the alternatives is to use ". This is unfortunate for the -d option, since you have to use "" in the JSON syntax, i.e. you have to escape each JSON " with \". Following might work (untested):
curl -X POST -H "Content-Type: application/json" -d "{\"$NAME\":\"$EVTPART0\"}" "https://maker.ifttt.com/trigger/{low_battery}/with/key/xxxxxxxxxxxxxxxxxxxx"
- If everything works in the shell, change the notify to the working version. Instead of using {system("...")} I recommend using "...". You should be able to take your shell test result without a change as FHEM sets the environment Variables $NAME, $EVTPART0, etc.
Please post your results here, to make life easier for followers.
Thanks for the info. After a little thought i got it to work. It actually seemed quite straight forward in the end.
define LowBatt notify .*:[Bb]attery.* "curl -X POST -H "Content-Type: application/json" -d '{"value1":"'$NAME'","value2":"'$EVTPART1'"}' https://maker.ifttt.com/trigger/low_battery/with/key/xxxxxxxxxxxxxxxxxxxxxxxxxxx"
it was just down to escaping from the singe quotes correctly.
Thanks again for the tips
Craig