Echo Devices (Alexa) as Media Player - Testers Needed

I have been having the same issue… The entities just go in to the unavailable state after some time… After some time they come online randomly…

2024-01-28 09:10:57.209 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration alexa_media which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2024-01-28 09:10:57.211 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2024-01-28 09:11:13.326 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 543, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 233, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 31, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 149, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/http.py", line 50, in get
    return await WebSocketHandler(request.app["hass"], request).async_handle()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/http.py", line 275, in async_handle
    await wsock.prepare(request)
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_ws.py", line 153, in prepare
    payload_writer = await super().prepare(request)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_response.py", line 415, in prepare
    return await self._start(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_response.py", line 423, in _start
    await self._write_headers()
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_response.py", line 503, in _write_headers
    await writer.write_headers(status_line, self._headers)
  File "/usr/local/lib/python3.11/site-packages/aiohttp/http_writer.py", line 130, in write_headers
    self._write(buf)
  File "/usr/local/lib/python3.11/site-packages/aiohttp/http_writer.py", line 75, in _write
    raise ConnectionResetError("Cannot write to closing transport")
ConnectionResetError: Cannot write to closing transport
2024-01-28 09:11:39.188 ERROR (MainThread) [alexapy.alexaapi] Giving up _static_request(...) after 5 tries (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)
2024-01-28 09:11:39.188 WARNING (MainThread) [alexapy.helpers] alexaapi.get_customer_history_records((<alexapy.alexalogin.AlexaLogin object at 0xffff82751310>,), {'max_record_size': 10}): An error occurred accessing AlexaAPI: An exception of type AlexapyTooManyRequestsError occurred. Arguments:
('Too Many Requests',)
2024-01-28 09:11:39.189 WARNING (MainThread) [alexapy.helpers] alexaapi.get_last_device_serial((<alexapy.alexalogin.AlexaLogin object at 0xffff82751310>,), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyTooManyRequestsError occurred. Arguments:
('Too Many Requests',)
2024-01-28 09:11:39.189 ERROR (MainThread) [custom_components.alexa_media] Error fetching alexa_media data: Error communicating with API: Too Many Requests
2024-01-28 09:11:39.303 ERROR (MainThread) [homeassistant.components.homeassistant_alerts] Error requesting homeassistant_alerts data: Cannot connect to host alerts.home-assistant.io:443 ssl:default [Network unreachable]
2024-01-28 09:11:43.193 ERROR (MainThread) [custom_components.hacs] <QueueManager> <Plugin ljmerza/tracking-number-card> Repository structure for 3.0.4 is not compliant

Automation to Fix Amazon Alexa Integration going offline
As mentioned by others, reloading the Alexa Media Player integration has been necessary for some time to ensure a reliable connection. After some testing, I found that reloading every five hours did the trick. Here is my automation for anyone interested.

If your integration does happen to go offline routinely during that five hour period, simply decrease to 4 hours and see how that works, etc… This automation will 1) reload the integration, 2) perform a check to make sure it is working, and 3) sending a notification if it fails. Simply change the variable to one of your own “echo_next” entities. Reloading a single entity will reload all entities in the integration. Hope this helps someone.

alias: Fix Amazon Alexa Echo
description: ""
trigger:
  - platform: time_pattern
    hours: /5
condition: []
action:
  - service: homeassistant.reload_config_entry
    data: {}
    target:
      entity_id: "{{ alexa_entity }}"
  - delay:
      minutes: 5
  - repeat:
      while:
        - condition: template
          value_template: "{{ states(alexa_entity) == 'unavailable' }}"
        - condition: template
          value_template: "{{ repeat.index <= 2 }}"
      sequence:
        - service: homeassistant.reload_config_entry
          data: {}
          target:
            entity_id: "{{ alexa_entity }}"
        - wait_template: "{{ states(alexa_entity) != 'unavailable' }}"
          continue_on_timeout: true
          timeout: "00:05:00"
  - condition: template
    value_template: "{{ states(alexa_entity) == 'unavailable' }}"
  - service: notify.notify
    data:
      title: Unavailable
      message: "{{ alexa_entity }}"
variables:
  alexa_entity: sensor.living_room_echo_next_timer
mode: single
4 Likes

hi guys I have searched but found nothing.

I recently added an Shoe 15 on my account but got none players, just alarm entities, is that normal?

And it also just show my email not the name of the device…

Someone that have 15 could reproduce?

Good morning, when updating to version 2024.4, errors appeared when I called the service: it has an action that calls an unknown service: notify.alexa_media

I don’t know if it’s a problem with my installation or if it’s a bug.

I got errors from my echo about actionable notifications that have been working for months. Also every voice command I issue comes back with the device is not responding. All this started with 2024.4

Here i dont have those issues. Everything seems to work correct.

Since HA 2024.3.x I have been getting this error consistently on every restart of HA.

Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:358
integration: Sensor (documentation, issues)
First occurred: 7 April 2024 at 20:26:44 (1 occurrences)
Last logged: 7 April 2024 at 20:26:44

Error while setting up alexa_media platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 358, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 630, in async_add_entities
    or not any(entity.should_poll for entity in entities)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 630, in <genexpr>
    or not any(entity.should_poll for entity in entities)
               ^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/sensor.py", line 591, in should_poll
    return not (self.hass.data[DATA_ALEXAMEDIA]["accounts"][self._account]["http2"])
                ^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'data'

This reported as an issue on the github here

Sensor error on restart reported above happening to me too since 2024.3. AMP is up to date and the issue linked above was dismissed & assigned to the op, then closed.

Another issue was reopened, then closed as a duplicate. At this point, it’s not an isolated issue.

Can we have a fix for this please?

1 Like

I think you’ll find the issue is still open.

You’re right. My bad. Was looking at the duplicate issue.

Hi All,

Since some time (sorry I don’t know whet it started) I see this in the log:


2024-04-20 02:05:56.282 ERROR (MainThread) [alexapy.alexaapi] Giving up _static_request(...) after 5 tries (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)

2024-04-20 02:05:56.282 ERROR (MainThread) [custom_components.alexa_media] Error fetching alexa_media data: Error communicating with API: Too Many Requests

Sometimes once, sometimes multiple times.

That’s Amazon telling you to connect less. Nothing we can do about that.

Any way to reduce it? I send max 7 times a day something to speak it out

Based on the non-replies to similar questions earlier in this thread, I think I can guess that the answer is “no”, but is there a way to get temperature and/or motion sensor information from the 4th generation and newer Echos?

I do have it working and have these entities associated with each of my Echos: media player, next alarm, next reminder, next timer, do not disturb switch, repeat switch, shuffle switch.

Edit: Hmm… I have 10 echos in my account though and it looks like I’m getting Too Many Requests API errors even though I’m not doing anything (no activity on any of my echos), so it seems that this probably won’t work for me anyway.

The answer is actually yes.

To get the temperature you have to click on “Configure” and then check the “Include devices connected via Echo” box. It is working well enough for me, even if I also sometimes get the Too Many Requests error.

Getting the presence can be done by creating two routines in the Alexa app to turn on/off a HA input boolean when the presence changes.
But in my opinion, after testing every possible settings, it is not so useful because it is too sensitive and cannot be used for room presence (only for home presence, but I think there are better options for that).

1 Like

Is there a way to suppress Alexa from announcing what it is about to do after you request an action through a script? Rather, it just does what you ask, missing out the announcement. E.g. In script you ask “Play my media” and Alexa anounces “Playing your blah blah playlist from My Media” and then starts the music. Can we not just go straight to the nusic?

That’s not possible as it happens on Amazon’s side.

1 Like

OK. Thanks for answering.

1 Like

I just realized today that none of my echo devices are playing notifications.

I’m not seeing anything in the logs for an error.

I’ve tried manually running automations and everything else works except speaking announcements on Alexa. I unplugged the one right here and plugged it back in but still not getting anything.

No alerts in HA that I need to reauth or reconfigure the integration.

I went into Developer Options and manually ran the notification service to various devices and it says it ran ok but I’m not hearing anything.

Is there something else I can check?

Thanks!

-Tim

Nevermind… they are working now.

I ended up restarting them all. We had an internet outage (GASP!) for most of the day on Friday.

I also logged in to Alexa on my phone and it showed me that the other devices were offline so I went and power cycled them as well. They aren’t showing online yet so not sure what the hold up is. But I did at least get an announcement on the one in this room recently so HA is working.

-Tim