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