alexa_media_player: Notify.alexa_media does not work with groups (or any non alexa_media entities).

IMPORTANT: Please search the issues, including closed issues, and the FAQ before opening a new issue. The template is mandatory; failure to use it will result in issue closure. ✅

According to the wiki on tts, I should be able to target rooms, serialnumbers (for echo device for example) and other groupings, but it does not seem to work, except if the target is the alexa_media entity itself.

I crated a script to facilitate TTS action via a button in the dashboard and this is how it looks:

sequence:
  - action: notify.alexa_media
    data_template:
      title: Alexa Speak...
      data:
        type: tts
      message: "{{message}}"
      target: |
        [
          {%- for key, values in targets.items() -%}
            {%- if values is string -%}
              "{{ values }}"
            {%- else -%}
              {%- for value in values -%}
                "{{ value }}"{% if not loop.last %}, {% endif %}
              {%- endfor -%}
            {%- endif %}
          {%- if not loop.last %}, {% endif %}
          {%- endfor -%}
        ]
alias: Echo talk
description: ""
fields:
  message:
    selector:
      text: null
    name: Message
    required: true
  targets:
    selector:
      target:
        entity:
          domain: media_player
          integration: alexa_media
    name: Targets
    description: Select Amazon Echo devices or areas to send your message to
    required: true
    default:
      entity_id: media_player.echo_main
mode: queued
max: 15

It was already tricky to get this to work at all, because the direct output of a target selector has an extra level in the result. Example:

Image

params:
  domain: notify
  service: alexa_media
  service_data:
    title: Alexa Speak...
    data:
      type: tts
    message: test
    target:
      area_id: office
  target: {}

Ended up with that ugly templating, difficult to figure out, because the result of the selector has a different type if it is a single item (string), or multiple (dictionary). Having the right template in place, I was able to have it output the way the integration expects it (or at least matches the format in the example):

params:
  domain: notify
  service: alexa_media
  service_data:
    title: Alexa Speak...
    data:
      type: tts
    message: test
    target:
      - office

But that doesn’t work. My assumption is that it would do an expansion, similar to what the UI does. If I do expand in the UI (have to expand twice, as the echo device directly also doesn’t work. room -> device -> entity), then it works:

Image

params:
  domain: notify
  service: alexa_media
  service_data:
    title: Alexa Speak...
    data:
      type: tts
    message: test
    target:
      - media_player.echo_office_1
      - media_player.office

Is there something I am missing here?

Either way, thanks for the fine work on this integration. Have been looking into this a long time for a project, integrating directly to it, before I decided to use HA, which brought me here.

To Reproduce

  1. HA Side Menu -> Settings -> Automations and Scenes -> Scripts
  2. Click on ‘Create Script’
  3. Click the ‘…’ in the top right corner -> Edit as YAML
  4. Paste the yaml for the script:
sequence:
  - action: notify.alexa_media
    data_template:
      title: Alexa Speak...
      data:
        type: tts
      message: "{{message}}"
      target: |
        [
          {%- for key, values in targets.items() -%}
            {%- if values is string -%}
              "{{ values }}"
            {%- else -%}
              {%- for value in values -%}
                "{{ value }}"{% if not loop.last %}, {% endif %}
              {%- endfor -%}
            {%- endif %}
          {%- if not loop.last %}, {% endif %}
          {%- endfor -%}
        ]
alias: Echo talk
description: ""
fields:
  message:
    selector:
      text: null
    name: Message
    required: true
  targets:
    selector:
      target:
        entity:
          domain: media_player
          integration: alexa_media
    name: Targets
    description: Select Amazon Echo devices or areas to send your message to
    required: true
    default:
      entity_id: media_player.echo_main
mode: queued
max: 15
  1. Save (give it a couple of seconds, otherwise it won’t launch). You may see an error about the description, but that doesn’t matter.
  2. Again click on the ellipses of top right corner -> Run Script
  3. You should be greeted with a popup similar to my screenshot above.
  4. Type in any message and run some tests with indirect objects (like room or devices) as targets,
  5. I expect you won’t hear anything from Alexa (the bug I refer to). Head back to the script editor and click on TRACES to validate that the parameters are passed in correctly.

Expected behavior

I expected that my message would have been spoken by all echo devices within the specified areas.

Screenshots

Included in the description

System details

  • Home Assistant version: Core 2025.1.2 Supervisor 2024.12.3
  • alexa_media version (from const.py or HA startup log): 5.3.0 (UI value is the same as the log)
  • alexapy version (from pip show alexapy in homeasssistant container or HA startup log): 1.29.5
  • Is Amazon 2FA/2SV enabled <!—We will not debug login issues if unanswered—> (y/n): y
  • Amazon Domain: amazon.com

Debug Logs (alexa_media & alexapy) Please provide logs.

2025-01-19 23:35:30.401 DEBUG (MainThread) [custom_components.alexa_media.notify] Message: test, kwargs: {'title': 'Alexa Speak...', 'target': ['office'], 'data': {'type': 'tts'}}
2025-01-19 23:35:30.401 DEBUG (MainThread) [custom_components.alexa_media.notify] Target type: <class 'homeassistant.helpers.template.gen_result_wrapper.<locals>.Wrapper'>
2025-01-19 23:35:30.401 DEBUG (MainThread) [custom_components.alexa_media.notify] Processing: office
2025-01-19 23:35:30.402 DEBUG (MainThread) [custom_components.alexa_media.notify] Processed Target by string: ['office']

No logs for alexapy for this action were in the output.

Additional context

N/A

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16

Most upvoted comments

and idiot of the year award goes to…myself…lol

tts working and announce not working solved…

For future cases: Do not disturb mode on Amazon Echo blocks Announces

Got a solution!

I changed the action in automation.

Works:

actions:
  - action: notify.alexa_media
    data:
      message: Test
      data:
        type: announce
      title: Test
      target: media_player.uberall

Stopped Working:

actions:
  - action: notify.alexa_media_uberall
    metadata: {}
    data:
      data:
        type: announce
      message: >-
        Test

So I changed my automations…