Combine values in script

Hey, i’m pretty new in this and I have a little problem that I’m sure you guys will be able to solve for me :wink:

What I’m trying to do is to execute a script that will send my roborock to vacuum selected rooms. I have input_boolean defined for each room. When executing commands I want to combine the input_booleans that are in ON sate and generate a “params” property of the command.

If I paste the code bellow to the template editor everything looks fine. Even if I execute the command in developer tools it works fine (i set the params to: [1,3,]). But when the script is executed via button I get an error: Unable to send command to the vacuum: {‘code’: -10000, ‘message’: ‘data for segment is not a number’}

vacuum_rooms:
  alias: Vacuum Rooms
  sequence:
  - data:
      entity_id: vacuum.roborock
      command: app_segment_clean
      params: >
        [{% if is_state('input_boolean.clean_kitchen', 'on') %}1,{% endif %}{% if is_state('input_boolean.clean_hallway', 'on') %}2,{% endif %}{% if is_state('input_boolean.clean_bedroom', 'on') %}3,{% endif %}]
    service: vacuum.send_command

Thanks for the help!

data_template

Thank you !

1 Like

Any idea why this gets the same error message?

'25487631215487613545':
  alias: 'Vacuum hall '
  sequence:
  - service: vacuum.send_command
    data_template:
      entity_id: vacuum.robby
      command: app_segment_clean
      params: >
        [{% if states('input_number.vacuum_repeats') | int == 1 %}
          18, 23
        {% elif states('input_number.vacuum_repeats') | int == 2 %}
          18, 18, 23, 23
        {% elif states('input_number.vacuum_repeats') | int == 3 %}
          18, 18, 18, 23, 23, 23
        {% endif %}]
  - service: input_boolean.turn_off
    data:
      entity_id: input_boolean.robby_is_empty