Webhook automations based on data

Hello,
I have configured a working ifttt webhook automation to fill Google keep list (from here)

- alias: Google Keep list update from google assistant and ifttt
  trigger:
    platform: event
    event_type: ifttt_webhook_received
    event_data:
      action: call_service
  action:
    service_template: '{{ trigger.event.data.service }}'
    data_template:
      title: '{{ trigger.event.data.title }}'
      things: '{{ trigger.event.data.things }}'

I want to add another webhook to change the state of an input_boolean.
I have defined it like this on ifttt:

{ "action":"call_service", "service":"input_boolean.turn_on", "entity_id": "input_boolean.living_ac" }

However, I get an error when using the webhook, I get an error from the automation:

2019-08-23 00:30:37 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.1777890832] Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'ifttt_webhook_received', 'data': {'action': 'call
_service', 'service': 'input_boolean.turn_on', 'entity_id': 'input_boolean.living_ac', 'webhook_id': 'abcdefgh12345678abcdefgh12345678abcdefgh12345678'}, 'origin': 'LOCAL', 'time_fired': datetime.date
time(2019, 8, 22, 21, 30, 37, 147999, tzinfo=<UTC>), 'context': {'id': 'abcdefgh12345678', 'parent_id': None, 'user_id': None}}}
2019-08-23 00:30:37 INFO (MainThread) [homeassistant.components.automation] Executing Google Keep list update from google assistant and ifttt
2019-08-23 00:30:37 INFO (MainThread) [homeassistant.helpers.script] Script Google Keep list update from google assistant and ifttt: Running script
2019-08-23 00:30:37 INFO (MainThread) [homeassistant.helpers.script] Script Google Keep list update from google assistant and ifttt: Executing step call service
2019-08-23 00:30:37 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.google_keep_list_update_from_google_assistant_and_ifttt. Invalid data for call_service at pos 1
: extra keys not allowed @ data['title']

If I understand correctly, the automation expects a non-existing field “title”.
So I thought about adding a condition to the automation to ignore it if the field does not exist:

  condition:
    - condition: template
      value_template: '{% if trigger.event.data.title != none %}True{% else %}False{% endif %}'

But it doesn’t seem to work. Nor does this:

      value_template: '{% if trigger.event.data.title is not defined %}True{% else %}False{% endif %}'

what am I doing wrong?

So I found out what’s wrong. Me. After battling with it for a few hours, I was able to solve only after posting here. Anyway, this worked:

value_template: '{% if trigger.event.data.title is not defined %}True{% else %}False{% endif %}'

Also to make the 2nd part work, I needed to create a second automation, as the webhook does not work without it:

- alias: Turn on input_boolean.living_ac from 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 }}'

You had the exact same problem as me, and you found the same solution…just one question, this solution implies that every time we will receive a ifttt webhook one of the two automations will die on error and the other one will work correctly, depending on the data passed through the webhook.
That’s correct?

You can add an extra item in the body like “service”:“service1” in IFTTT then add a condition in the automation trigger looking for that item.

  condition:
    - condition: template
      value_template: "{{ trigger.event.data.service == 'service1' }}"

1 Like

Don’t know what I was missing, because I had tried putting a condition but it wasn’t working…your code is fine! Thank you so much!