Echo Devices (Alexa) as Media Player - Testers Needed

Hi
Can someone help me get this working? I have this error when I restart HA after following the instructions above;

Log Details (ERROR)
Sun Aug 19 2018 20:00:53 GMT+1200 (New Zealand Standard Time)

Testing configuration at /config
ERROR:homeassistant.scripts.check_config:BURB
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/scripts/check_config.py", line 207, in check
    res['components'] = check_ha_config_file(hass)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/scripts/check_config.py", line 372, in check_ha_config_file
    platform = loader.get_platform(hass, domain, p_name)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/loader.py", line 58, in get_platform
    return get_component(hass, PLATFORM_FORMAT.format(domain, platform))
  File "/usr/local/lib/python3.6/site-packages/homeassistant/loader.py", line 86, in get_component
    module = importlib.import_module(path)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 674, in exec_module
  File "<frozen importlib._bootstrap_external>", line 781, in get_code
  File "<frozen importlib._bootstrap_external>", line 741, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/config/custom_components/media_player/alexa.py", line 93
    if failed_login:
    ^
IndentationError: unexpected indent
Fatal error while loading config: unexpected indent (alexa.py, line 93)
Failed config
  General Errors: 
    - unexpected indent (alexa.py, line 93)
Successful config (partial)

This looks like the file was downloaded incorrectly from github. Did you copy and paste it or did you save the raw file? I would try to save the raw file from github.

1 Like

Thanks alandtse,

I thought that I copied the raw file, how ever I have just copied it again and now I’m getting a different error message;

Log Details (ERROR)
Mon Aug 20 2018 19:35:01 GMT+1200 (New Zealand Standard Time)

Error while setting up platform alexa
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 346, in _get_idna_encoded_host
    host = idna.encode(host, uts46=True).decode('utf-8')
  File "/usr/local/lib/python3.6/site-packages/idna/core.py", line 361, in encode
    s = alabel(label)
  File "/usr/local/lib/python3.6/site-packages/idna/core.py", line 284, in alabel
    check_label(label)
  File "/usr/local/lib/python3.6/site-packages/idna/core.py", line 261, in check_label
    raise InvalidCodepoint('Codepoint {0} at position {1} of {2} not allowed'.format(_unot(cp_value), pos+1, repr(label)))
idna.core.InvalidCodepoint: Codepoint U+201C at position 1 of '“alexa' not allowed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 394, in prepare_url
    host = self._get_idna_encoded_host(host)
  File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 348, in _get_idna_encoded_host
    raise UnicodeError
UnicodeError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 129, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/media_player/alexa.py", line 115, in setup_platform
    login = AlexaLogin(url, email, password, hass)
  File "/config/custom_components/media_player/alexa.py", line 571, in __init__
    self.login(cookies=cookies)
  File "/config/custom_components/media_player/alexa.py", line 670, in login
    resp = self._session.get(site)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 525, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 498, in request
    prep = self.prepare_request(req)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 441, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 309, in prepare
    self.prepare_url(url, params)
  File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 396, in prepare_url
    raise InvalidURL('URL has an invalid label.')
requests.exceptions.InvalidURL: URL has an invalid label.

I am running Hassio and I originally downloaded the add-on (which I don’t believe I need anymore) , so I tried to delete it, but for some reason it won’t delete, could this be related?

Also, I am adding the file through Samba, and using Xcode as the editor, I get this message when saving, could this be my problem?

Can you try just using your browser’s “Save as” function when you’re at the raw file and then copying alexa.py where you need it? It looks like the file is getting mangled by trying to paste it in the editor.

Hi alandtse,

I have tried that and I’m getting the same issue, could it be the add-on? And if so, how can I remove it if the uninstall isn’t working? It works for the rest of the add-ons.

I installed and HA is not showing any Echo devices. I had an issue at first with using quotes in the configuration.yaml file but read the thread and took them out as someone said. Now the module seems to load but the log is saying “taking too long (60 seconds), continuing boot sequence”. And I have no Echos that show up :frowning: I can’t seem to find any other logs that may be helpful (like the mention of /tmp/alexa).
I am running HA from docker.
EDIT: I should have mentioned I am new to HA (a week into it) coming from Vera (for 10 years). So that may be why I don’t know where logs are or how to troubleshoot this further. I am not familiar with the HA startup sequence.

So I’ve got the Echo/Alexa interface working with ‘text to speak’ (that is SOOO KOOL!). By the way, the upgrade to 0.76.1 didn’t break it.
Have my twitter API developer codes in hand. Now I want to play with creating a script to monitor for a certain individual’s twitter posting to trigger Alexa to make a certain verbal announcement. Anyone willing to give this newbie on HA a hand?

No, I don’t think its the add-on. The new error is complaining because you have a unicode quotation mark in your url config. If you remove the quotation marks does that change anything for you?

@RandyA:
In your config directory you should see a home-assistant.log. To debug a custom_component you’ll need to edit the Logger component to change logging for at least the alexa component to Debug. See here (you can ignore the rest of the post as the debug mode code is by default in now).

Thanks alandtse,

I’m assuming that you mean the " either side of the url in the configuration.yaml file. I have removed them and this is now the error.

Log Details (ERROR)
Tue Aug 21 2018 19:32:09 GMT+1200 (New Zealand Standard Time)

Error while setting up platform alexa
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 171, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 56, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/local/lib/python3.6/socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name does not resolve

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 849, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 314, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 180, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x6fe2e9d0>: Failed to establish a new connection: [Errno -2] Name does not resolve

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 445, in send
    timeout=timeout
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='alexa.alexa.amazon.com', port=443): Max retries exceeded with url: /api/devices-v2/device (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x6fe2e9d0>: Failed to establish a new connection: [Errno -2] Name does not resolve',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 129, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/media_player/alexa.py", line 115, in setup_platform
    login = AlexaLogin(url, email, password, hass)
  File "/config/custom_components/media_player/alexa.py", line 571, in __init__
    self.login(cookies=cookies)
  File "/config/custom_components/media_player/alexa.py", line 670, in login
    resp = self._session.get(site)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 525, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 512, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 513, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='alexa.alexa.amazon.com', port=443): Max retries exceeded with url: /api/devices-v2/device (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x6fe2e9d0>: Failed to establish a new connection: [Errno -2] Name does not resolve',))

What are you using for a URL in the config file? It should be just amazon.com.

@SMARTMEDIA Would you like to share the script? I just did the same as you but it read everything. I have not used scripts in HA before. How do you call them?

Here is an example is a simple script, should be easy to determine what needs to be changed for your configuration

#===============================================================================

# ALEXA says: Sensor value ... Command execution, complete !

#-------------------------------------------------------------------------------
alexa_tts_test_call:

  alias: "Alexa tts test call"

  sequence:

  # Cancel "execute" script, in case it has timers, to reset them
    - service: script.turn_off
      data:
        entity_id: script.alexa_tts_test_execute

  # Call "execute" script into action again
    - service: script.turn_on
      data:
        entity_id: script.alexa_tts_test_execute

#-------------------------------------------------------------------------------
alexa_tts_test_execute:

  alias: "Alexa tts test execute"

  sequence:

    - service: media_player.alexa_tts
      data_template:
        entity_id: media_player.batman
        message: “ The outside temperature is {{states ('sensor.dark_sky_apparent_temperature') }} degrees ... Command execution, complete ! ”

#===============================================================================

Create a new script file, and copy/paste the above example.
As you can see, there are 2 scripts above. All my scripts have a call and an execute.
The call script cancels the execute script, then calls it into action again … if you have delays or timers … you will not want to call the same script if its already running.
If you want to call the script from an automation, you call the script with call at the end and it does the rest … meaning it will call the execute for you … :slight_smile:

Replace media_player.batman with the device of your choice.
Replace sensor.dark_sky_apparent_temperature with some sensor of your choice.

1 Like

I’m not seeing many people reporting this any more, but I’m still getting this a lot. The site itself is very responsive via standard browser. Any recommendations. I’m sure it’s not the cause, but I’ve also starting noticing logon errors with other components (ecobee), etc from time to time, so not sure if this is causing excess traffic, or the latest update has caused slowdown. Really just seeing if others are having similar issues

Updating alexa media_player took longer than the scheduled …

… that was in the logs since before v.0.0.0.1 … :slight_smile: … because is not about the component, is about the availability of Amazon servers and access times for your geographical region, I believe.

1 Like

Hi, I would like to use my Alexa to TTS using another language rather than English or native Alexa languages. With Google Home I can use another TTS like Amazon Polly to play TTS but this component doesn’t support that. Its possible somehow to use Amazon Polly with Alexa?

Interesting. Does Alexa speak foreign languages? Probably.

But, your Alexa will speak anything that is in your script, right? Although I guess if the language for the echo was English and you provided French words in the template, it would probably horribly mispronounce the words

Yeah, I tested it and she mispronounce the words because the tts service is using Alexa.Speak service which only supports the languages alexa supports natively ofc. I know that google home users can use Amazon Polly which makes the tts as mp3 or similar and then use google mini to play it.

So, you’re looking to have Alexa speak a language that is not officially supported by the echo yet? If you look at your history in the alexa app, you’ll see that this is really just doing a “simon says TEXT HERE” command to your echo. It’s a great way to get it to speak. That’s why it does not support the native TTS, etc. It’s really not doing TTS, its just using the native alexa capabilities. If you set your echo language to the language you wanted to speak (if supported), I’d think it would pronounce it correctly.

I’ve never messed with language settings, what languages are supported? Do you know? Can you set one echo to one language and another to a different language?

… sure, easily … I repeat … EASILY !

How ?, easy … :slight_smile: … just go here: read this, and you’re all set !

Have a glance at it: