buckle up, I wanted to be quick, but the post just grew… so here’s kinda long read
TL;DR: want to send some variables from IFTTT to HomeAssistant, that would feed universal automation/script which is going to do the rest based on variables. for main questions please jump to the end of this post
I’m using IFTTT webhooks to call few services/scripts on my Home Assistant. even helped few guys so I guess “I’m doing it ok” but right now I’m stuck with sending more variables thru it.
background info: I love to make universal automations/scripts that can work differently based on given arguments.
so, I want to pimp up the simple webhook receiving automation to be able to handle more case scenarious than the basic one. if you don’t want to jump between topics, here’s the basic one:
- alias: automate_ifttt
trigger:
- platform: event
event_type: ifttt_webhook_received
event_data:
action: 'call_service'
action:
- service_template: '{{ trigger.event.data.service }}'
data_template:
entity_id: '{{ trigger.event.data.entity_id }}'
when I POST application/json body from IFTTT, containing:
{
"action": "call_service",
"service": "script.turn_on",
"entity_id": "script.MY_SCRIPT"
}
everything works, and script.MY_SCRIPT is being executed.
but I want to pass some info to that script - let’s say it’s going to be the URL to some file uploaded to my Google Drive. so I modify json’s body to:
{
"action": "call_service",
"service": "script.turn_on",
"entity_id": "script.MY_SCRIPT",
"variables": { "var_temp":"{{FileUrl}}" }
}
the “variables” part is thanks to reading some other topics.
unfortunately it’s not working - tried it with a script that notifies me on telegram:
MY_SCRIPT:
sequence:
- service: notify.my_telegram_bot
data_template:
message: "here goes nothing: {{ var_temp }}"
I tried adding something like adding this to data_template of webhook receiving automation:
var_temp: '{{ trigger.event.variables.var_temp }}'
no luck. so I’ve changed the message part of MY_SCRIPT:
message: "here goes nothing: {{ trigger.event.variables.var_temp }}"
but it didn’t work too [well, I’m not surprised, since trigger.event is for automation, not scripting, right?]
CONCLUSION & MAIN QUESTIONS [boy, finally!]
- how can I add some variable to json’s body - so it would be used by some scripts, and could be ignored while empty?
- couldn’t find this - is the “call_service” in “action” part, a mandatory thing for calling a service? or is it just a keyword that can be later checked in the automation? [if it’s just a keyword, maybe I could make some “action” like “send_variable” and then solve the rest with conditions within automation?]