Echo Devices (Alexa) as Media Player - Testers Needed

I can confirm that making THESE changes to the notify.py file, and deleting the pickle file, fixes the issue after a reboot.

FWIW, disabling Hassio Cloud integration (cloud:) stops the errors, even with alexa_media still enabled and configured (it’s not working though).

Is it possbile to make the alexa_media_player use the Synology Audio Station with Home Assistant. It were brilliant. thx

Ok, so do we (users) need to do something manually or will it fix itself with the next update(s)?

@h4nc if you edit the notify.py file, with the linked changes, and delete the alexa pickle, it fixes the issue. No need to wait for an update to roll out.

1 Like

2.1.0 is out.

Should have squashed all login bugs. :sweat_smile: If I missed one, please use 1.4.1 to login. Also addressed some minor bugs related to bluetooth. New feature bump is the ability to exclude switches/alarm_control_panels, etc. Use the exclude_devices options described in the link below.

For those of you using include please note all your switches/Alexa Guard devices will not appear until you include them.

Include only loads devices that have been listed. If you didn’t include the Alexa guard or the switches, then you will not see them. If you want to figure out the names, then let the component run once without any include_devices settings and save the names. Alexa Guard is admittedly difficult since it includes part of it’s serial number at the end. The other switches should follow a standard naming convention, e.g. “Echo Bedroom do not disturb switch”, “Echo Bedroom repeat switch”, “Echo Bedroom shuffle switch”.

FYI, found one bug where you’ll see a warning on startup from your recorder. Decided the login issues where more important to resolve but let me know if the bug impacts you more than the warning.

For those on hassio, you may have to restart 2-3 times before HA will load the dependencies.
Please note, we’ve swapped repositories to custom-components. If you haven’t done so, please reinstall from HACS so it tracks from the new repo.

Feature

  • allow exclusions for alarm_control_panel and switches (169545f) - Use the full friendly name (e.g., “Master Bedroom repeat switch”)

Fix

  • update to alexapy 1.0.2 (3e50526) (fixes #307, fixes #310?, fixes #323)
  • change platform loading to be account specific (bcc0de7) (fixes #260?)
  • add key check for targets (fac356d) (fixes #328)
  • provide updated message for use of HA tts UI (46b9d88)
  • bug where bluetooth state not properly updated (c5da965) (fixes #316)
  • add await for set_bluetooth (e622497)(fixes #316)

Full changelog.

As always, please use the the Wiki and FAQ if you need instructions or have questions. Also, please help in documenting features in the wiki since this thread is basically unsearchable now. We also use GitHub for bug reports/feature requests .

2 Likes

Hi alandtse,
thank you again for your job and patience.
I’m replying here because different errors came up after 2.1.0 update, let me show you some screenshots and reports.

After clicking ‘configure’ on the alexa persistent notification, it correctly asks me the double authentication code but after ‘confirm’ this is what I get:

‘Failed call to service configurator/configure . ’

which is a bit different from the previous error in 2.0.1 version [ ‘Failed call to service configurator/configure . get’ ].

Logs:

  1. custom_components/alexa_media/init.py (ERROR):
    Login successful, but AlexaLogin session is missing required token: 'csrf' please try to relogin but if this persists this is unrecoverable, please report.

  2. core.py (ERROR):
    Error doing job: Unclosed client session.

  3. core.py (ERROR):
    Error doing job: Unclosed connector

  4. custom_components/alexa_media/init.py (ERROR):

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 130, in handle_call_service
    connection.context(msg),
  File "/usr/src/homeassistant/homeassistant/core.py", line 1235, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1260, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/components/configurator/__init__.py", line 235, in async_handle_service_call
    await self.hass.async_add_job(callback, call.data.get(ATTR_FIELDS, {}))
  File "/config/custom_components/alexa_media/__init__.py", line 166, in configuration_callback
    login, callback_data)
  File "/config/custom_components/alexa_media/__init__.py", line 156, in setup_platform_callback
    await login.login(data=callback_data)
  File "/usr/local/lib/python3.7/site-packages/alexapy/alexalogin.py", line 344, in login
    site = await self._process_page(await post_resp.text(), site)
  File "/usr/local/lib/python3.7/site-packages/alexapy/alexalogin.py", line 494, in _process_page
    assert self._data is not None
AssertionError

Thank you
SoL

1 Like

I got the same error as SoL in v2.1.0.

Home Assistant frontent reports this after the “Please hit confirm to begin login attempt.” submission :

Failed call to service configurator/configure .

And prints this in the logs:

Login successful, but AlexaLogin session is missing required token: 'csrf' please try to relogin but if this persists this is unrecoverable, please report

as suggested by alandtse I logged in with 1.4.1 and then upgraded to 2.1.0 correctly.

1 Like

I logged in using 1.4.1, but it does not work for me after I update to 2.1.0

FWIW, I upgraded to 2.1.0 this morning, was successfully able to use the configurator and all of my Alexa Media devices were re-found and are working.

If folks are still seeing the

File "/usr/src/homeassistant/homeassistant/components/alexa/state_report.py", line 103, in async_send_changereport_message

errors. These are coming from the Home Assistant Hassio Cloud integration (Nabu Casa). The only way to get rid of them is to disable the integration. Otherwise you get about 1 every 3 seconds.

Thanks @alandtse for all of the hard work and quick response to the errors in 2.0.1.
On that Recorder “warning”, I also noticed the password was being recorded in clear text. Can that be masked? I wasn’t expecting the password to show up in the log.

I don’t know if this is related. I just updated to 98.2 and I can no longer announce to my echo devices. It looks like home assistant can no longer see the entity.

custom_components.alexa_media.notify] Invalid Home Assistant entity in

Any thoughts?

Got it working again. I removed the files out of /custom_components/alexa_media/ replaced them with the master branch. Restarted home assistance, it asked me to authenticate and bam.

Have you reinstalled alexa via Hacs

Thanks for reporting. Will need logs from the login attempt to figure out whether we can do anything. The issue is we’re not getting all the required information from Amazon after signing in. It’s possible we can discover the CSRF token, but because Amazon requires it after this point we actually abort the login process so not to keep hammering Amazon. The other errors are the result of aborting the process.

Can’t really help without knowing the specific errors from the logs.

Not until we fix the warning.

There’s a race condition where notify starts before the media players have loaded so it loses the targets. Will need to fix this later. If you’re able to create an issue, that would help me.

Just updated from v2.0.1 to v2.1.0, working great, no issues for me apart from the Event is not JSON serializable: recorder error on startup :slight_smile:

Looks like there is some bug with include_devices. When, I use:

alexa_media:
  accounts:
    - email: !secret amazon_user
      password: !secret amazon_pass
      url: amazon.com
      include_devices:
        - "Echo Dot Gen2"

it does not work for me. I get the following in my logs:

2019-09-03 13:10:31 DEBUG (MainThread) [custom_components.alexa_media] a*******o@g*******m: Websocket succesfully connected
2019-09-03 13:10:35 DEBUG (MainThread) [custom_components.alexa_media] a*******o@g*******m: Found 20 devices, 1 bluetooth
2019-09-03 13:10:35 DEBUG (MainThread) [custom_components.alexa_media] Locale en-us found for G************6XR
2019-09-03 13:10:35 DEBUG (MainThread) [custom_components.alexa_media] DND False found for G************6XR
2019-09-03 13:10:35 DEBUG (MainThread) [custom_components.alexa_media] a*******o@g*******m: Existing: [] New: ['Echo Dot Gen2']; Filtered out by not being in include: ["Rashmi's Alexa Apps", "Alok's 2nd Fire TV", "Alok's 4th Fire TV", 'Master AFTV', "Alok's 2nd Fire", "Alok's 3rd Fire", 'My Dash', "Alok's 4th Fire", "Alok's 5th Fire", "Alok's 6th Fire", "William's TAB🗼", 'Family Room', 'LivingRoomSonos', "Alok's Echo Dot", "Alok's 2nd Fire TV Stick", 'AFTVMaster', 'AFTV4kStick', 'This Device', "Alok's Alexa Apps"] or in exclude: []
2019-09-03 13:10:36 DEBUG (MainThread) [custom_components.alexa_media] a*******o@g*******m: Updated last_called: {'serialNumber': 'G************6XR', 'timestamp': 1567432857731}
2019-09-03 13:10:36 DEBUG (MainThread) [custom_components.alexa_media] a*******o@g*******m: last_called changed:  to {'serialNumber': 'G************6XR', 'timestamp': 1567432857731}
2019-09-03 13:10:36 DEBUG (MainThread) [custom_components.alexa_media.switch] Loading switches
2019-09-03 13:10:36 DEBUG (MainThread) [custom_components.alexa_media.switch] Media Players not loaded yet; delaying load
2019-09-03 13:10:36 DEBUG (MainThread) [custom_components.alexa_media.media_player] a*****o@g*******m: Refreshing Echo Dot Gen2
2019-09-03 13:10:36 DEBUG (MainThread) [custom_components.alexa_media.media_player] Echo Dot Gen2: Last_called check: self: G************6XR reported: 
2019-09-03 13:10:36 DEBUG (MainThread) [custom_components.alexa_media.helpers] a*******o@g*******m: Adding [<Entity Echo Dot Gen2: standby>]
2019-09-03 13:10:36 DEBUG (MainThread) [custom_components.alexa_media.alarm_control_panel] a*******o@g*******m: Discovered Alexa Guard 227b3: AAA_OnGuardSmartHomeBridgeService_eXYZ01-9XYf-3XY2-9701-13XYZb3 07XYZ8-daa1-45c5-ac7e-51XYZe1
2019-09-03 13:10:36 DEBUG (MainThread) [custom_components.alexa_media.helpers] a*****o@g*******m: Excluding device: <Entity Alexa Guard 227b3: None>
2019-09-03 13:10:51 DEBUG (MainThread) [custom_components.alexa_media.media_player] a*******o@g*******m: Refreshing Echo Dot Gen2
2019-09-03 13:10:51 DEBUG (MainThread) [custom_components.alexa_media.media_player] Echo Dot Gen2: Last_called check: self: G************6XR reported: G************6XR
2019-09-03 13:10:51 DEBUG (MainThread) [custom_components.alexa_media.switch] Loading switches
2019-09-03 13:10:51 DEBUG (MainThread) [custom_components.alexa_media.switch] a*******o@g*******m: Found G************6XR dnd switch with status: False
2019-09-03 13:10:51 DEBUG (MainThread) [custom_components.alexa_media.switch] a*******o@g*******m: Found G************6XR shuffle switch with status: None
2019-09-03 13:10:51 DEBUG (MainThread) [custom_components.alexa_media.switch] a*******o@g*******m: Found G************6XR repeat switch with status: None
2019-09-03 13:10:51 DEBUG (MainThread) [custom_components.alexa_media.helpers] a*******o@g*******m: Excluding device: <Entity Echo Dot Gen2 do not disturb switch: off>
2019-09-03 13:10:51 DEBUG (MainThread) [custom_components.alexa_media.helpers] a*******o@g*******m: Excluding device: <Entity Echo Dot Gen2 shuffle switch: off>
2019-09-03 13:10:51 DEBUG (MainThread) [custom_components.alexa_media.helpers] a*******o@g*******m: Excluding device: <Entity Echo Dot Gen2 repeat switch: off>
2019-09-03 13:10:52 DEBUG (MainThread) [custom_components.alexa_media.media_player] Disabling polling for Echo Dot Gen2

However, when I use exclude_devices and include all the unwanted devices, it works for me in 2.1.0.

Since that is the only device in the include that is the only thing that will be loaded. The logs show everything else is filtered away and I’m not seeing any errors. Are you saying even that isn’t showing up as a media?player?

@sunny @pickerin
This Alexa bug has been sorted in 0.98.3

1 Like

Hi I keep getting this:

Event is not JSON serializable: <Event platform_discovered[L]: service=load_platform.alarm_control_panel, platform=alexa_media, discovered=name=alexa_media, [email protected], password=xxxxxx, url=amazon.com, exclude_devices=["Henning's Sonos One", "Henning's 2nd Sonos One", "Henning's Alexa Apps", 'This Device_2', 'living_room_4'], scan_interval=0:01:00, include_devices=[], debug=False>

I am running HA 98.3 and Alexa v2.1.0. What is wrong?

Ha setup:

alexa_media:
  accounts:
    - email: [email protected]
      password: xxxxxxx
      url: amazon.com
      exclude_devices:
        - "Henning's Sonos One"
        - "Henning's 2nd Sonos One"
        - "Henning's Alexa Apps"
        - "This Device_2"
        - "living_room_4"
1 Like

Yes, earlier I would get an alarm_control_panel related to that Echo (Entity Alexa Guard 227b3). With include_devices that is excluded.

I have this errors with Alexa Media Player 2.1:

Event is not JSON serializable: <Event platform_discovered[L]: service=load_platform.alarm_control_panel, platform=alexa_media, discovered=name=alexa_media, [email protected], password=PASSWORD, url=amazon.com, include_devices=['Echo Plus'], exclude_devices=["Maciej's Alexa Apps", 'This Device'], debug=False, scan_interval=0:01:00>

Does the component have to send a email and password in the event content? It’s not safe to save such things in a database or log.

1 Like