Notify.alexa_media from lovelace with custom:button-card?

Hi everybody,

can you please help me fix my template? I am trying to create a card that will allow me to

  1. Input some text
  2. select a device
  3. have the selected device speak this text

This is the code

type: vertical-stack
cards:
  - type: entities
    entities:
      - entity: input_text.helper_ttstext
      - entity: input_select.helper_tts_devices
    title: Alexa Jonna
    show_header_toggle: false
  - type: 'custom:button-card'
    entity: input_text.helper_ttstext
    name: Abschicken
    tap_action:
      action: call-service
      service: notify.alexa_media
      service_data:
        target: |
          [[[
            states('input_select.helper_tts_devices').state;
          ]]]
        message: |
          [[[
            states('input_text.helper_ttstext').state;
          ]]]
        data:
          type: tts

Previously I had only one single media_player entity hard coded into this; this used to work. I also used this instead of the code above

        message: "{{ states('input_text.helper_ttstext') }}"

I tried using the same kind of syntax for target, but no success. So I looked at the button-card docs and changed to this syntax in the code quoted first.

Can you please help me fix my code so that I can pick text and device and send it from lovelace?

Thank you in advance for your help :slight_smile:

The template syntax is not the same between Jinja (template engine inside home assistant) and JS (template engine inside the custom button card).

Change your () to [], add return and end the line with a ;.

[[[
  return states[...].state;
]]]
1 Like

Thank you :slight_smile:

Iā€™m trying to follow this to create a custom:button-card that makes an announcement based on whatever speaker I select. This is what I wrote:

type: vertical-stack
cards:
  - type: entities
    entities:
      - entity: input_text.announcement_speaker
  - type: 'custom:button-card'
    icon: mdi:speaker
    name: " "
    tap_action:
      action: call-service
      service: tts.google_say
      service_data:
        entity_id: |
          [[[ 
            states['input_text.announcement_text'].state;
          ]]]
        message: "This is a test"

This is the error I get:

Failed to call service tts/google_say. required key not provided @ data['entity_id']

What am I missing?