Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify.alexa_media does not work with groups (or any non alexa_media entities). #2801

Open
fabio-s-franco opened this issue Jan 19, 2025 · 9 comments

Comments

@fabio-s-franco
Copy link

fabio-s-franco commented Jan 19, 2025

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

@danielbrunt57
Copy link
Collaborator

AMP hooks itself into the HA notify platform and AMP was designed before "areas" was a thing in HA so it's no surprise that it doesn't work.

Where the wiki mentions "Guest Room", that's not an HA area but is the friendly name of an echo device or an Alexa speaker group.

@SchmidSP
Copy link

The same problem for me ( since approx. 1 week).
Can you please check whether the groups still work for you when playing music (Amazon Music app, say “Play Music everywhere”)? For me, the groups no longer work there either.
I therefore assume that there is a problem on the part of Amazon.
Unfortunately, I can't find a contact at Amazon where I could report this.
I can still use the TTS on individual devices without any problems.

@digiltd
Copy link

digiltd commented Jan 20, 2025

Do you have the speaker group setup in the Alexa app? In the app go to Devices, then click the plus icon in the top right then choose Combine Speakers, then select Multi-room music, pick the Echos you want to be in the group, then choose a name and save (and apologies if you already knew how to do it, i try never to assume). The new Multi-room speaker group will then appear as its own media player in HA.

Is the idea that:

  • you quickly type a message in the dashboard
  • select from a list which of various Echos scattered around the house you want the message to come out of
  • have the message spoken by Alexa to all the devices
    • in sync?
    • play on each device one by one, looping through the list?

@SchmidSP
Copy link

Hi,
thanks for the support first of all:

Groups are set up with the respective devices in the Alexa app (e.g. Everywhere contains all devices).

The whole thing has been used for months in various automations where notifications

Action: action: 
notify.alexa_media_uberall
data:
  message: test

are sent to all devices.
Individual devices still work.
Example:

action: notify.alexa_media_buro_2
data:
 message: test

Only the groups no longer do.

I also see a http/code: 200 in log, so it look that the plugin had a clean connection to Amazon service.
POST: https://alexa.amazon.de/api/behaviors/preview returned 200:OK:application/octet-stream

I think for this project it would only be important to know if it is the HACS plugin or Amazon.
Therefore the hint

Image

that I can no longer get all devices to run simultaneously via voice control (Alexa, play music everywhere).

@fabio-s-franco
Copy link
Author

fabio-s-franco commented Jan 20, 2025

In my case the groups I am referring to are from home assistant, so not related to amazon (in my case at least).

so it's no surprise that it doesn't work.

It would be nice if the wiki would clarify the ambiguity of groups. As the wiki does state:

"target:" - The target Alexa devices. This can be the Friendly Name, Serial Number, entity_id, `or Home Assistant Group.` **

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Jan 21, 2025

In my case the groups I am referring to are from home assistant, so not related to amazon (in my case at least).

so it's no surprise that it doesn't work.

It would be nice if the wiki would clarify the ambiguity of groups. As the wiki does state:

"target:" - The target Alexa devices. This can be the Friendly Name, Serial Number, entity_id, or Home Assistant Group. **

Home Assistant groups are not Areas. I believe groups predate areas and were legacy entities defined in YAML. They can now be created in the UI via Helpers:

Image

The other way would be to create speaker group(s) in Alexa which would then be discovered by AMP as unique media_player device(s) for the Alexa speaker group(s).

@danielbrunt57
Copy link
Collaborator

The whole thing has been used for months in various automations where notifications

Action: action: 
notify.alexa_media_uberall
data:
  message: test

are sent to all devices.

I think WHA groups only support type: announce?

@fabio-s-franco
Copy link
Author

I think the most sustainable way to do this, would be to carry out the expansion, since it works with any concept of groups within HA (floors, areas, device and what not).

I will try to do it and can share here, maybe can be incorporated into the addon somehow

@SchmidSP
Copy link

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants