Trouble with templating (using IFTTT ingredients in script)

Hey there,

So I set up an IFTTT event that I can call with my Google Home, that creates a webrequest to my HA to trigger a script. I am using the $ text ingredient with IFTTT and want to pass it to my script. I found this post to be helpful, but I still don’t get my script running correctly.

This is my IFTTT setup

This is my script “saugen”. As you can see, it should pass the list [26500, 20500,29000, 23000, 1] to the vacuum no matter what. The problem is: the vacuum does not get the list. If I call the script without the templating (just with the list) it works perfectly. But of course my goal is to set up different rooms with different coordinates, depending on which room I give to my Google Home. I bet I have just a stupid tiny mistake in there, since this is my first time using templates. My script:

saugen:
  alias: test
  sequence:
  - data_template:
      command: app_zoned_clean
      entity_id: vacuum.mozart
      params: >
        {% if (raum == "Küche" or raum == "küche") %}
          [[26500, 20500,29000, 23000, 1]]
        {% else %}
          [[26500, 20500, 29000, 23000, 1]]
        {% endif%}
    service: vacuum.send_command

Thanks,
ciB

It seems like (correct me if I am wrong) that a template cannot output a list since it’s always a string.

So what I did is created another script that is called which already has the parameters that I need.

There is a workaround to pass a list through a template though if you create it like this:

List:
  - item
  - item
  - item

And lists within lists:

List:
  - - item
    - item
    - item
  - - item
    - item
    - item

But unfortunately the latter one does not work. No idea why, maybe it’s a bug.

  - data_template:
      command: app_zoned_clean
      entity_id: vacuum.mozart
      params: >
        {% if (raum == "Küche" or raum == "küche") %}
          {% set values = [26500, 20500, 29000, 23000, 1] %}
        {% else %}
          {% set values = [26500, 20500, 29000, 23000, 1] %}
        {% endif%}
        {%- for value in values %}
          {{- value }},
        {% endfor %}

Can’t return a list inside a list which is what you are doing when you use [[ ]]. I believe the way I posted will work for you. You may need to remove the comma in the {{- value}}, line. I always forget if that’s needed or not.

Unfortunately this didn’t work, with or without the “,”.

what does your vacuum except? What is the shape of the data object if you were to avoid using templating?

The vacuum needs a list of coordinates and how often it should clean the area. But since the vacuum accepts multiple zones at once to be cleaned, I have to pass the list in a list - even if there is just one zone in it, hence

[[x1,y1,x2,y2, iterations]]

another example with more than one area/zone to be cleaned:

[[x1,y1,x2,y2, iterations], [x1,y1,x2,y2, iterations]]

Yes but do you have a working automation in YAML form that just uses a data object? Here’s an example of what I’m looking for:

data:
  command: app_zoned_clean
  entity_id: vacuum.mozart
  params:
    - something_that_is_correct

oh sure, sorry

saugen:
      alias: "Küche saugen"
      sequence:
        - service: vacuum.send_command
          data:
            entity_id: vacuum.mozart
            command: app_zoned_clean
            params: [[26500, 20500, 29000, 23000, 1]]

But it does not work if I use it like this (which should work according to this documentation):

saugen:
      alias: "Küche saugen"
      sequence:
        - service: vacuum.send_command
          data:
            entity_id: vacuum.mozart
            command: app_zoned_clean
            params: 
              - - 26500
                - 20500
                - 29000
                - 23000
                - 1

My mistake, documentation is faulty, works with:

saugen:
      alias: "Küche saugen"
      sequence:
        - service: vacuum.send_command
          data:
            entity_id: vacuum.mozart
            command: app_zoned_clean
            params: 
              - 
                - 26500
                - 20500
                - 29000
                - 23000
                - 1 

I think that way I can pass it through the template now.

This works, although this is ofc a very nice, manageable solution. I probably just stick to using a seperate script for each room/area.

 saugen:
          alias: "Saugen"
          sequence:
            - service: vacuum.send_command
              data_template:
                entity_id: vacuum.mozart
                command: app_zoned_clean
                params:
                   - 
                      - "{% if (raum == 'Küche' or raum == 'küche') %}26500{% endif %}"
                      - "{% if (raum == 'Küche' or raum == 'küche') %}20500{% endif %}"
                      - "{% if (raum == 'Küche' or raum == 'küche') %}29000{% endif %}"
                      - "{% if (raum == 'Küche' or raum == 'küche') %}23000{% endif %}"
                      - 1