How do I pass data from button to script?

I’m trying to pass, without success, data from buttons to a script. I have 8 buttons that turn on a media player (a tuner) and select a preset. All works well. I wanted to include setting the volume (possibly a different volume for different presets).

I have a script for each button and that works. However, better would be one script that is called by the 8 buttons but receives the appropriate data; the preset number (1-8) and the volume (0-1) from each button press.
I’ve tried using fields in scripts without success (and, tbh, not much clue about what I’m doing!).
Any ideas??

This is one of the scripts

alias: OnVol 621
sequence:
  - action: media_player.play_media
    target:
      entity_id: media_player.rx_a740_main
    data:
      media_content_id: tun:preset:1
      media_content_type: music
    metadata:
      title: 621
      thumbnail: null
      media_class: music
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: ""
          media_content_id: tun:presets
  - action: media_player.volume_set
    metadata: {}
    data:
      volume_level: 0.45
    target:
      entity_id: media_player.rx_a740_main
description: Turn on 621, set Volume
icon: mdi:radio

and the yaml for the 8 buttons

type: vertical-stack
cards:
  - type: grid
    columns: 4
    square: false
    cards:
      - show_name: true
        show_icon: false
        type: button
        name: "621"
        tap_action:
          action: perform-action
          perform_action: script.onvol_621
      - type: button
        show_name: true
        show_icon: false
        name: "594"
        tap_action:
          action: perform-action
          perform_action: script.onvol_594
      - type: button
        show_name: true
        show_icon: false
        name: "774"
        tap_action:
          action: perform-action
          perform_action: script.onvol_774
      - type: button
        show_name: true
        show_icon: false
        name: ABC FM
        tap_action:
          action: perform-action
          perform_action: script.onvol_abc_fm
      - type: button
        show_name: true
        show_icon: false
        name: 3BA FM
        tap_action:
          action: perform-action
          perform_action: script.onvol_3ba_fm
      - show_name: true
        show_icon: false
        type: button
        name: ABC Classic
        tap_action:
          action: perform-action
          perform_action: script.onvol_abc_classic
      - show_name: true
        show_icon: false
        type: button
        name: Power FM
        tap_action:
          action: perform-action
          perform_action: script.onvol_power_fm
      - show_name: true
        show_icon: false
        type: button
        name: JJJ
        tap_action:
          action: perform-action
          perform_action: script.onvol_jjj
grid_options:
  columns: 12
  rows: auto

Yes, thanks didgeridrew, I have been there and, sure, I can add fields to the script. My question is how are the parameters (variables) passed to the script by the button on a tap_action?

I’m guessing it’s something like:

type: button
show_name: true
show_icon: false
name: "594"
tap_action:
  action: perform-action
  perform_action: script.onvol_master
  data:
    preset: "tun:preset:1"
    volume: 0.45

But it’s hard to say exactly without know which values you are changing between the different scripts. The following is a best guess, but I have never used the Yamaha integration, so there may be some requirement in the media player action that I am unaware of.

alias: OnVol Master
fields:
  preset:
    name: Preset
    description: ""
    example: "tun:preset:1"
    selector:
      text:
  volume:
    name: Volume
    description: ""
    default: 0.4
    selector:
      number:
        min: 0
        max: 1
sequence:
  - action: media_player.play_media
    target:
      entity_id: media_player.rx_a740_main
    data:
      media_content_id: "{{ preset }}"
      media_content_type: music
  - action: media_player.volume_set
    metadata: {}
    data:
      volume_level: "{{ volume }}"
    target:
      entity_id: media_player.rx_a740_main
description: Turn on Selected Preset, set Volume
icon: mdi:radio

The fields block is optional, but helpful. If you wanted, you could set up a Select Selector so that you have a predefined list of presets to choose from instead of having to type the out.

Thanks again for the follow-up - it’s now working !
The preset data ( eg tun:preset:1) only works if not in quotes
(fyi, the only data that was changing in the multiple scripts was volume & preset)

Button

show_icon: false
type: button
tap_action:
  action: perform-action
  perform_action: script.onvol_master
  data:
    vol: 0.47
    preset: tun:preset:1
name: "621"
grid_options:
  columns: 2
  rows: 1

Script

sequence:
  - action: media_player.play_media
    data:
      media_content_id: "{{ preset }}"
      media_content_type: music
    target:
      entity_id: media_player.rx_a740_main
  - action: media_player.volume_set
    data:
      volume_level: "{{ vol }}"
    target:
      entity_id: media_player.rx_a740_main
fields:
  vol:
    name: Volume
    description: ""
    default: 0.45
    selector:
      number:
        min: 0
        max: 1
        step: 0.01
  preset:
    selector:
      text: null
    name: Preset
    default: tun:preset:1
description: Turn on tuner, set Volume
icon: mdi:radio