I’m looking to send a Google Assistant request to vacuum a certain room in my house, via IFTTT.
Everything seems to be working so far, except for the conditional if statements.
(The end goal will be to send a service request with the room’s ID number)
My automations file
- id: this_is_the_automation_id
trigger:
- platform: event
event_type: ifttt_webhook_received
event_data:
action: vacuum_room
action:
- service_template: '{{ trigger.event.data.service }}'
data_template:
message: >
{% if '{{ trigger.event.data.message }}' == 'the laundry' %}
L
{% elif '{{trigger.event.data.message}}' == "the kitchen" %}
K
{% else %}
'{{ trigger.event.data.message }}'
{% endif %}
I’ve only just started looking into Templating, and don’t fully understand the syntax, but can’t seem to get any of the data messages to match, but can spit out the data message in the else statement.
I’ve looked around for different templating examples and tried different combinations of quotation levels etc., but I’m sure there’s something fundamental I’m missing in the syntax or misunderstanding about templating.
Would be grateful if someone could steer me in the right direction - cheers!
It’s possible to use a dictionary but you already have working code so there’s no pressing need to change it. What I would suggest is that you append a final else to the long if-elif chain to handle the case where there is no match found (i.e. it needs a default value). Currently, it produces no value in that situation which is not likely to be acceptable to the service call.
Please consider marking my post (above) with the Solution tag (only you, the author of this topic, can do that). It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions about webhooks and templating the trigger variable.