Passing multiple choices to a script

Hi all.
I’ve read some other posts and the documentation but I’m afraid still being very new to this it’s still not clear what I’m doing wrong. If I run a test, it says run successfully but nothing is coming through. I’ve pieced the structure together from parts that the UI created and other posts. I don’t know if this is causing problems due to the fact that I’m trying to pass multiple options to an entity_id .
Any help or further docs to read would be appreciated.
Thanks
Alan

Automation:

service: script.notify_chosen_google_devices
data:
  devices:
    - media_player.gh_chef
  message: test 1 2 3

Script:

alias: Notify Chosen Google Devices
description: Send message to specific chosen google devices
icon: mdi:speaker-multiple
fields:
  message:
    selector:
      text: null
    name: Message
    description: What is the message to announce on a specific speaker
    required: true
  devices:
    selector:
      entity:
        domain: media_player
        multiple: true
    name: Devices
    description: What google devices do you want to run on
    default:
      - media_player.gh_chef
      - media_player.gh_main
      - media_player.gh_lunar_lander
      - media_player.gh_sleepy
      - media_player.gh_toto
    required: true
sequence:
  - service: tts.speak
    target:
      entity_id: tts.google_en_com
    data_template:
      cache: false
      media_player_entity_id: "{{devices}}"
      message: "{{message}}"
# The following is just to stop the cast icon from staying
  - wait_template: "{{ is_state("{{devices}}", 'idle') }}"
  - service: media_player.turn_off
    target:
      entity_id: "{{devices}}"
    data: {}

This is an example of a script that takes 3 variables, ‘counter’, ‘targetid’ and transition.

The automation:-

service: script.colour_loop_lights
data:
  counter: 0
  targetid: light.moes_rgb_bulb_first_floor_hall_light
  transition: 1
enabled: true

And the script that then uses them:-

alias: Colour Loop Lights
sequence:
  - if:
      - condition: template
        value_template: "{{ counter is not defined or counter == 0 }}"
    then:
      - stop: Counter is zero
  - if:
      - condition: template
        value_template: "{{ targetid is not defined  }}"
    then:
      - stop: No target entity id provided
  - repeat:
      count: "{{ counter }}"
      sequence:
        - service: light.turn_on
          data_template:
            xy_color: "{{ colours[((startingseed+repeat.index) % (colours | count))] }}"
            transition: "{{ transition if transition is defined else 1 }}"
          target:
            entity_id: " {{ targetid }}"
        - delay:
            milliseconds: "{{ (transition*1000) if transition is defined else 1000 }}"
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
variables:
  colours: |-
    {{ [[0.217,0.077], [0.157,0.05], [0.136,0.04], [0.137,0.065],
        [0.141,0.137], [0.146,0.238], [0.151,0.343], [0.157,0.457],
        [0.164,0.591], [0.17,0.703], [0.172,0.747], [0.199,0.724],
        [0.269,0.665], [0.36,0.588], [0.444,0.517], [0.527,0.447],
        [0.612,0.374], [0.677,0.319], [0.701,0.299], [0.667,0.284],
        [0.581,0.245], [0.477,0.196], [0.385,0.155], [0.301,0.116]] }}
  startingseed: "{{range(0,(colours | count)-1) | random}}"
mode: parallel

You should be able to figure out from this how the variables are passed and then used.

1 Like

Thanks for helping :slight_smile:. I’ll give it a look over when I’m free again.

You can see my implementation in my script blueprint for all supported TTS in my blueprint link in the message footer.
That does pretty much exactly your example and you are free to copy what you like.

Many of my other scripts there also use fields.

I don’t see what’s wrong with yours, it’s very close. You can test these in developer - services.
Open your Home Assistant instance and show your service developer tools.

1 Like

Thanks for the reply.
Sorry, being extremely noobish here but I can’t see any link in the footer. The only link points to my local home assistant developer tools.

The blue words in the bottom of every one of my messages…
image

Image below just to show I’m not totally losing my mind (don’t ask my wife that question). I’ll try on pc later as no luck on my phone.