Script not working with multiline template

Hello.
I cant understand why this code doesn’t work.
Could you help me, please.

service: xiaomi_miot.call_action
data:
  entity_id: vacuum.ijai_robot_cleaner
  siid: 7
  aiid: 9
  params:
    - >
      {%- set data = namespace(rooms=[]) -%}
      {%- if is_state('input_boolean.clean_kitchen','on') -%}
      {%- set data.rooms = data.rooms + ['\\"1_10_1_2_1_1_1_1\\"'] -%}
      {%- endif -%}
      {%- if is_state('input_boolean.clean_bedroom','on') -%}
      {%- set data.rooms = data.rooms + ['\\"1_11_1_2_1_1_1_1\\"'] -%}
      {%- endif -%}
      "[{{ data.rooms|join(',') }}]"
    - 1111111

I’am trying to get this working script:

service: xiaomi_miot.call_action
data:
  entity_id: vacuum.ijai_robot_cleaner
  siid: 7
  aiid: 9
  params:
    - "[\"1_10_1_2_1_1_1_1\",\"1_11_1_2_1_1_1_1\"]"
    - 1111111

When I’am trying to test my code using templates in developer tools, I get this result:

service: xiaomi_miot.call_action
data:
  entity_id: vacuum.ijai_robot_cleaner
  siid: 7
  aiid: 9
  params:
    - >"[\"1_10_1_2_1_1_1_1\",\"1_11_1_2_1_1_1_1\"]"
    - 1111111

It looks like there’s an extra character “>”. How can I exclude it?

Maybe this is a problem in the integration implementation, where the params array is analyzed?

Implementation should ignore “>”, “>-”, “|” and “|-” symbols at the begining of line?

No it is a problem with your syntax. The multi line character can only appear between a key and value pair, so something like this:

  params:
    - param_1: >
        {%- set data = namespace(rooms=[]) -%}
        {%- if is_state('input_boolean.clean_kitchen','on') -%}
        {%- set data.rooms = data.rooms + ['\\"1_10_1_2_1_1_1_1\\"'] -%}
        {%- endif -%}
        {%- if is_state('input_boolean.clean_bedroom','on') -%}
        {%- set data.rooms = data.rooms + ['\\"1_11_1_2_1_1_1_1\\"'] -%}
        {%- endif -%}
        {{ data.rooms|join(',')|list }}
    - param_2: 1111111

You could put the whole template after “params” but the template would return a string that looks like a list:

  params: >
      {%- set data = namespace(rooms=[]) -%}
      {%- if is_state('input_boolean.clean_kitchen','on') -%}
      {%- set data.rooms = data.rooms + ['\\"1_10_1_2_1_1_1_1\\"'] -%}
      {%- endif -%}
      {%- if is_state('input_boolean.clean_bedroom','on') -%}
      {%- set data.rooms = data.rooms + ['\\"1_11_1_2_1_1_1_1\\"'] -%}
      {%- endif -%}
      {{ [data.rooms|join(',')|list,  1111111] }}
1 Like