Service data template not evaluating when being passed to a called script

I’m trying to set it up when button is pressed the script is called with the “media_content_id” is populated with state of input select. However it just seems to send the whole command instead of evaluating the state. The input select contains a list of sound names. The weird thing is when I call the script with same data it works perfectly.

lovelace card:

type: vertical-stack
cards:
  - type: entities
    entities:
      - input_text.tts_fire_tv
      - input_select.alexa_sound_list
  - type: grid
    columns: 2
    square: false
    cards:
      - show_name: true
        show_icon: true
        type: button
        icon_height: 20px
        tap_action:
          action: call-service
          service: script.play_sound_fire_tv
          data:
            media_content_id: '{{ states("input_select.alexa_sound_list") }}'
          target: {}
        icon: mdi:surround-sound
      - show_name: true
        show_icon: true
        type: button
        icon_height: 20px
        tap_action:
          action: call-service
          service: script.play_tts_fire_tv
          data:
            message: '{{ states("input_text.tts_fire_tv") }}'
          target: {}
        icon: mdi:account-voice

play_sound_fire_tv script

sequence:
  - service: media_player.play_media
    data:
      media_content_type: sound
      media_content_id: "{{ media_content_id }}"
    target:
      entity_id: media_player.bedroom_alexa_fire_tv
mode: single
alias: Play Sound Fire TV

Most core dashboard cards, like the entities card, do not support templating.

You can send the entity id of the input_select and evaluate it in the script (which does support templates).

        tap_action:
          action: call-service
          service: script.play_sound_fire_tv
          data:
            media_content_id: 'input_select.alexa_sound_list'
sequence:
  - service: media_player.play_media
    data:
      media_content_type: sound
      media_content_id: "{{ states(media_content_id) }}"
    target:
      entity_id: media_player.bedroom_alexa_fire_tv
mode: single
alias: Play Sound Fire TV

Additionally, unless things have changed, I believe the tap-action service call, wants service_data: rather than just data: for some inexplicable reason.

I think that has changed to use either now.

1 Like

Ah fair enough that’s a bit of a bummer. The main reason I wanted to have the template there is because the script is also into some automation which just have plain text being passed. Is there an easy way to handle both cases?

Sure. Use your original method and this:

https://community.home-assistant.io/t/100-templatable-lovelace-configurations/105241

Damn there really is an addon for anything. Thanks for the help.