Is there a maximum characters allowed for incoming IFTTT JSON bodies?

Hello,

I have IFTTT up and running for various automations and switches inside HASSIO, but for my first “Input Select” entity I am having a drop off of data from IFTTT webhooks in the service call JSON.

I am having Google assistant accept a text ingredient and plug it into the JSON body for input_select.select_option.

Here is the webhook JSON:
{ "action": "call_service", "service": "input_select.select_option", "entity_id": "input_select.light_color", "option":"blue" }

Fires the following error in Hassio:
Invalid service data for input_select.select_option: required key not provided @ data['option']. Got None

If I change the JSON data to a “input_select.select_next” it fires properly inside HASSIO.

After some troubleshooting I have found that this error fires if the “option” data is not included in the JSON service call. If I leave “option”:"[blank]" it will give a different error that lists all available options. And pasting the last two data portions of my webhooks code into the services dev tool creates the correct response in HASSIO.
This tells me that the webhook JSON body is not transmitting the entire “option”:“blue” portion.
I am wondering if HASSIO can only take in so much JSON data, or IFTTT webhooks can only send so much. That doesn’t sound right or logical to me though.

I have thought of some other ways around this problem to create the automations I need, but I would still like to solve this problem instead of going around it.

Edit: Now I’m considering the likelihood that my IFTTT automation needs more templating to read the rest of the data (option) coming in from the webhook.

Thank you

1 Like

option needs to be under data, so your JSON would need to look like this:

{"action": "call_service", "service": "input_select.select_option",
"entity_id": "input_select.light_color", "data": {"option":"blue"}}

Thank you very much Bruckner. I see you all around here tossing out knowledge.

Can I ask you what aspect of Hass docs I maybe should have read to figure this out?

Thanks again.

edit:
Spoke too soon. IFTTT throws an error in saving the applet due to the extra {}'s around the “data” set. i know its not HASS related, but do you have any recommendations?

Bummer,

Got IFTTT to accept the extra brackets through the Maker/Platform set and pasted your code in. Hassio gives same error.
Do I have to add or change my service or data template that sits inside the IFTTT webhook automation to parse the data further?

I have zero programming experience, sorry if my jargon is wrong.

Coincidentally, I just helped someone else with a very similar issue. I think I might have steered you wrong. (I.e., made a bad assumption.)

Can you post whatever you have that responds to that IFTTT request? (In the other topic there was an automation that indirectly called the requested service and pass the data to it. Do you have something similar?)

This is the code inside my automations.yaml that I assume parses IFTTT’s webhook JSONs

- alias: iftt_auto
  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 }}'

Thanks Bruckner

Got it to work.

Added to Automation.yaml

  action:
    service_template: '{{ trigger.event.data.service }}'
    data_template:
      entity_id: '{{ trigger.event.data.entity_id }}'
      option: '{{ trigger.event.data.option}}'

And re-wrote the JSON data to my original

{"action": "call_service", "service": "input_select.select_option",
"entity_id": "input_select.light_color", "option":"blue"}

Bruckner, if you have the time, can you briefly say when a situation would need the {} inside the JSON {} like we originally thought was the problem.

Thanks a ton

That’s probably because IFTTT sees double curly braces as a special sequence. I probably should have had {... "data": {"option":"blue"} } (i.e., with a space between them) so IFTTT didn’t treat them as a special sequence. But, of course, as we found, this wasn’t the right solution anyway.

This was the first time I ever saw this new HA webhook used, so I had assumed incorrectly how it worked. I thought the JSON needed to look more like the corresponding YAML, in which case, option needed to be “under” data. Now I think I see how it really works.

I’ll go out on a limb and chance making another mistake, but I think you might actually want your automation to look like this:

- alias: iftt_input_select.select_option
  trigger:
    platform: event
    event_type: ifttt_webhook_received
    event_data:
      action: call_service
      service: input_select.select_option
  action:
    service: input_select.select_option
    data_template:
      entity_id: '{{ trigger.event.data.entity_id }}'
      option: '{{ trigger.event.data.option}}'

This makes this automation only work for this one service, since the option parameter is pretty unique to it. If you were using the automation with other services (e.g., that only used entity_id as data), then you might want to add back the original automation so those still work.