Echo Devices (Alexa) as Media Player - Testers Needed

Thanks, didn’t think of using regular groups for this, was thinking of notify groups.

2 Likes

Awesome! Thanks for sharing this :slight_smile:

Ps. How can I send mp3 songs via automation? It’s possible?

So I"m getting this in my logs for the plugin

Fri, 06 Jul 2018 15:58:39 GMT nightmare queuing process start
Fri, 06 Jul 2018 15:58:39 GMT nightmare queueing action "goto" for https://alexa.amazon.com
Fri, 06 Jul 2018 15:58:39 GMT nightmare queueing action "wait"
Fri, 06 Jul 2018 15:58:39 GMT nightmare queueing action "type"
Fri, 06 Jul 2018 15:58:39 GMT nightmare queueing action "type"
Fri, 06 Jul 2018 15:58:39 GMT nightmare queueing action "click"
Fri, 06 Jul 2018 15:58:39 GMT nightmare queueing action "wait"
Fri, 06 Jul 2018 15:58:39 GMT nightmare queueing action "goto" for https://alexa.amazon.com/api/devices-v2/device
Fri, 06 Jul 2018 15:58:39 GMT nightmare queueing action "wait"
Fri, 06 Jul 2018 15:58:39 GMT nightmare queueing action "evaluate"
Fri, 06 Jul 2018 15:58:39 GMT nightmare running
There was an error
Internal endpoint:
curl -X POST -d "tts=Ask Alexa team for a proper TTS API" -d "deviceSerialNumber=deviceSerialNumber" http://localhost:8091/alexa-tts
got request for getDevices
TypeError: Cannot read property 'alexaURL' of null
    at Object.getDevices (/workspace/alexa-api.js:181:19)
    at /workspace/index.js:29:13
    at Layer.handle [as handle_request] (/workspace/node_modules/express/lib/router/layer.js:95:5)
    at next (/workspace/node_modules/express/lib/router/route.js:137:13)
    at urlencodedParser (/workspace/node_modules/body-parser/lib/types/urlencoded.js:100:7)
    at Layer.handle [as handle_request] (/workspace/node_modules/express/lib/router/layer.js:95:5)
    at next (/workspace/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/workspace/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/workspace/node_modules/express/lib/router/layer.js:95:5)
    at /workspace/node_modules/express/lib/router/index.js:281:22
got request for getDevices
TypeError: Cannot read property 'alexaURL' of null
    at Object.getDevices (/workspace/alexa-api.js:181:19)
    at /workspace/index.js:29:13
    at Layer.handle [as handle_request] (/workspace/node_modules/express/lib/router/layer.js:95:5)
    at next (/workspace/node_modules/express/lib/router/route.js:137:13)
    at urlencodedParser (/workspace/node_modules/body-parser/lib/types/urlencoded.js:100:7)
    at Layer.handle [as handle_request] (/workspace/node_modules/express/lib/router/layer.js:95:5)
    at next (/workspace/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/workspace/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/workspace/node_modules/express/lib/router/layer.js:95:5)
    at /workspace/node_modules/express/lib/router/index.js:281:22
got request for getDevices
TypeError: Cannot read property 'alexaURL' of null
    at Object.getDevices (/workspace/alexa-api.js:181:19)
    at /workspace/index.js:29:13
    at Layer.handle [as handle_request] (/workspace/node_modules/express/lib/router/layer.js:95:5)
    at next (/workspace/node_modules/express/lib/router/route.js:137:13)
    at urlencodedParser (/workspace/node_modules/body-parser/lib/types/urlencoded.js:100:7)
    at Layer.handle [as handle_request] (/workspace/node_modules/express/lib/router/layer.js:95:5)
    at next (/workspace/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/workspace/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/workspace/node_modules/express/lib/router/layer.js:95:5)
    at /workspace/node_modules/express/lib/router/index.js:281:22

I have the URL plugged in correctly but I’m not sure why its complaining about the a Null for the AlexaURL. Thank you for your help

When someone figures out how to install this on a Docker install, I can help test.

I have 4 echo dots, 1 echo, and 1 echo show. Home Assistant is running on an old laptop running Ubuntu Server under Docker. I have experimented a little with TTS, and play music on my Echos on occasion, but I’m primarily interested in TTS notification ability as I am trying to avoid having to buy a Chromecast Audio and a separate speaker for every room that has an Echo.

1 Like

I would love it

Hey @BrianHanifin. There hassio add-on is simply a docker container, I’ve built it for both armhf and amd64 machines.

If you’re on one of those architectures you should be able to:

docker pull keatontaylor/amd64-addon-alexa-api

You’ll then need to create a options.json file in a directory of your choice that will include the config parameters

{
  "username": "[email protected]",
  "password": "mysupersecretamazonpassword",
  "url": "https://alexa.amazon.com"
}

Next run the container and mount the directory that contains options.json to the /data folder

docker run -id -v /your-directory-containing-options-json:/data -p 8091:8091 -t alexa-api

Next you’ll need to add your IP to the yaml config for the component. (The IP will most likely be the IP of your host box running docker)

media_player:
  - platform: alexa
    host: 10.0.1.4

For those going this route, I added the host config for the component today. So be sure to download the latest @
[https://github.com/keatontaylor/custom_components/blob/master/media_player/alexa.py]

3 Likes

The main error is that it didn’t login correctly. Troubleshooting I’d say to ensure your credentials are correct and ensure that you have two-factor authentication off on your amazon.com account.

The error about alexaURL being null is because it is being passed to the rest of the node.js code, but fails to do so when the login fails.

1 Like

Give this a shot:

curl -X POST -d 'deviceSerialNumber=G2A0P30774060QRT' http://192.168.1.11:8091/alexa-getState

This is awesome!
I think the 2FA is pretty important. Maybe, nightmarejs can set the „remember me“ check and keep the cookie. That way, you can turn off the 2FA for initial setup and turn it back on after. Just my 2 cents.

Hmm, not a bad idea, assuming amazon doesn’t invalidate all session cookies when 2FA is turned on or off. (which if they’re smart they do)

LOL I feel dumb I swear I copied the right pass from lastpass. I see now that I did not.

EDIT: Well now I know that I have the correct password in there I’m still getting no love. My password is complex though with special characters. This shouldn’t cause an issue though should it? Thanks. BTW 2 Factor is disabled. I honestly didn’t know that amazon had 2 factor functionality. Looking forward to when this is compatible with it because I’d love to enable it.
EDIT2: I uninstalled and reinstalled the addon and now it picked up my devices.

1 Like

Or, the user could follow this advice:

If login fails look at /tmp/.alexa.login. Search for “password” and see if you are being prompted for the captcha. If so, you can attempt to login to Alexa manually from a browser (from the same IP) and see if that fixes the issue for you. It never did for me, so I logged in to https://alexa.amazon.com with Chrome and used the cookies.txt extension(https://chrome.google.com/webstore/detail/cookiestxt/njabckikapfpffapmjgojcnbfjonfjfg?hl=en) to export my amazon cookies to /tmp/.alexa.cookie. Other individuals have reported success using the same procedure, but only when using Firefox.

GitHub - walthowd/ha-alexa-tts: Alexa Unsolicted TTS for Home Assistant

When you login in your browser, you can click “remember this computer” and this computer will show up in a list under the amazon 2FA settings. Once it’s on the list, you don’t need to use 2FA on this browser.

Maybe, you can link your add-on to the config folder where one can save the cookie.

It discover 3 media players, and not working with Spotify

I’ll certainly look into adding that as an option. I can mount the share directory of the hassio install within the container and then users could drop the cookies file there.

UPDATE!

0.4 released (for both the custom_component and hassio add-on.

Please be sure to update both the add-on and place the update alexa.py file in your media_player custom_components directory.

[https://github.com/keatontaylor/custom_components/blob/master/media_player/alexa.py]

Make sure you see VERSION 0.4 when downloading.

What this fixes:

  1. Support for other media providers besides amazon music. Spotify and others should show up correctly in HA now
  2. Better resolution album art
  3. Minor refactoring of the hassio add-on
1 Like

I did this for several devices:

curl -X POST -d 'deviceSerialNumber=G2A0P30774060QRT' http://192.168.1.11:8091/alexa-getState

{"statusCode":400,"body":"{\"message\":null}","headers":{"server":"Server","date":"Sat, 07 Jul 2018 09:09:20 GMT","content-type":"application/json","content-length":"16","connection":"close","x-amzn-requestid":"6ec33f41-81c5-11e8-ae18-2f0454587d02","x-amzn-alt-domain":"https://alexa.amazon.de/logout","x-amzn-error":"DEVICE_NOT_CONNECTED","vary":"Accept-Encoding,User-Agent"},"request":{"uri":{"protocol":"https:","slashes":true,"auth":null,"host":"alexa.amazon.com","port":443,"hostname":"alexa.amazon.com","hash":null,"search":"?deviceSerialNumber=G2A0P30774060QRT&deviceType=A7WXQPH584YP&screenWidth=2560","query":"deviceSerialNumber=G2A0P30774060QRT&deviceType=A7WXQPH584YP&screenWidth=2560","pathname":"/api/np/player","path":"/api/np/player?deviceSerialNumber=G2A0P30774060QRT&deviceType=A7WXQPH584YP&screenWidth=2560","href":"https://alexa.amazon.com/api/np/player?deviceSerialNumber=G2A0P30774060QRT&deviceType=A7WXQPH584YP&screenWidth=2560"},"method":"GET","headers":{"Cookie":"session-id=135-8757514-3331324; session-id-time=2161671756l; csm-hit=H19GYE6J4KZ4EK9XSGJ8+s-H19GYE6J4KZ4EK9XSGJ8|1530951760584; ubid-main=133-1885545-6358834; x-main=\"zvIAjuxG3aIRu4fggnC@iRxgrz7DM2Xh\"; at-main=Atza|IwEBIKhay6PuyKu_BQQ3zCpvvpAMYmLaNs78yfg2BDevd80apUskkGZOeixuTOm2mOsATNb2BYvd_tkcAyYzgXaveVLDYwLS4k9-4GkrLBESXf5rDYGceS0PPytercBAi8Qu73d9KP7AtrkXl9n4DmwORGeSR2bqjDhtTi1Sv1Fzfnq9l0PbAMEaC4L0XylhoAxXwvteVo2u_KP2xuzd5nh1H4gjXEDkM6SphiUMuTEdBl_tjvhB0s3RqAYF-mhz1tbUIvnmIxuMAE8ygMGUYqdCBin8Fxv8AF5AnOd3JRkbPXrEI7lSF8ta3vhEvMtVVPerLuPcbUU_msXgwHzwlrRN7BsFV7DuNLalwCHZ91zCpuxywF4sYJLTuE--DsnDWN4kPzZhz_fyWaDVWpE1NM7Pa0va; sess-at-main=\"ib9UN1tuFCtATMvOULxOmbj4LoDF56hcz5tMpJCsLHw=\"; csrf=1821686027; ","csrf":"1821686027"}}}#

curl -X POST -d 'deviceSerialNumber=1084C963D52F4E85BB2556000DC1CA7A' http://192.168.1.11:8091/alexa-getState

{"playerInfo":{"hint":null,"infoText":null,"isPlayingInLemur":false,"lemurVolume":null,"lyrics":null,"mainArt":null,"mediaId":null,"miniArt":null,"miniInfoText":null,"playbackSource":null,"playingInLemurId":null,"progress":null,"provider":null,"queueId":null,"state":null,"template":null,"transport":null,"volume":null}}#

curl -X POST -d 'deviceSerialNumber=30559f9c4cd247a1a2d8ebfb9d8d7df2' http://192.168.1.11:8091/alexa-getState

{"playerInfo":{"hint":null,"infoText":null,"isPlayingInLemur":false,"lemurVolume":null,"lyrics":null,"mainArt":null,"mediaId":null,"miniArt":null,"miniInfoText":null,"playbackSource":null,"playingInLemurId":null,"progress":null,"provider":null,"queueId":null,"state":null,"template":null,"transport":null,"volume":null}}#

curl -X POST -d 'deviceSerialNumber=G090LF1180340C7E' http://192.168.1.11:8091/alexa-getState

{"statusCode":400,"body":"{\"message\":null}","headers":{"server":"Server","date":"Sat, 07 Jul 2018 09:12:13 GMT","content-type":"application/json","content-length":"16","connection":"close","x-amzn-requestid":"d6232db8-81c5-11e8-b808-67070dedb794","x-amzn-alt-domain":"https://alexa.amazon.de/logout","x-amzn-error":"DEVICE_NOT_CONNECTED","vary":"Accept-Encoding,User-Agent"},"request":{"uri":{"protocol":"https:","slashes":true,"auth":null,"host":"alexa.amazon.com","port":443,"hostname":"alexa.amazon.com","hash":null,"search":"?deviceSerialNumber=G090LF1180340C7E&deviceType=A3S5BH2HU6VAYF&screenWidth=2560","query":"deviceSerialNumber=G090LF1180340C7E&deviceType=A3S5BH2HU6VAYF&screenWidth=2560","pathname":"/api/np/player","path":"/api/np/player?deviceSerialNumber=G090LF1180340C7E&deviceType=A3S5BH2HU6VAYF&screenWidth=2560","href":"https://alexa.amazon.com/api/np/player?deviceSerialNumber=G090LF1180340C7E&deviceType=A3S5BH2HU6VAYF&screenWidth=2560"},"method":"GET","headers":{"Cookie":"session-id=135-8757514-3331324; session-id-time=2161671756l; csm-hit=H19GYE6J4KZ4EK9XSGJ8+s-H19GYE6J4KZ4EK9XSGJ8|1530951760584; ubid-main=133-1885545-6358834; x-main=\"zvIAjuxG3aIRu4fggnC@iRxgrz7DM2Xh\"; at-main=Atza|IwEBIKhay6PuyKu_BQQ3zCpvvpAMYmLaNs78yfg2BDevd80apUskkGZOeixuTOm2mOsATNb2BYvd_tkcAyYzgXaveVLDYwLS4k9-4GkrLBESXf5rDYGceS0PPytercBAi8Qu73d9KP7AtrkXl9n4DmwORGeSR2bqjDhtTi1Sv1Fzfnq9l0PbAMEaC4L0XylhoAxXwvteVo2u_KP2xuzd5nh1H4gjXEDkM6SphiUMuTEdBl_tjvhB0s3RqAYF-mhz1tbUIvnmIxuMAE8ygMGUYqdCBin8Fxv8AF5AnOd3JRkbPXrEI7lSF8ta3vhEvMtVVPerLuPcbUU_msXgwHzwlrRN7BsFV7DuNLalwCHZ91zCpuxywF4sYJLTuE--DsnDWN4kPzZhz_fyWaDVWpE1NM7Pa0va; sess-at-main=\"ib9UN1tuFCtATMvOULxOmbj4LoDF56hcz5tMpJCsLHw=\"; csrf=1821686027; ","csrf":"1821686027"}}}#

Some of them are real echo devices and some are mobiles with apps running. I only need the real echos so far. The one with the big return seem to be my real echo devices, but not 100% sure.

Everything was working fine before the last update. Now I’m getting this error:

TypeError: Cannot read property 'alexaURL' of null
at Object.getDevices (/workspace/alexa-api.js:181:19)
at /workspace/index.js:29:13
at Layer.handle [as handle_request] (/workspace/node_modules/express/lib/router/layer.js:95:5)
at next (/workspace/node_modules/express/lib/router/route.js:137:13)
at urlencodedParser (/workspace/node_modules/body-parser/lib/types/urlencoded.js:100:7)
at Layer.handle [as handle_request] (/workspace/node_modules/express/lib/router/layer.js:95:5)
at next (/workspace/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/workspace/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/workspace/node_modules/express/lib/router/layer.js:95:5)
at /workspace/node_modules/express/lib/router/index.js:281:22

UPDATE: Found the error, have to put the full URL ( “url”: “https://alexa.amazon.com”) after the login settings.

1 Like

I tried it last night while i couldnt sleep and it seems to work perfectly, even works with the fire tablets

Hey!
so fare very nice and right in time :slight_smile:
Does anybody already has set up a pick list to select you favorite radio and or playlist?

And I’m still struggling to use alexa for TTS - actualy I Use my Sonos with that script.
May that would be usefull and suitable for alexa as well:

sonos_say:
alias: Sonos TTS script
sequence:

  • service: media_player.sonos_snapshot
    data_template:
    entity_id: ‘{{ sonos_entity }}’
  • service: media_player.sonos_unjoin
    data_template:
    entity_id: ‘{{ sonos_entity }}’
  • service: media_player.volume_set
    data_template:
    entity_id: ‘{{ sonos_entity }}’
    volume_level: ‘{{ volume }}’
  • service: tts.google_say
    data_template:
    entity_id: ‘{{ sonos_entity }}’
    message: ‘{{ message }}’
  • delay: ‘{{ delay }}’
  • service: media_player.sonos_restore
    data_template:
    entity_id: ‘{{ sonos_entity }}’

okay - I got the TTS part :slight_smile:

even more easy than sonos

  • service: media_player.alexa_tts
    data_template:
    entity_id: “media_player.Stiffs_echo”
    message: “Hello everybody.”

next I try to figure out how to adress the content ID in Amazon music

- service: media_player.play_media
  data_template:   
    entity_id: "media_player.Stiffs_echo"
    media_content_id: ????
    media_content_type: audio/mp3