Echo Devices (Alexa) as Media Player - Testers Needed

I played arround a little with the sensor.last_alexa and I also tried the example from the wiki.

The thing is as you I would have changed the entity.entity_id in the example.
Try it in your template without changing anything in that example, this way it magically works.

from here

{%- for entity in states.media_player -%}
{%- if state_attr(entity.entity_id, ‘last_called’) == True -%}
{{ entity.entity_id }}
{%- endif -%}
{%- endfor -%}

I think the advantage of this sensor against the one from here is that we don’t have to specify every device. Also if you get new alexa device you don’t have to change something in the code.

EDIT: But I have another issue that I also mentioned here
The last_called true state doesn’t go back to false. So I end up with more than one device having last_called: true.
Does someone else have that?
With the above sensor this will cause two entities in a line. So wrong information.
Could be that issue?

Using what you suggest to me in the template editor i get the following:

  last_alexa:
    value_template: >media_player.echo_plusmedia_player.echo_spot

It means both the echo devices i own are last called? And why that strange output?

I think so and I have the same behaviour. I think the way it should work is that only one device can be last_called: true so the last one that was true has to be updated and go back to false. Then you will only get one entity in that output.

I could be wrong as I don’t fully understand how it works, but hopefully @alandtse will make clear if this is a (known) bug or a feature :wink:

Until than we should keep the other way to do it.
Your output tells that you also have two devices “last_called”. Does your sensor work right, with the code we got from @lonebaggie ? I mean does it update to the latest triggered alexa? Because in that template nothing seems to proof which of the last_called: true alexas was the last one. This is probably confusing, sry.
@maurizio53 you could restart ha and try that template again, does it only show the right last_called after the restart (it does for me)?

Ok, thanks for the clarification…

Could you answer the questions above? Maybe it would help to figure out the issue. If you have the exact same behaviour it is more likely, it’s not me doing somethin wrong.

For me it’s not clear how to use the template for the ‘last_called’ property.
I have added the sensor as described in the wiki:

- platform: template
  sensors:
    last_alexa:
      value_template: >
        {%- for entity in states.media_player -%}
          {%- if state_attr(entity.entity_id, 'last_called') == True -%}
            {{ entity.entity_id }}
          {%- endif -%}
        {%- endfor -%}

and if I copy the same ‘code’ in the templates page to test, I can see the correct name of my device:

  • platform: template
    sensors:
    last_alexa:
    icon_template: mdi:amazon-alexa
    value_template: >media_player.echo_spot_di_luigi

But if I check the value in the states page, the sensor is empty.
Where is the error?

It’s only a guess. After the restart, all the last_called attributes go to False.
So state of the sensor would be empty (I guess).
The test in the template was before the restart.

Just updated to 0.88.1 and now this media player isn’t working. It was working before the update.

I’m not sure, because if I check the state of my echo, the last_called attribute is True:

Ok, I tried it, I have the same as you. Empty state with that code.

I don’t have any more ideas. Unfortunately this is not the only issue.
We’ll have to wait for someone with better knowledge.
Maybe @BrianHanifin as he posted this example here.

@kpj5425 read the posts from the last three days in this thread.

1 Like

Never mind…I can’t spell “init” apparently.

However, Now I can’t get past the email verification where it says “Please hit confirm to begin login attempt.”

I hit the button three times. I’m sure it’s just me again…

EDIT: OK So I may really be stupid…

in the box that asks you for the verifiucation methoid (sms or email) do you type in “email” or do you put in your email address “[email protected]”?

They Repos that the alexa.py file came in somehow got removed with the new update. Trying now to see if adding it back in makes it work again.

Any luck with this? I’m getting the same exact error and it also seems to be breaking MySQL/Recorder

Error executing query: (MySQLdb._exceptions.DataError) (1406, "Data too long for column 'event_type' at row 1") [SQL: 'INSERT INTO events (event_type, event_data, origin, time_fired, created, context_id, context_user_id) VALUES (%s, %s, %s, %s, %s, %s, %s)'] [parameters: ('[email protected]', '{"last_called_change": {"serialNumber": "G090#########", "timestamp": 1551139820854}}', 'LOCAL', datetime.datetime(2019, 2, 26, 0, 41, 22, 153825, tzinfo=<UTC>), datetime.datetime(2019, 2, 26, 0, 41, 41, 29487), 'b76083ed4586459797bbc7bafbc6da25', None)] (Background on this error at: http://sqlalche.me/e/9h9h)

@keatontaylor 1.0 breaks mariaDB w/ recorder.

2019-02-25 20:07:01 ERROR (Recorder) [homeassistant.components.recorder.util] Error executing query: (MySQLdb._exceptions.DataError) (1406, "Data too long for column 'event_type' at row 1") [SQL: 'INSERT INTO events (event_type, event_data, origin, time_fired, created, context_id, context_user_id) VALUES (%s, %s, %s, %s, %s, %s, %s)'] [parameters: ('alexa_media_xxxxx', '{"last_called_change": {"serialNumber": "xxx", "timestamp": 1551140434099}}', 'LOCAL', datetime.datetime(2019, 2, 26, 1, 6, 55, 409797, tzinfo=<UTC>), datetime.datetime(2019, 2, 26, 1, 7, 1, 599780), '7a2d936d2bb646c49814d317126406f2', None)] (Background on this error at: http://sqlalche.me/e/9h9h)

Seeing same issue @Bartem, @lordsiris.

@lordsiris, how did you find out the length of the event_type that it was trying to put in?

EDIT: Found this PR, appears to have fixed the problem, will keep you guys posted

1 Like

Thanks @petro - I just setup MySQL the other day and was kind of annoyed it broke already…
this fix is also working for me as well so far.

This is a rare break. It’s only because this is a custom component. It’s part of the thrill when going custom!

seems that 88.1 breaks this component…update?

please read back. its all discussed in the last few days

If you only have one Alexa account, then there should only be one last_called echo. There is a polling thread to determine the last serial number, and all devices will read an event when a new one is discovered and should adjust themselves. If you see more than one returning true (for more than a split second, which is the time for HA to tell every component), that’s a bug. Please file an issue. For multiple accounts, each account should have its own last_called as each account is treated separately for now.

As for the timing interval (that was the problem with reducing the polling), we’ll add an update service that will need to be manually triggered hopefully in the next release.

“email” or “sms”. Can someone update the FAQ for me? This has been asked before.

@Mirai_Hayashi
No that won’t work. 88 broke the component anyway so we took the opportunity to migrate to the new file structure and configuration. You need to follow the wiki.

Glad you found the PR, appears to have corrected my issue with mariadb.