Sonos sources, automatically create a script to change to source

hi all,

I’m using tile board on an old iPad and have it set up so I have a button for each of my Sonos sources. I prefer this to clicking ‘Source’ and selecting from the list.
Pressing the button runs a script, the script starts that source on the Sonos speaker.

This is obviously quite clunky as every time I want to add a new source I have to:

  1. Create a script for that source
  2. Create the button on tileboard to activate that script.

Are there any suggestions for how I might better automate this?
A way to automatically create a script if the list of sources updates? A better alternative to creating a script for each source?
Thanks

Can you please show the scripts you are using? You can probably pass over a variable to the script and use one script for all your sonos sources.

Thanks for your reply.

Here is the script I am using, from scripts.yaml:

'lofi':
  alias: LoFi
  sequence:
  - data:
      source: 'Lo-fi'
    entity_id: media_player.bedroom_sonos
    service: media_player.select_source

This is the code for the tile in Tileboard:

                 {
                   title: "Lo-fi",
                   position: [0, 1],
                   width: 1,
                   height: 0.25,
                   state: false,
                   type: TYPES.SCRIPT,
                   id: 'script.lofi',
                 },

I assume the easiest way would be to create a tile for each source, then pass the title of the tile into a generic script, but I’m not sure how to do that

I’m not familiar with Tile Board, can you send data when you execute a service call from a tile, like some parameter of the tile configuration?

I would change the script to accept a variable and then pass the source name from the tile to the script. Here is the part of the docs about passing variables to scripts.