Script with passed field / list (multiple label selection) not working

Hi probably something very simple - but I try now already for houres:

My script should get a list of labels (I love the new labels) and run some services with it.

Here is an example with a single service:

alias: set_sonnenschutz
fields:
  labels:
    selector:
      label:
        multiple: true
    name: Label_Test
    required: true
sequence:
  - alias: Set tilt
    service: cover.set_cover_tilt_position
    target:
      label_id: '{{ labels }}'
    data:
      tilt_position: 60

no matter what I try it gives me an error, I tried for the target: lable_id:

label_id: '{{ labels }}'
label_id: '{{ labels | string }}'
label_id: '{{ labels | list}}'
label_id: '{{ labels | join('', '') }}'

I call it as (created in the UI / dev tools / services) :

service: script.1714122790820
data:
  labels:
    - rechts
    - vorne

And always get errors like:

with this additional but wrong “list dash”

  target:
    label_id:
      - - rechts
        - vorne

Hard coding it like:

    service: cover.set_cover_tilt_position
    target:
      label_id: 
        - rechts
        - vorne
    data:
      tilt_position: 60

works fine.

Regarding this result:

target:
    label_id:
      - - rechts
        - vorne

It created a list whose first item is the list you passed to it. In other words, regardless of what you pass to it (a string, list, or even dictionary), it simply becomes the first item of a list.

I’m not sure if that’s intentional or a bug but it makes passing lists to label_id ineffective. It seems like a bug so I suggest you report it as an Issue in Home Assistant’s GitHub Core repository.

@mhoff did you ever report this as a bug? I do have the same issue and would open a bug if not already present.

Here is a minimum working example for reference including the trace:

alias: Cover open / close (Duplicate)
sequence:
  - data: {}
    action: cover.close_cover
    target:
      device_id: '{{ f_cover_device }}'
fields:
  f_cover_device:
    selector:
      device:
        multiple: true
    required: true
    default: # make sure to add two devices here - can be anything I used a covers as example
      - c042fda57770a7f83072e84315a5357f
      - 35f58faa396ee578fba25b18413c0304
description: ''
icon: mdi:window-shutter

Trace Step details

Executed: January 5, 2025 at 11:55:51
Error: template value should be a string @ data['device_id'][0]
Result:

params:
  domain: cover
  service: close_cover
  service_data: {}
  target:
    device_id:
      - - c042fda57770a7f83072e84315a5357f
        - 35f58faa396ee578fba25b18413c0304
running_script: false

Full trace: trace script.cover_open_close_duplicate 2025-01-05T10_55_51.170362+00_00 · GitHub