Echo Devices (Alexa) as Media Player - Testers Needed

The media card has never worked for tts..
Are you saying you don’t have a service media_player.alexa_tts? We’ll need logs to figure out why. Please turn on debugging and post any errors being generated by the component in an issue and we’ll take a look.

There have been scripts posted in the thread to help set the volume by playing a silent track prior to any TTS announcement. Please search. Alternatively, you can wait till someone resolves it here.

As for custom updater, no one’s filed an issue for it although people have requested it a couple of times.

I believe it’s an Amazon limitation that it only supports Amazon’s built in music services; HA can’t interact with the groups directly. Workarounds have been to create a HA group with all media_player entities and then adjust for the different response times since they do not all sync anymore.

Thank you, found the solution here Echo Devices (Alexa) as Media Player - Testers Needed - #1458 by b3voholic

I also opened an issue (custom updater).

Do we need amazon music unlimited for this?

It works for me now because I have a test phase, but I won’t use it after it ended. I do have amazon music (prime). Does it work with that too?

yes it works without unlimited. Prime is enough.

1 Like

HA can interact with music groups, but only for music.
you can only do with HA what you can do with an alexa (so with something you say, or something you do in the app)
you cant talk to all alexas at the same time, so it cant respond on all at the same time.
remember there is no such thing as TTS on amazon. in HA we create a hack to mimic TTS.

I think we can make this script a little smarter, I had problems with the delay as the song was not playing when it sets the volume after the 3 second delay. I think the wait_template is the right choice.

alexa_test:
  sequence:
    - service: media_player.play_media
      data:
        entity_id: media_player.echo_dotr
        media_content_id: Silence 5 Seconds
        media_content_type: AMAZON_MUSIC
    - wait_template: "{{ states.media_player.echo_dot.state == 'playing' }}"
    - service: media_player.volume_set
      data:
        entity_id: media_player.echo_dot
        volume_level: 0.4
    - delay:
        milliseconds: 200
    - service: media_player.alexa_tts
      data:
        entity_id: media_player.echo_dot
        message: "Test"

Also I think we could make a script out of this that could be used for different tts messages with only filling in the message.

Maybe @petro can help making this script more compact and smarter.

I’m not sure you can. If those delays are needed and your goal is to “play something, turn the volume up, and then say test”, then it’s pretty much optimized.

@petro in another thread you showed me how to use scripts with data_template to use them in different automations. This we could avoid a lot copied and pasted code.

I copied the code above to every tts service call. So maybe this could be make it more compact.

Well then this could be made into a w/ variables

alexa_test:
  sequence:
    - service: media_player.play_media
      data_template:
        entity_id: "{{ media_player }}"
        media_content_id: "{{ content_id }}"
        media_content_type: "{{ content_type }}"
    - wait_template: "{{ is_state(media_player, 'playing') }}"
    - service: media_player.volume_set
      data_template:
        entity_id: "{{ media_player }}"
        volume_level: "{{ volume_level }}"
    - delay:
        milliseconds: 200
    - service: media_player.alexa_tts
      data_template:
        entity_id: "{{ media_player }}"
        message: "{{ message }}"

Then just call this in any action and fill it in with the appropriate info.

  - service: script.alexa_test
    data:
      media_player: media_player.echo_dotr
      content_id: Silence 5 Seconds
      content_type: AMAZON_MUSIC
      volume_level: 0.4
      message: "Test"
2 Likes

Thank you @petro

I remember a conversation about calling such a script (with variables) multiple times at the same time.

Will this fail when to automations trigger this script at the same time? I think the one that is triggers some milliseconds before will “win”, right? The other one will “ignored”?

Yes, I believe so. In that regard, you’d need to build a message queue. Normal HA automations can’t do that, but AppDaemon or a python script can.

Silly question, but is there any way to clear the media player card in the front end? I’m not using Love Lace and when I call media_player.turn_off or any of the other services the status of the media player changes to “paused” and the artist name, title and cover art are still displayed.

1 Like

this is easily remedied by changing it from something like ‘Courtney’s Bedroom’ to “Courtney’s Bedroom”

At this point no. Amazon continues to populate last song information so the media player continues to show it when we update the media_state. If you play flash briefing (and potentially other Amazon skills), the media_player stops showing info and will clear the media_player.

It might be possible to force a clear by doing something with the power button (which just does a pause now) where we turn off device updates and force clears the media_details.

Alternatively, we could avoid showing the media info if the device hits “idle” state which appears to happen when it finishes the play list naturally. Others may have to chime in if they ever see it in idle state otherwise.

1 Like

Thanks for your suggestions! Unfortunately this is out of my programming skills. I think I will stay with the multiple used code.

I added a timeout to the wait_template, because if the command to set the silent song fails, it waits forever and nothing happens.
So if it fails it should play the tts message in the volume that is set.

Looks like this now

test_alexa:
  alias: Alexa - test  
  sequence:
    - service: media_player.play_media
      data:
        entity_id: media_player.echo
        media_content_id: Silence 5 Seconds
        media_content_type: AMAZON_MUSIC
    - wait_template: "{{ states.media_player.echo.state == 'playing' }}"
      timeout: '00:00:07'
      continue_on_timeout: 'true'    
    - service: media_player.volume_set
      data:
        entity_id: media_player.echo
        volume_level: 0.4
    - delay:
        milliseconds: 500
    - service: media_player.alexa_tts
      data:
        entity_id: media_player.echo
        message: "test"
1 Like

Thanks so much for this component. Between it and node-red I now have audible announcements if any of my water or freeze sensors detect a situation

I’m in the uk. Is this correct for UK Alexa

media_player:
  - platform: alexa
    email: “[email protected]”
    password: “my.password”
    url: “https://alexa.amazon.co.uk”

Nothing is seen and I am using HASSIO. Where might the log files be?

try it this way:
media_player:

your quotes are the wrong kind. And yes it makes a difference…

look at your post above and then look here to see the difference:

media_player:
  - platform: alexa
    email: "[email protected]"
    password: "my.password"
    url: "alexa.amazon.co.uk"