Dashboard script widget with args

Hello out there!

I just wondered if it’s possible to use the script widget and pass some arguments to the script? I couldn’t find a documented solution for this purpose. Does anyone know how to do this?
If not, I’VE GOT A FEATURE REQUEST :slight_smile:

Best,
Matthias

isnt possible if i am correct, and i dont think its possible in HA also.

Well, in HA this works.

Example:

    mediaplayer_play_radio:
        alias: 'play radio station'
        sequence:
          - service: media_player.play_media
            data_template:
              entity_id: '{% if player_entity_id %}{{ player_entity_id }}{% else %}{{ group.media_player }}{% endif %}'
              media_content_type: 'playlist'
              media_content_id: 'http://...'

I can use the script passing over the entity_id for the media player as an argument:

    - service: script.mediaplayer_play_radio
      data:
          player_entity_id: media_player.player01

but you cant create a button where you can give an argument.

Okay, than this is my feature request :slight_smile: When calling a script make it possible to pass over a predefined argument.
Example: Pressing button “Play Radio” calls the script “mediaplayer_play_radio” and passes entity_id “media_player.player01” to it :slight_smile:

create different scrits that call that one scrits with different arguments and connect the dashboard to the different scripts.
that works the same and is possible already :wink:

and there is little difference between hardcoding an option at one place or another :wink:

Well, in the example above this would require to have a single script for each media_player and for each radio station. This does not sound very comfortable to me.
Being able to define the media_player entity_id (together with the radio station) with the button seems the smarter and more minimalistic approach to me :slight_smile:

then i think you have to wait untill custom widgets are there :wink:

but i dont see much difference between:

    - service: script.mediaplayer_play_radio
      data:
          player_entity_id: media_player.player01
    - service: script.mediaplayer_play_radio
      data:
          player_entity_id: media_player.player02

or extra lines in the dash file.

you also could create a very small app like

initialize(...):
  listen_state(self.callback,self.args["input_boolean"]
callback(self,...):
  self.call_service(self.args["script"],data=self.args["data"])

create an input_boolean for every dashboard button you like and put that in the cfg.

yeah you need to create an input boolean AND a widget instead of only a widget, but it does the trick.

If the options could be represented by a input_select, would that work?
Does it pop up a UI to select a different mode?
mode that shows as active, not sure I follow?
How does script tie into this?
Could be way off, if so just let me know …

mode

A widget to track the state of an input_select by showing active when it is set to a specific value. Also allows scripts to be run when activated.

Mandatory Arguments

entity - the entity_id of the input_select
mode - value of the input select to show as active
script - script to run when pressed
state_text
state_map
1 Like

didnt know that the select also could trigger a script.
that should be what he is looking for i guess.

Same problem here - you cannot post an argument to the script.
I’d like to hand over two variables at this point.
Let me give an example config:

mediaplayer_play_radio:
  widget_type: script
  entity: script.mediaplayer_play_radio
  title: 'Radio'
  data:
    entity_id: media_player.player01
    radio_station_token: 'myradiostation'

That’s the way it would offer the possibility to define the buttons particular action. I’d like to prevent using a single script for each media_player entity and for each radio station for each media_player as its possible at the moment.
So handing both informations over with the button data would be pretty cool. I hope you can understand my purpose :slight_smile:

Thanks for your support guys!

i see 1 other option for it.

2 input selects that contain the entity ids and the radiostation tokes
1 input boolean to turn it on and of.
1 small app that starts what you want based on the 2 input selects.

that way you dont have to create a big amount of buttons, so i see it as a better way any way.
if you only want to create 3 buttons then it wouldnt be worthwhile anyway, so i guess you want a lot of buttons.
and that can be avoided with 2 input selects

Hi,

take a look here: New widget: Remote controller button custom widget you should be able to do what you want.

1 Like

I am right that this is still not possible out of the box?