Echo Devices (Alexa) as Media Player - Testers Needed

Since installing this, I’ve been forced to change my Amazon password numerous times. I’m still to work out how to use alexa with HA, even after signing up for the free month of nabu casa

Yes, today i did it again and it finally worked fine! Thanks!

Since I can’t do analytics directly, here’s a google form where you can let me know about your reauth experiences. I’d also appreciate people with good experiences to chime in so we can figure out if it’s a setting that’s causing people problems.

Hi alantse, I answered the questionaire twice. In my first one, I estimated the reauth frequency with 10 days. Rechecking my SMS shows, that I have to reauth exactly every 14 days. So if possible, ignore or delete my first record. (DE, every 10 days, 25 api calls)

Trying to get a different Echo, using ‘sensor.last_alexa’, to announce the value of ‘sensor.kitchen_echo_next_timer’ as it is shown in the front-end card, ie ‘in six minutes’ rather than using the actual sensor value, ie ‘2020-11-23T09:41:38+00:00’ which I currently use to produce ‘The kitchen timer will go off at nine forty one’ like this…

The kitchen timer will go off at {{ as_timestamp(strptime(states(‘sensor.kitchen_next_timer’), ‘%Y-%m-%d %H:%M:%S’)) | timestamp_custom(‘%-I:%M’) }}

Hoping to end up with something relatively simple like …

The kitchen timer will go off {{ state_attr(‘sensor.echo_next_timer’, ‘message’) }}

…as the sensor card has already done the hard work and that format is what I ideally need to fit in with the way I have Alexa call announcements from HA using @lonebaggie’s genius dummy light technique. Adding other sensors to call on to make it a simple message is obviously fine.

Have adapted this…

…to create a script I can expose to Alexa and although it works I’d like to get something into the format described above if possible…

kitchen_timer:
  sequence:
  - service_template: '{% set name = states(''sensor.last_alexa'').split(''.'') %}
      notify.alexa_media_{{name[-1]}}

      '
    data_template:
      message: >-
        {%- if states.sensor.kitchen_next_timer.state != "unavailable" -%}
        {%- set sorted_active = states.sensor.kitchen_next_timer.attributes.sorted_active | from_json -%}
        {%- set duration = (sorted_active[0][1].remainingTime / 60000) | round(0) -%}
        {%- set remaining = (((as_timestamp(states.sensor.kitchen_next_timer.state) - as_timestamp(now())) / 60) | int) -%}
        You have {{ remaining }} {{ "minutes" if duration > 1 else "minute" }} left on your kitchen timer.
        {%- endif -%}
      data:
        type: tts
        method: all

Any suggestions gratefully received.

Thanks for the mention :slight_smile:

If your sill using my Speech engine

You can extract time and date info

2 Likes

You’re more than welcome :+1:

I did actually use that code, great find, and it works a treat but went back to basics for this post so as not confuse/put off people who aren’t familiar with it from helping out if they can and also to show that I have tried and got stuck rather than just expect someone else to do it for me :grin:

Just here to chime in a bit late, but still. Thank you for all of your hard work on this project. The re-authentication is no problem for me. It really is a tiny price to pay for such an amazing integration.

Also wanted to add that I solved the “Detected a Password Reset” prompt by simply changing my Amazon password to be something under 14 characters and it re-authenticated instantly while also putting my 2FA code in.

2 Likes

@PlayedIn How did you get Multiroom Music (speaker groups) to work? When I call the service for an Alexa speaker group, I get no response at all or errors in the log.

Wiki.

I thought I would provide some info of my most recent relogin experience. I tried the google spreadsheet, but thought I could add more information here instead. Today I upgraded HA to latest and followed up by upgrading Alexa Media Player to latest (3.3.0). A couple of hours later (perhaps by coincidence from the upgrade, not sure), got the following Log:

alexaapi.get_notifications((<alexapy.alexalogin.AlexaLogin object at 0x7fc46c6ae280>,), {}): An error occured accessing AlexaAPI: An exception of type TimeoutError occurred. Arguments: ()
4:17:08 PM – /opt/homeassistant/venv_3.8/lib/python3.8/site-packages/alexapy/helpers.py (WARNING)
AlexaLogin session is missing required token: 'csrf' This may result in authorization errors, please report
4:12:26 PM – /opt/homeassistant/venv_3.8/lib/python3.8/site-packages/alexapy/alexaapi.py (WARNING) - message first occurred at 4:12:26 PM and shows up 13 times
alexaapi.get_devices((<alexapy.alexalogin.AlexaLogin object at 0x7fc46c6ae280>,), {}): A login error occured: An exception of type JSONDecodeError occurred. Arguments: ('Expecting value: line 1 column 1 (char 0)',)
4:12:09 PM – /opt/homeassistant/venv_3.8/lib/python3.8/site-packages/alexapy/helpers.py (WARNING) - message first occurred at 4:12:08 PM and shows up 4 times
websocket connection is closing.
4:12:09 PM – /opt/homeassistant/venv_3.8/lib/python3.8/site-packages/alexapy/aiohttp/http_websocket.py (WARNING) - message first occurred at 4:12:08 PM and shows up 4 times
Websocket is missing ubid-main and ubid-acbcom cookies; please report this if anything isn't working.
4:12:08 PM – /opt/homeassistant/venv_3.8/lib/python3.8/site-packages/alexapy/alexawebsocket.py (WARNING)

I also received the following two notifications:

At least one of your integrations requires reconfiguration to continue functioning. Check it out.

and

Alexa Media Reauthentication Required
Reauthenticate on the Integrations page. Relogin required after 2:30:17.495143 and 19 api calls.

The Reauth itself went as usual, had to do it a couple of times to take. My only nit feedback for this, is when successful you get Aborted (along with Alexa Media Player successfully reauthenticated.) When I see Aborted I at first think something went wrong, but finish reading the rest of the message which makes me :slight_smile: :slight_smile:

Again, thanks for your work on this!!!

EDIT: I meant to add that the scan_interval is the default; using .com domain; using auth app; and it has been oh around 3-4 weeks since the last re-auth.

That’s coming from HA. I have no control on that and I have submitted feedback that it’s misleading. With 3.3.0 if you also set up the Built-in 2FA app it should be able to auto relogin assuming there isn’t a captcha

2 Likes

Hi @alandtse, what do you mean with "built-in 2fa app’?

New feature just added in 3.3.0

1 Like

I had to reauth today and got this error.
It’s just for info, the reauth worked in the end even I had to enter the captcha 4 times.
It’s version 3.3.0

Logger: homeassistant.util.logging
Source: util/logging.py:108
First occurred: 9:27:29 (1 occurrences)
Last logged: 9:27:29

Exception in _handle_event when dispatching 'alexa_media_p**t@j************e': ({'player_state': {'destinationUserId': 'AW8IZS06RS67A', 'dopplerId': {'deviceType': 'A7WXQPH584YP', 'deviceSerialNumber': 'G2A0RF0483620129'}, 'bass': 3, 'midrange': 1, 'treble': 6}},) Traceback (most recent call last): File "/config/custom_components/alexa_media/media_player.py", line 390, in _handle_event await _refresh_if_no_audiopush(already_refreshed) File "/config/custom_components/alexa_media/media_player.py", line 278, in _refresh_if_no_audiopush await self.async_update() File "/config/custom_components/alexa_media/helpers.py", line 159, in _catch_login_errors result = await func(*args, **kwargs) File "/config/custom_components/alexa_media/media_player.py", line 814, in async_update await self.refresh( # pylint: disable=unexpected-keyword-arg File "/config/custom_components/alexa_media/helpers.py", line 159, in _catch_login_errors result = await func(*args, **kwargs) File "/config/custom_components/alexa_media/media_player.py", line 545, in refresh session = await self.alexa_api.get_state() File "/usr/local/lib/python3.8/site-packages/alexapy/helpers.py", line 127, in wrapper return await func(*args, **kwargs) File "/usr/local/lib/python3.8/site-packages/alexapy/alexaapi.py", line 975, in get_state return await response.json(content_type=None) if response else None File "/usr/local/lib/python3.8/site-packages/alexapy/aiohttp/client_reqrep.py", line 1074, in json await self.read() File "/usr/local/lib/python3.8/site-packages/alexapy/aiohttp/client_reqrep.py", line 1023, in read self._body = await self.content.read() File "/usr/local/lib/python3.8/site-packages/alexapy/aiohttp/streams.py", line 371, in read block = await self.readany() File "/usr/local/lib/python3.8/site-packages/alexapy/aiohttp/streams.py", line 393, in readany await self._wait("readany") File "/usr/local/lib/python3.8/site-packages/alexapy/aiohttp/streams.py", line 307, in _wait await waiter File "/usr/local/lib/python3.8/site-packages/alexapy/aiohttp/helpers.py", line 655, in __exit__ raise asyncio.TimeoutError from None asyncio.exceptions.TimeoutError

Hey, so when I call the service like this:

alias: Alexa TTS Test
sequence:
  - service: notify.alexa_media_administrator
    data:
      message: test
      data:
        type: tts
      target:
        - media_player.noel
mode: single

It will say that it enacted the script, but nothing will happen.
I’m new to this so bear with me if this is simple.

Can This be used to ask Alexa what the temperature and Humidity is in the Livingroom?

Yes. I wrote a script which I exposed to Alexa.

I have already installed Alexa media player. Is there somewhere I can find some examples for the scripts on how to do it?