I use Google Assistant (GA) and IFTTT to trigger a variety of Home Assistant (HA) services/scripts. For several of the scripts, I pass variables from IFTTT. That had been working extremely well until I switched authentication methods. I moved from using api_password
to service integrations. For simple scripts, this move has been an easy transition. However, I can’t figure out how to successfully continue passing variables from IFTTT to HA.
With the api_password
method, my configuration looked something like this:
IFTTT
URL:
https://[DOMAIN].duckdns.org:[PORT]/api/services/script/tv_volume_up_input?api_password=[PASSWORD]
Body:
{ "vol_amnt":"{{NumberField}}" }
Home Assistant
script:
tv_volume_up_input:
alias: 'TV Volume Up Input Control'
sequence:
- service: input_number.set_value
entity_id: input_number.tv_volume_up_variable
data_template:
value: >
{% set vol_val = vol_amnt|float %}
{% if vol_val|float <= 0.0|float %}
{% set vol_val = 0.0|float %}
{{vol_val|float}}
{% elif vol_val|float > 32.0|float %}
{% set vol_val = 31.0|float %}
{{vol_val|float}}
{% else %}
{{vol_val|float - 1.0|float}}
{% endif %}
With the new integration method, my configuration looks something like this:
IFTTT
URL:
https://[DOMAIN].duckdns.org:[PORT]/api/webhook/[TOKEN]
Body:
{ "action": "call_service", "service": "script.tv_volume_up_input" }
Home Assistant
automation:
- hide_entity: true
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 }}'
I still need to pass that variable to the tv_volume_up_input
script (and other variables to other scripts), but I have no idea how to do it. I’ve tried multiple ways to include it in the IFTTT body and within HA, but with no success (things such as using the variable term in the body, adding a field in the data_template
, etc).
If I do nothing, the HA log returns:
“Error rendering data template: UndefinedError: ‘vol_amnt’ is undefined”
Hopefully someone can help me with this
Thanks!