Echo Devices (Alexa) as Media Player - Testers Needed

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?

HI, thats my script as an example:

question_inside_temperature:
  sequence:
    - service: alexa_media.update_last_called
    - delay: "00:00:01"
    - service: notify.alexa_media
      data:
        target: "{{ states('sensor.last_called_alexa') }}"
        data:
          type: tts
        message: >
          {% if states('sensor.netatmo_imeerbus121_wohnzimmer_temperature') |length > 2 %}
              Die Temperatur im Wohnzimmer beträgt {{ states('sensor.netatmo_imeerbus121_wohnzimmer_temperature') |replace('.', ',') |round(1) }} Grad.
          {% else %}
              Die Temperatur im Wohnzimmer beträgt {{ states('sensor.netatmo_imeerbus121_wohnzimmer_temperature') }} Grad.
          {% endif %}
          {% if states('sensor.wt_schlafzimmer_temperature') | length > 2 %}
              Im Schlafzimmer beträgt die Temperatur {{ states('sensor.wt_schlafzimmer_temperature') |replace('.', ',') |round(1) }} Grad
          {% else %}
              Im Schlafzimmer beträgt die Temperatur {{ states('sensor.wt_schlafzimmer_temperature') }} Grad
          {% endif %}

Expose this to alexa.
In alexa I created a routine “Alexa, what is the temperature inside” and added this script.

3 Likes

this is awesome, thanks for sharing! is there a way to make this more dynamic, where you can ask for the temp of different rooms in the house? or do you need to setup a script per room?

Up to now it is necessary to set up a script per room.
I wrote the complete management of home control in scripts anyway and exposed them to alexa.
Only some input_boolean entities and two spotlights are known to alexa.
That looks then like
scritpt.command_light_on
script.command.light_brightness_up
and so on
That is more comfortable in my point of view and gives more control about the behavior of the devices.

I use a Dummy Bulb exposed to Alexa . Then I only need 1 device in Alexa to trigger 99 events ( use the bulb brghtness levels) . It keeps Alexa Interface clean as I use the mobile alexa app to control HA outside the house

2 Likes

The example I linked from the wiki uses a similar technique but I prefer yours :slight_smile:

The script I linked to above allows you to do up to 255 calls in one script but I personally prefer @lonebaggie’s way to do it.

I must admit … much more elegant architecture :wink: even I would not use the alexa app to control the home.
The routines are not very user friendly to manage and talking to alexa in the train or office is not my favorite :slight_smile:
But anyway not much work to change for me, I only need one controlling script.
Thanks

No not for automation . I use the alexa app when remote , to turn on lights, heating etc. The app is simple with nice large icons and you don’t have to open any ports to HA. I use the cloud integration to push all my HA devices to Alexa
You can use the app without having to talk to alexa, to turn devices on or off , or change temperature, etc , can you image the looks on the train, shouting down the phone :slight_smile:

1 Like

I got most working Thanks. Just want to know if the sensor value can be rounded to whole numbers?

# Automation
- alias: "Alexa Report"
  trigger:
  - platform: state
    entity_id: light.alexa_virtual
    to: 'on'
  condition:
  action:
  - service: alexa_media.update_last_called  #this will force update the last Alexa attribute used by the sensor
  - delay: 00:00:01  # you may need to increase this value if you dont get the response on the echo you asked the question
  - service: notify.alexa_media
    data_template:
      target: 
        -  '{{ states.sensor.last_alexa.state }}' 
      data:
        type: tts
      message: >-
        {% if (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | int  == 1  %}
          The bathroom temp is{{ states('sensor.bathroom_temp') }} degrees

Yes |round(0)