Dynamic list of alexa devices in a script

Hello,

I have a script that takes over my TTS output to Alexa devices.
A fixed list of Alexa devices is kept ready in the script:

sequence:
    - service: notify.alexa_media
      data:
        message: "{{message}}"
        title: "{{title}}"
        target: "{{target}}"
        data:
          type: announce
          method: all
fields:
  message: []
  title: []
  target:
    selector:
      select:
        options:
          - media_player.uberall
          - media_player.erdgeschoss
          - media_player.obergeschoss
          - media_player.k68_3_firetv_r13
          - media_player.alexa_bmw
        multiple: true  
    name: Ziel
  

I would like to replace this fixed list with a template that could query Alexa devices. Then the script would be more flexible and would offer new devices automatically. I do know how to write such a template:

{{ integration_entities('alexa_media') | select('search', 'media_player\.')
 | list }}
# or with friedly_names like this:
{{ integration_entities('alexa_media') | select('search', 'media_player\.')
| map('state_attr', 'friendly_name') | list }}

But I don’t know how to put it into a format that replaces my fixed list.
Can anyone help me with this?

Best regards, Eckart

You probably shouldn’t have the friendly name, but the entity name.

But do you really new Alexa devices that often?

The Device Selector allows you to filter entities by integration (and other parameters).

No, I don’t change my alexa devices often. But I wanted to write an universal script that can bee uses by others to.

Regards, Eckart

The tip with the device selector has solved my problem - thank you very much. The code for selecting ‘target’ now looks like this:

  target:
    selector:
      device:
        filter:
          - integration: alexa_media
        entity:
          - domain: media_player
        multiple: true
    name: Ziel
    required: true

Regards, Eckart