Echo Devices (Alexa) as Media Player - Testers Needed

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:

But we’re not using a skill. And the strings we send don’t support SSML. With the technique used for this media player, you can’t send arbitrary audio files, which is necessary if you want to use Polly.

I know, I wrote the post above for 3 reasons:

  1. To be the one who gets to write post No.700 … :-), I just had to (child in me hasn’t died yet)
  2. To make a point, simple question = simple answer, the question is quoted, he did not relate it in any way with alexa.tts … he just asked if you can use Polly with Alexa … technically you can … easily … :slight_smile:
  3. To entertain myself
1 Like

Well, logically you got the point.

But if you use the context of this topic, I want to use the current component with home assistant to play TTS using Polly to synthesize the words. :slight_smile:

1 Like

ok… I got it to work but seems the solution was strange based on others comment for the URL.

I changed alexa.amazon.com to just amazon.com

I discovered this by going through the alexa.py file and found the login url with the /gp/sign_in.html. I manually tried that URL in a browser and got an exception. So I took the alexa part out and got a sign in page. Made the change in configuration.yaml and --walaaa-- my echo devices show up.

Love seeing the album art and being able to play, pause, skip.

Volume controls don’t seem to work and TTS in the media card doesn’t work but does from the service (she will even tell you that if you try :slight_smile: )

Looking good so far. Look forward to this becoming more feature-ful / stable in the future.

Thanks, alandtse. I didn’t have Logger in my configuration.yaml file for some reason. I was just getting very basic messages in the log. I added the info at your link and am now seeing lots of interesting data.

I just added this to my configuration and everything appeared to be setup properly. I can send tts through the services panel and I can hear it being played on my various devices. However when I add the media player card to my Lovelace setup this is what I see. I have no control. If this correct? I was expecting it to be like all my other media player cards. All my echos seem to be in “standby” mode. Does it only appear like the screenshots in the beginning of this thread when a song is playing?

Echo_Dot_MediaCard

Sorry to ask again, you say all of your sensors, but do you mean ALL, or just all templated Sensors

Like this one Yes

      house_mode:
        value_template: '{{ states.input_select.house_mode.state }}'
        friendly_name: 'House Mode'
        icon_template: >
            {%- if is_state('input_select.house_mode', 'Home') -%}
                mdi:home-account
            {%- elif is_state('input_select.house_mode', 'Away') -%}
                mdi:run-fast
            {%- elif is_state('input_select.house_mode', 'Night') -%}
                mdi:weather-night
            {%- else -%}
                mdi:help
            {%- endif -%}
        entity_id: sensor.time

but would you also for this binary sensor template

 - platform: template
   sensors:
     garage_fridge_warm:
       value_template: "{{ states('sensor.temp_garage_fridge') | float > 40.0 }}"
       entity_id: sensor.time

Lastly, I set this up really not understanding what the purpose of adding entiry_id really was.

 - platform: template
   sensors:
     downstairs_smoke_detector_smoke:
       value_template: "{{ is_state('sensor.smoke_detector_downstairs_alarm_type', '1') }}"
       friendly_name: "Smoke Detector - Smoke"
       entity_id: sensor.smoke_detector_downstairs_alarm_type

Should I replace sensor.time, can I have two? Or is it fine as is?

Thanks again, I’ve added sensor.time to many of my sensors so far, just not sure about these last few

Edit, will adding this to battery templates cause the device to be polled every minute, draining the battery faster?