Store custom configuration in local yaml file and retrieve it in scripts?

Hi,

At the moment, I have a lovelace page that I use to choose between 9 radio streaming. The page shows a grid of 9 buttons. Each button shows a thumbnail of one of the 9 radio stations. Each of the 9 buttons in the grid is configured basically the same, like this:

type: grid
cards:
  - type: picture
    tap_action:
      action: call-service
      service: script.switch_radio
      service_data:
        url: https://stream.rcs.revma.com/2v1zz979n98uv
        volume: 0.8
        radio_name: FG At work
        radio_title_url: fgnonstop
        radio_sub: FG Non-stop
        radio_icon: >-
          https://raw.githubusercontent.com/adumont/media/main/radios/fgnonstop.png
      target: {}
    hold_action:
      action: none
    image: https://raw.githubusercontent.com/adumont/media/main/radios/fgnonstop.png

So basically all 9 buttons call the same script. The script takes several parameters, like url, volume, radio name, radio subtitle,…

I wonder if there’s some way in HA (natively or via a HACS add-on?) to create a custom config file, in which I could define something like this:

radios:
   radiofg:
      url: 
      volume:
      radio_icon:
      radio_name: "Radio FG"
      radio_subtitle: "..."
   radiofgstarter:
      url: 
      volume:
      radio_icon:
      radio_name: "FG Starter"
      radio_subtitle: "..."
   radio3:
      url: 
      volume:
      radio_icon:
      radio_name: "..."
      radio_subtitle: "..."
...

Hopefully you get the idea. And then the idea would be to be able to call the script by just passing the name of the radio object in the webradio array:

something like this:

type: grid
cards:
  - type: picture
    tap_action:
      action: call-service
      service: script.switch_radio
      service_data:
        radio: radiofg
    hold_action:
      action: none
    image: https://raw.githubusercontent.com/adumont/media/main/radios/fgnonstop.png

So I’d like to pass just enough so the script would be able to “somehow” (how?) retrieve all the attributes of the radio it receives as argument (variable radio)

maybe somtheing like {{ webradio[radio].url }}, {{ webradio[radio].radio_icon }}, {{ webradio[radio].radio_name }}

Why I’d like that?

Right now I have these grid with radio in several pages in lovelace, pages are different for different users, each one see his page. When I need to change the attributes of soe radios (change the url thumbnail, or subtitle, name, …) I need to go to each one of them. Also I have automations that call the same script (to launch a radio at certain time,…). At the moment I have all the attributes hardcoded in each place that actually call the script instead of being able to factor them in one place.

Also I’d like to be able to maybe launch a random radio from an automation, which I could do with something like {{ [ radiofg, radio3 ] | random }} , so just pass the name of the element in the webradio array, so I can pass it to the script which will retrieve all the needed parameters…

Is there any way to achieve that in HA?

Maybe macros in this?

It does require you to use Lovelace yaml mode though.

I believe this would be handy to describe the Lovelace UI in terms of Yaml files and maybe use loops to represent the 9 buttons in just one piece of code, but I think it doesn’t answer the need I have to store my radios configurations in a file. Thanks anyways, as it can definitely be interested to solve other situations.