Roborock Integration with Q Revo Vacuum / Mop - Segment cleaning

I use send_command in my automation and it works (see snippet of automation below)

service: vacuum.send_command
data:
  command: app_segment_clean
  params:
    - segments:
        - 16
        - 17
        - 18
        - 19
        - 20
        - 21
      repeat: 2
target:
  entity_id: vacuum.roborock_q_revo

But the script does not work with send_command (see below)

alias: Run Vacuum
sequence:
  - service: vacuum.send_command
    data_template:
      command: app_segment_clean
      params:
        - segments: |
            {%- for rooms in state_attr('sensor.roborock_rooms','rooms') -%}
            {% if is_state(rooms.boolean,'on') %}
             - {{ rooms.id }}
            {%- endif %}
            {%- endfor %}
    target:
      entity_id: vacuum.roborock_q_revo
mode: single
icon: mdi:robot-vacuum