Roborock Valetudo RE zoned_cleanup using input_boolean buttons. (code help)

Hi, I am trying to get my xiaomi roborock vacuum running Valetudo RE to zone clean multiple zones using input_boolean buttons, using the below code. The code works when inserted into the template editor and also starts the vacuum when one zone is selected. But I am having trouble making it work with multiple zones. Any help would be great.

input_boolean:
  vac_lounge:
    name: Lounge
  vac_kitchen:
    name: Kitchen
  vac_bedroom:
    name: Bedroom
  vac_bathroom:
    name: Bathroom
  vac_study:
    name: Study

group: 
  vac:
    name: vac
    entities:
      - input_boolean.vac_lounge
      - input_boolean.vac_bedroom
      - input_boolean.vac_kitchen
      - input_boolean.vac_bathroom
      - input_boolean.vac_study

script:
  clean_xiaomi:
    alias: "xiaomi clean action"
    sequence:
      - service: vacuum.send_command
        data_template:
          entity_id: vacuum.rockrobo
          command: 'zoned_cleanup'
          params:
            'zone_ids': ["{{ expand('group.vac') | selectattr('state','equalto','on') | map(attribute='name') | list | join('\", \"') }}"]

Thanks.

You got most of the way there and thank you @K_Shot, because based on what you posted I was able to get it working.

So the issue appears to be that in a template, all template generated values are strings. If we look at the mqtt message that is published in response to your code instead of getting something like…

valetudo/rockrobo/custom_command {"command": "zoned_cleanup", "zone_ids": ["Kitchen"]}

…we instead get…

valetudo/rockrobo/custom_command {"command": "zoned_cleanup", "zone_ids": "['Kitchen']"}

…there is apparently no way to get a template to generate a list as opposed to a string.

However, there is a workaround. We can use a python_script to call the vacuum.custom_command service and have more control over the service data we send it. So to get this working we keep the same input_boolean and group configuration but also enable python_script and add a file called vac_clean.py to the config/python_scripts directory. We can then call python_script.vac_clean service which will use group.vac_rooms and vacuum.rockrobo but default but this can be changed.

configuration.yaml

python_script:

input_boolean:
  vac_living:
    name: Living
  vac_kitchen:
    name: Kitchen
  vac_hall:
    name: Hall
  vac_dining:
    name: Dining

groups:
  vac_rooms:
    entities:
    - input_boolean.vac_hall
    - input_boolean.vac_living
    - input_boolean.vac_kitchen
    - input_boolean.vac_dining

python_scripts/vac_clean.py

group = data.get("group", "group.vac_rooms")
robot_id = data.get("entity_id", "vacuum.rockrobo")

logger.info( f"Check {group}, clean with {robot_id}" )

rooms = []
for entity_id in hass.states.get(group).attributes["entity_id"]:
	if hass.states.is_state(entity_id, "on"):
		rooms.append( hass.states.get(entity_id).attributes["friendly_name"] )

logger.info( f"Cleaning {rooms}" )

data = {"entity_id": robot_id, 
		"command": "zoned_cleanup", 
		"params": {"zone_ids": rooms}}
hass.services.call("vacuum", "send_command", data )