Echo Devices (Alexa) as Media Player - Testers Needed

Here is my working script, My playlist is called “Home”

spotify:
  alias: play spotify
  icon: mdi:music
  mode: single
  sequence:
  - data:
      source: Spotify
    entity_id: media_player.bedroom
    service: media_player.select_source
  - data:
      entity_id: media_player.bedroom
      media_content_id: shuffle Home
      media_content_type: SPOTIFY
    entity_id: media_player.bedroom
    service: media_player.play_media
1 Like

Is it the first part “select source” needed?

Not sure but the script works so shrugs

Hi, I’m facing the problem, that alexa media updates its status much slower then around until two weeks ago.
The problem is for example, that I’m connecting bluetooth with my receiver when starting music. When I change the source to another echo group, then the blutooth status of my speeker is still not updated and therefore empty so that the script to connect bluetooth is called again and the echo answers correctly that its already conncted to bluetooth. Thats annoying and leads in other cases to issues.
The update of the echo status (show the music source picture and set status playing) needs around 3 to 15 minutes.

Has anybody else recognized a decrease in speed of alexa media?

Maybe in relation to my post above, I have an issue I don’t understand.
In order to switch the ligt off by saying the same “alexa, light off” in every room I have the following script exposed to alexa:

command_light_off:
  sequence:
    - service: alexa_media.update_last_called
    - delay: "00:00:02"
    - service: logbook.log
      data:
        name: "Licht aus"
        message: "is being used from {{states('sensor.last_called_alexa')}}"
    - service: light.turn_off
      data:
        entity_id: >
          {% if is_state('sensor.last_called_alexa','media_player.wohnzimmer') %}
             light.wohnzimmer
          {% elif is_state('sensor.last_called_alexa','media_player.gastezimmer') %}
             light.gastezimmer
          {% elif is_state('sensor.last_called_alexa','media_player.office') %}
             light.office
          {% elif is_state('sensor.last_called_alexa','media_player.kuche') %}
             light.kuche
          {% elif is_state('sensor.last_called_alexa','media_player.fitnessraum') %}
             light.fitnessraum
          {% elif is_state('sensor.last_called_alexa','media_player.schlafzimmer') %}
             light.schlafzimmer
          {% elif is_state('sensor.last_called_alexa','media_player.bad_yvonne') %}
             light.schlafzimmer
          {%- endif %}

The script worked without issues until last friday.
Then it starts, that I’ve had to give the command always twice. In the beginning I thought, that alexa didn’t understood me, but then I recognized these issues in my log:

Logger: homeassistant.components.script.command_light_off
Source: helpers/script.py:1138
Integration: Skript (documentation, issues)
First occurred: 12:14:47 (3 occurrences)
Last logged: 17:51:42

command_light_off: Error executing script. Invalid data for call_service at pos 3: not a valid value for dictionary value @ data['entity_id']
command_light_off: Error executing script. Invalid data for call_service at pos 4: not a valid value for dictionary value @ data['entity_id']

Ok for pos4, it seems that the sensor isn’t set.
So I added the log entry in order to check, if the sensor really isn’t set. I’m wondering why this could be because the sensor alwas has a value at least the old one.
But the error for pos 3 confuses me completely because I just write the active state of an entity in the log. I expected an empty value but not the same error like pos4.
By the way: I use the same sequence in many scripts, but the issue appears only in this command.

Just a thought. Could it be that the state of sensor.last_called_alexa is somtimes (for whatever reason) none of the tested states ? In this case entity_id ist not set and an error is logged. It might help to add an else path that sets entity_id to a default media_player that is used in case all of the above tests fail.

Thanks, yes. I was thinking about that as well. But the ‘else’ can only be the wrong light :wink: That would cause confusion when you are in the livingroom, want to switch off the light and the lights in the office react :slight_smile:
What I’m missing is an error handler like in other languages in order to give the user a response.
That would be the easiest way.
What I have done so far is to increase the delay. Will see if it helps. But imo it’s just a workaround and doesn’t explain, why all other scripts with exactly the same sequence work with a delay of 1 second and this one needs 3. :face_with_raised_eyebrow:

You could try to wait until sensor.last_called_alexa is populated with a value before testing its state. Try this:

# wait until sensor.last_called_alexa is populated with last device. 
          - wait_template: "{{ not is_state('sensor.last_called_alexa', '' ) }}"

or this

# wait until sensor.last_called_alexa is populated with last device. 
          - wait_template: "{{ not is_state('sensor.last_called_alexa', 'unknown' ) }}"

To make it short:
I tested it out this morning as it still did not work:
I had to increase the delay up to 5 seconds before sensor.last_called alexa is updated.
Last week it worked with 1 second. So something changed over the last two eeks.

Wait_template is no solution because the script will work with the old value and continue

OK, understand. There were indeed many code updates in the last couple of weeks. You may want contact the author. Probably best is to flag an issue here: https://github.com/custom-components/alexa_media_player/issues

already done: https://github.com/custom-components/alexa_media_player/issues/1159

Hey all,

I have a device in HA that I want to trigger a routine in Alexa (sleep sensor), but I have no idea how to do it? Is there a step by step guide for newbies on how to connect animations to alexa routines.

Even if someone can just post some screenshots of already existing routines and config and I can work it out.

I have had a look at the Automation routines section on github, but I have no context for it, so no idea what goes where.

Thanks guys, I really appreciate it :slight_smile:

The easiest way is through Nabu Casa: https://www.nabucasa.com/config/amazon_alexa/

Thanks mate,

I know, how easy would that be HAHA. But it shows as a switch that cant be a device that triggers a routine :frowning:

Unless I can change the device type?

https://community.home-assistant.io/t/how-to-trigger-alexa-routines-from-home-assistant/90678

Thanks!

The sleep sensor is not the right device class to start a routine.

But hopefully I can get this to work, I’ve got this at the end of the script. Is this all I have to do to kick off the routine? obviously I have Alexa Media Player installed and am using the right devices ect.

image

This should work too. But this is using the alexa media player custom component which is different from the nabu casa cloud solution provided in the link above.

Thanks,

I got it working, found this legends blog with all the info, hope this helps someone :slight_smile:

  1. create the Alexa routines
  2. create the scripts (I just pasted these directly into the scripts.yaml and edited to what I needed)
radioparadise:
  alias: Play Radio Paradise
  icon: "mdi:play"
  sequence:
  - service: media_player.play_media
    data:
      media_content_id: Radio Paradise
      media_content_type: routine
    entity_id: media_player.den_echo_dot
  mode: single

stopmusic:
  alias: Stop playing music on Alexa
  icon: "mdi:stop"
  sequence:
  - service: media_player.play_media
    data:
      media_content_id: stop playing music
      media_content_type: routine
    entity_id: media_player.den_echo_dot
  mode: single 
  1. Put the following in your configuration.yaml
homeassistant:
  customize: !include customize.yaml
  packages: !include_dir_named packages # package setup
  1. Create a “customize.yaml” in the HA config folder and add this code block (edit for your own context)
script.radioparadise:
  friendly_name: Start Playing
  icon: mdi:play
script.stopmusic:
  friendly_name: Stop Playing
  icon: mdi:stop
  1. I also created a lovelace card to test it out, but up to you
entities:
  - action_name: Play
    entity: script.radioparadise
  - action_name: Stop
    entity: script.stopmusic
show_header_toggle: false
title: Radio Paradise
type: entities

Maybe somebody cab figure out my issue. I have my Echo devices set up as a group called “Everywhere”. I can control each individually and they will play media,tts,etc.
I created a card that included the media_player.everywhere. If I try to play to all my Echo devices using the “Everywhere” card,the devices do respond by showing the current volume level,but no music plays.

I’m not using any sort of streaming service,just for radio,so I’m not sure thats the issue or not.

Wiki.