Echo Devices (Alexa) as Media Player - Testers Needed

Hi,

I also testet amazon prime yes. It seems that no status at all is getting collected:


How can I best debug this?
I am using newest hassio and sitting in germany.
The addon log look like this:

got request for getDevices
got getState for  device: 7094180751441CJQ
got getState for  device: d301d1d2f225409bb7e9961700cad079
got getState for  device: b96454b9645e4dd2bcd6ffb81b378c0b
got getState for  device: 24fd69af48844fb78aa026dbae2c7cf8
got getState for  device: G090LF11741608R0
got getState for  device: ca69be5cdb874b74b4d2ea87ad5c7f12
got getState for  device: 14a4c9ed6d2a45bbbda0b47f52d10839
got getState for  device: 35e398bcf28946c497ea3b825ef0c354
got getState for  device: 6e917ac1070549dbb74c02fe6d47fe44
got getState for  device: G090LF1180340C7E
got getState for  device: G2A0P30774060QRT
got getState for  device: 30559f9c4cd247a1a2d8ebfb9d8d7df2
got getState for  device: 1084C963D52F4E85BB2556000DC1CA7A

Perhaps there is an easy way to print the json result of the call to get the status. But I am not familar with python, so dont know how to modify your alexa.py file…

EDIT:

I checked your code a bit. You use the following:

setup_alexa('addon_9ff8aed5_alexaapi', hass, config, add_devices_callback)

def setup_alexa(host, hass, config, add_devices_callback):
"""Set up a alexa api based on host parameter."""
alexa_clients = hass.data[ALEXA_DATA]
alexa_sessions = {}
track_utc_time_change(hass, lambda now: update_devices(), second=30)

@util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS)
def update_devices():
    """Update the devices objects."""
    try:
        req = requests.post('http://' + host + ':8091/alexa-getDevices')

there you define your host as addon_9ff8aed5_alexaapi

and than you call http://’ + host + ':8091/alexa-getDevices wich results in calling

http://addon_9ff8aed5_alexaapi:8091/alexa-getDevices

I think thats wrong. Dont you need to access the addon here?
Regards

@keatontaylor Wow. It works! Good work! Just tested TTS and have been struggling with the other script and cookies for days without success. This one https://github.com/walthowd/ha-alexa-tts

Ok I did further debugging by myself and now I get the following:

curl -d '{"deviceSerialNumber": "G2A0P30774060QRT"}' -H "Content-Type: application/json" -X POST http://192.168.1.11:8091/alexa-getState

{"statusCode":403,"body":"{\"message\":\"user not authorized\"}","headers":{"server":"Server","date":"Fri, 06 Jul 2018 13:06:18 GMT","content-type":"application/json","content-length":"33","connection":"close","x-amzn-requestid":"5ebb2e6a-811d-11e8-ba66-955c17d0600e","x-amzn-alt-domain":"https://alexa.amazon.de/logout","vary":"Accept-Encoding,User-Agent"},"request":{"uri":{"protocol":"https:","slashes":true,"auth":null,"host":"pitangui.amazon.com","port":443,"hostname":"pitangui.amazon.com","hash":null,"search":"?deviceSerialNumber=undefined&deviceType=undefined","query":"deviceSerialNumber=undefined&deviceType=undefined","pathname":"/api/media/state","path":"/api/media/state?deviceSerialNumber=undefined&deviceType=undefined","href":"https://pitangui.amazon.com/api/media/state?deviceSerialNumber=undefined&deviceType=undefined"},"method":"GET","headers":{"Cookie":"session-id=138-3162072-7641115; session-id-time=2161602325l; csm-hit=7DFV7P9MWFBZBAPHP8W8+s-7DFV7P9MWFBZBAPHP8W8|1530882334424; ubid-main=130-7496092-0604654; x-main=ZNRyKN5Obtzcn6HO3FJqqoziaBeSEBOr; at-main=Atza|IwEBIFZ2MVwjn1lzv2J-khKw0qy1tg034BI2-HRg5u5qMxkRM1D1yCXXNAr87idwLwGeJPHVMP0894n_IZqiowMg7REzz7NGItVwrGs0rFq5KyubamjAu-i4JnMU2nc09qdkOJ7TkfqBo4W92yFjW_8GJr5axbHmXaadHcW7HHRtb1PBPEiMJMoM0R-ZIxBA2XPFUzyqMQzfGcAf2GripK6RWZPpTygscfi0GNY-UZNwrynThsClpkAVrXn-OiEsPfy4RaZA0Q4oNCdGrwhjx6-AYMKfmKCgZZUTbrktsEV4KrcqOCsqnO6LWsv1CwNSzxPv1BRZSHBLEFq7M5F1yfuWgkyUEihoA1QosjWWh1qreI7YHY5bQaBEGVNcrNufR6zX0B8pf6IwBR07yJYaW-MVUO5J; sess-at-main=\"xdZ2GTeWB3+VkscAstz8/bTkfpySjMcM5Iau/WVJz+M=\"; csrf=775519716; ","csrf":"775519716"}}}#

Now I have no further plan whats going on…

You were able to get the TTS through Alexa working with this new Echo media player? I’ve been having trouble as well with that script.

Is there an easy way to send TTS to all devices or must we loop over them in a script?

Is there an easy way to send TTS to all devices or must we loop over them in a script?

While I haven’t implemented this yet for my Echo’s with my current Sonos and DLNA speakers I can invoke all of them at once by throwing them in a group. This sometimes has mixed results where it plays on 2/3 and other times it knocks out all 3.

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.