Echo Devices (Alexa) as Media Player - Testers Needed

Would it be possible to get the ‘’last received command ‘’ in real time as a string like what openhab does? (One string entity per echo device) .

Take a look at the channel : lastVoiceCommand

Thank you so much.

That way I would be able to completly remove openhab from my setup.

not sure I follow, but if you mean to find out the last alexa called, then yes. Read here

@jeffky
so thank you again. I wrote the following automation and works “most” of the time :smile:
I added the input_text to the media card; type album/artist and it will play the album/artist. If I type album/artist, song; sometimes it does get the song as well.

input_text:
  plex_office_echo:
    name: Plex Office Echo
    initial: Album, Song
    pattern: "[Album, Song]"
  plex_living_echo:
    name: Plex Living Echo
    initial: Album, Song
    pattern: "[Album, Song]"
  plex_master_echo:
    name: Plex Master Echo
    initial: Album, Song
    pattern: "[Album, Song]"
  plex_bruno_echo:
    name: Plex Bruno Echo
    initial: Album, Song
    pattern: "[Album, Song]"

automation:
  - id: plex_on_echo
    alias: Plex on Echo
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_text.plex_office_echo, input_text.plex_master_echo, input_text.plex_living_echo, input_text.plex_bruno_echo
    action:
    - service_template: media_player.volume_set
      data_template:
        entity_id: '{% if trigger.entity_id.split(".")[1].split("_")[1] == "office" %} media_player.office_echo_dot {% elif trigger.entity_id.split(".")[1].split("_")[1] == "master" %} media_player.master_echo_dot {% elif trigger.entity_id.split(".")[1].split("_")[1] == "living" %} media_player.living_echo_dot {% else %} media_player.bruno_echo_dot {% endif %}'
        volume_level: 0.3
    - service_template: media_player.play_media
      data_template:
        entity_id: '{% if trigger.entity_id.split(".")[1].split("_")[1] == "office" %} media_player.office_echo_dot {% elif trigger.entity_id.split(".")[1].split("_")[1] == "master" %} media_player.master_echo_dot {% elif trigger.entity_id.split(".")[1].split("_")[1] == "living" %} media_player.living_echo_dot {% else %} media_player.bruno_echo_dot {% endif %}'
        media_content_id: '{"library_name" : "{{trigger.to_state.state.split(",")[0]}}","track_name" : "{{trigger.to_state.state.split(",")[1]}}","shuffle": "0"}'
        media_content_type: "AMAZON_MUSIC"
    - delay: 00:00:05
    - service_template: input_text.set_value
      data_template:
        entity_id: '{{trigger.entity_id}}'
        value: Album, Song
1 Like

Hi I just upgraded HASS to 0.92.2 so that I could install the latest alexa_media_player. I had to re-configure both echo and dot for them to show up under by amazon account. Now they do and they show up under hass. I can see the players (mostly showing the correct state Standby or playing something). I can control the playback. But the reason for me installing this plugin is voice notifications.
As you can see in the attachment two devices and a group were recognised.

I tried calling the service in many different combination (many more than this). I have restarted hass many times.

notify.alexa_media
{
  "message": "Just testing",
  "data": {
    "type": "announce"
  },
  "target":["90F00718649XXXXX", "G090LF09645XXXXX"]
}
notify.alexa_media
{
  "message":"Just testing",
  "data": {
    "type": "tts"
  },
  "target":["90F00718649XXXXX", "G090LF09645XXXXX"]
}

notify.alexa_media_bathroom
notify.alexa_media_bathroom
{
  "message": "Just testing",
  "data": {
    "type": "announce"
  }
}
notify.alexa_media_bathroom
notify.alexa_media_bathroom
{
  "message": "Just testing",
  "data": {
    "type": "announce"
  },
  "target":["90F00718649XXXXX", "Bathroom", "Bedroom", "G090LF09645XXXXX"]
}
notify.alexa_media_bathroom
notify.alexa_media_bathroom
{
  "message": "Just testing",
  "data": {
    "type": "tts"
  },
  "target":["90F00718649XXXXX", "Bathroom", "Bedroom", "G090LF09645XXXXX"]
}

And a somewhat corresponding log:

2019-05-11 13:00:48 DEBUG (SyncWorker_0) [custom_components.alexa_media.notify] Converting: <Entity Bedroom: paused> to (entities): <Entity Bedroom: paused>
2019-05-11 13:00:48 DEBUG (SyncWorker_0) [custom_components.alexa_media.notify] Testing item: <Entity Bedroom: paused> against (<Entity Everywhere: standby>, Everywhere, 1****************************XXX, media_player.everywhere)
2019-05-11 13:00:48 DEBUG (SyncWorker_0) [custom_components.alexa_media.notify] Testing item: <Entity Bedroom: paused> against (<Entity This Device: standby>, This Device, C****************************XXX, media_player.this_device)
2019-05-11 13:00:48 DEBUG (SyncWorker_0) [custom_components.alexa_media.notify] Testing item: <Entity Bedroom: paused> against (<Entity MR's Alexa Apps: standby>, MR's Alexa Apps, F****************************XXX, media_player.mr_s_alexa_apps)
2019-05-11 13:00:48 DEBUG (SyncWorker_0) [custom_components.alexa_media.notify] TTS entities: [<Entity Bedroom: paused>]
2019-05-11 13:00:48 DEBUG (SyncWorker_0) [custom_components.alexa_media.notify] TTS by <Entity Bedroom: paused> : Just testing
2019-05-11 13:00:50 INFO (SyncWorker_4) [homeassistant.components.command_line.switch] Running state command: curl -s http://10.0.1.23:3000/api/local/info/mission | jq .cleanMissionStatus.cycle | sed -e 's/^"//' -e 's/"$//'
2019-05-11 13:00:51 DEBUG (SyncWorker_4) [custom_components.alexa_media.notify] Message: Just testing, kwargs: {'target': ['G090LF09645XXXXX'], 'data': {'type': 'tts'}}
2019-05-11 13:00:51 DEBUG (SyncWorker_4) [custom_components.alexa_media.notify] Testing item: G090LF09645XXXXX against (<Entity Bathroom: paused>, Bathroom, 9************XXX, media_player.bathroom)
2019-05-11 13:00:51 DEBUG (SyncWorker_4) [custom_components.alexa_media.notify] Testing item: G090LF09645XXXXX against (<Entity Bedroom: paused>, Bedroom, G************XXX, media_player.bedroom)
2019-05-11 13:00:51 DEBUG (SyncWorker_4) [custom_components.alexa_media.notify] Converting: G090LF09645XXXXX to (entities): <Entity Bedroom: paused>
2019-05-11 13:00:51 DEBUG (SyncWorker_4) [custom_components.alexa_media.notify] Testing item: G090LF09645XXXXX against (<Entity Everywhere: standby>, Everywhere, 1****************************XXX, media_player.everywhere)
2019-05-11 13:00:51 DEBUG (SyncWorker_4) [custom_components.alexa_media.notify] Testing item: G090LF09645XXXXX against (<Entity This Device: standby>, This Device, C****************************XXX, media_player.this_device)
2019-05-11 13:00:51 DEBUG (SyncWorker_4) [custom_components.alexa_media.notify] Testing item: G090LF09645XXXXX against (<Entity MR's Alexa Apps: standby>, MR's Alexa Apps, F****************************XXX, media_player.mr_s_alexa_apps)
2019-05-11 13:00:51 DEBUG (SyncWorker_4) [custom_components.alexa_media.notify] Testing item: <Entity Bedroom: paused> against (<Entity Bathroom: paused>, Bathroom, 9************N4D, media_player.bathroom)
2019-05-11 13:00:51 DEBUG (SyncWorker_4) [custom_components.alexa_media.notify] Testing item: <Entity Bedroom: paused> against (<Entity Bedroom: paused>, Bedroom, G************E5S, media_player.bedroom)
2019-05-11 13:00:51 DEBUG (SyncWorker_4) [custom_components.alexa_media.notify] Converting: <Entity Bedroom: paused> to (entities): <Entity Bedroom: paused>
2019-05-11 13:00:51 DEBUG (SyncWorker_4) [custom_components.alexa_media.notify] Testing item: <Entity Bedroom: paused> against (<Entity Everywhere: standby>, Everywhere, 1****************************XXX, media_player.everywhere)
2019-05-11 13:00:51 DEBUG (SyncWorker_4) [custom_components.alexa_media.notify] Testing item: <Entity Bedroom: paused> against (<Entity This Device: standby>, This Device, C****************************XXX, media_player.this_device)
2019-05-11 13:00:51 DEBUG (SyncWorker_4) [custom_components.alexa_media.notify] Testing item: <Entity Bedroom: paused> against (<Entity MR's Alexa Apps: standby>, MR's Alexa Apps, F****************************XXX, media_player.mr_s_alexa_apps)
2019-05-11 13:00:51 DEBUG (SyncWorker_4) [custom_components.alexa_media.notify] TTS entities: [<Entity Bedroom: paused>]
2019-05-11 13:00:51 DEBUG (SyncWorker_4) [custom_components.alexa_media.notify] TTS by <Entity Bedroom: paused> : Just testing

No errors just utter silence. I have changed device language to English (United States) - from English (United Kingdom) in an effort to debug which is reflected during component init:

2019-05-11 12:52:08 DEBUG (SyncWorker_0) [custom_components.alexa_media] XXXXXXXXXXXX: Found 5 devices, 1 bluetooth
2019-05-11 12:52:08 DEBUG (SyncWorker_0) [custom_components.alexa_media] Locale en-us found for 9************XXX
2019-05-11 12:52:08 DEBUG (SyncWorker_0) [custom_components.alexa_media] Locale en-us found for G************XXX
2019-05-11 12:52:08 DEBUG (SyncWorker_0) [custom_components.alexa_media] Locale en-gb found for C****************************XXX
2019-05-11 12:52:08 DEBUG (SyncWorker_0) [custom_components.alexa_media] Locale en-us found for F****************************XXX
2019-05-11 12:52:08 DEBUG (SyncWorker_0) [custom_components.alexa_media] XXXXXXXXXXXX: Existing: [] New: ['Bathroom', 'Bedroom', 'Everywhere', 'This Device', "MR's Alexa Apps"]; Filtered by: include_devices: [] exclude_devices:[]
2019-05-11 12:52:08 INFO (MainThread) [homeassistant.components.notify] Setting up notify.alexa_media
2019-05-11 12:52:08 INFO (MainThread) [homeassistant.setup] Setup of domain media_player took 3.7 seconds.

Any help or suggestion would be much appreciated.

looking at the post above I noticed a bunch of different 'notify.alexa_media_xxx" services in the list. It prompted me to check my services list and I see them there too.

I see they were added (I think…) in the change for 1.2.4.

I don’t see anything in the docs telling me how to use those new services. Do I still need to add the “target” into the service call since the component created a “automatic target generation”?

What is the syntax of a service call using the new target based notify service?

Hi , what I meant i to get the last message spoken to an alexa device .

ex ; if I say ‘’ alexa turn on tv’’ to the bedroom alexa? then, i would get ‘‘turn on tv’’ as a string into home assistant. So I could make rules ‘’ if the string ‘‘on tv’’ is set on the alexa bedrrom. Then turn on the bedroom tv

Yes and that’s what the sensor in the write up I quoted allows you to do. It detects the last echo activated, which you can then use to activate a device in the same room/place.

The sensor and sample automationsre there.

I think I understand your question.

You’re not asking which was the last echo device to be used, but what was the last verbal command issued to ‘any’ device?

Assuming this is the question - I don’t think this is possible currently. The alexa website does show the very last command, so it would be possible to pull it out, but…

I think you might be making this more complex that it needs to be - especially as your using node-red.

You can use the wemo emulator or hue emulator nodes in node-red to trigger on the right key word, e.g. ‘Bedroom Light’ and then inspect the message attributes to determine whether its an on/off or a dim command, which covers ‘Turn on … , turn of …, bright … to x, dim … to x’.

Then if you want to do something more clever, create a new ‘pretend’ wemo/hue device in node-red, add a routine with a complex text command, e.g. “Which bin is it this week” and then have the routine turn on the fake device, which in node-red you can then detect which alexa the call came from and issue a TTS response back.

1 Like

sorry to ask but can’t handle with my problem: I created a group of Alexa media players (I have 2), can’t send tts to the group, I don’t see either the service notify.alexa_media_name.of.group, but I have the service for individual players, is it possible to send notification to a group of Alexa media players?

The group must be in home assistant not echo app.
Go to config / groups.yaml and make a new group . See Below
Sorry cant seem to remember how to insert code on the forum but im sure you get the idea.

alexatts_wholehouse:
name: Alexa Group Whole House
entities:
- media_player.front_room #(replace with your echo/dot entity ids)
- media_player.food_room
- media_player.shelbys_bathroom
- media_player.master_bathroom
- media_player.master_bedroom

Then restart home assistant and you will have a new group named
group.alexatts_wholehouse and you can send tts to that group to make alexa speak on multiple echos and dots.
Lots of great info here GitHub - keatontaylor/alexa_media_player: This is a custom component to allow control of Amazon Alexa devices in Home Assistant using the unofficial Alexa API. and probably much more clearly explained than my explanation.
Hope this helps.

ok I understand, the media player alexa tts works for a group of media player created in groups.yaml, my problem is with the notify (newer) service. I have a script (it is part of a package for a notification center with which can be set do not disturb time, notify on google and alexa media players, on telegram, as persistent notification in hassio etc…) that works if the target is a single media player, don’t work with the group, but it work if used in dev tools to test, strange behaviour but maybe is a component limit or package code limit.

OK sorry , misunderstood your problem.
So, i do my automation and scripts in node red and from node red if i want to send a message to more than one device that is not in a group i enter the devices separated by commas. Like this:
media_player.food_room, media_player.shelbys_bathroom, media_player.master_bathroom
Maybe this will work for you in your script as opposed to sending to a specific group? Sorry, I don’t have much experience with scripts and automatons in ha, wish i could be more help.

Thank you @finity
I was doing it backwards, i appreciate the update!

thanks , but that is in fact more complex than what i do. And i do some more complex thing than just room aweness.

ex: Alexa turn on tv in 5 minutes.
-alexa turn turn of lamp in 5.5 hours.
etc.

I am transfering all the string to Homeseer via nodered.

From there is is very easy to automate things.

So i really need the last string from the last spoken command on a given alexa device.

That would be a really nice addon to home assistant.

the first rason why I would like to drop openhab is because it uses far to much memory (ram)

here is my nodered setup. All the string are sent to HomeSeer via Mqtt.

Then from homeseer. i can do A LOT of thing with the string.

to get the last spoken command you need to send a request to the amazon server.
off course its possible to send a request every second, and have the result in HA with a delay from 1 second. (obvious its possible, because openhab seems to do it)
but that would be bad practice. and also probably why openhab uses more resources.

if say a command like “Alexa turn on tv in 5 minutes” to alexa, she should do the work.
you dont want to start to use commands that she cant perform, and then have HA perform the command. thats like disableling Alexa on an echo.

Not sure if I am missing something, but if I play music on my echos from Spotify, track info etc shows up in the media card in HA. If I listen to any radio it stays showing “standby”
Any ideas ?

This has been working reliably for a while, but now running routines seems to have stopped working. Other things, such as the notify platform still seem to be working fine, but when it ties to trigger a routine I get this in the log:

  File "/home/homeassistant/.homeassistant/custom_components/alexa_media/media_player.py", line 660, in play_media
    self.alexa_api.run_routine(media_id)
  File "/srv/homeassistant/lib/python3.5/site-packages/alexapy/alexaapi.py", line 153, in run_routine
    for automation in automations:
TypeError: 'NoneType' object is not iterable

It looks like it is failing to get the list of routines from the device, any ideas?

Edit: It definitely looks like something odd was happening with retreiving the list fo routines. I opened https://alexa.amazon.co.uk/api/behaviors/automations (which I believe this component uses to get the list of routines) in my browser to see if there were any issues and found it was only returning the two default routines you get when you haven’t created any (“Start my day”, and “Goodnight”). The other URL, https://alexa.amazon.co.uk/api/behaviors/routines, was returning an empty list.

Now both of them return the correct routines and, after a restart of Home Assistant, it is all working again.

Amazon seems to have changed something on their side.

When i speek something loud, i get the device id of every echo here. If i wishper it…i only get the device id from the echo near me.