Any change on this? Or is there some faster and reliable alternative to get the LastCalled information?
I’m using the Alexa Media Player (5.7.1) integration with 14 Alexa devices, but it is neither reliable (sometimes Alexa activity won’t be recognized) nor fast (takes up to 10 minutes to get the update) for me.
Strange, how do you go about it? The answer comes within a few seconds. However, I “only” have 7 devices. Very rarely does the answer come on the wrong device. It’s been like this here for a year.
Just the template sensor from the wiki, that’s enough. I use the DIY skill to activate the scripts via Alexa routine.
template:
- sensor:
- name: Last Alexa
state: |-
{{ expand(integration_entities('alexa_media') | select('search', 'media_player'))
| selectattr('attributes.last_called', 'eq', True) | map(attribute='entity_id') | first }}
availability: |-
{{ expand(integration_entities('alexa_media') | select('search', 'media_player'))
| selectattr('attributes.last_called','eq',True) | first is defined }}
Thats all. Look here. I have simply adopted this. But I’m not an expert either. But it works perfectly.
There you will also find lots of examples of what such scripts could look like.
Edit: I think you also have wrong indentations. And why so many sensors?
Just out of curiosity I also just tested it (on 5.7.1) and mine never updated and when it finally did it was from an hour ago. Not sure why some people are having better success than others?!
I’d like to pick this thread up. Since two or three days I have the issue, that I call call my alexa from where ever, only the one in the livingroom shown the last_called attribut as true. It has not really something to do with AMP. Does anybody have the same issue?
I found the last_called entity to be extremely unreliable. I ended up using AI to come up with a custom AWS lambda skill with purposed intents, a python_script, several home assistant scripts, a couple helpers, and an automation using a webhook.
It works like this - when I use the custom Alexa skill it triggers my webhook automation which parses the json payload sent back from Amazon looking for the specific intent invoked (using choose blocks with conditions), when the payload is received the automation then triggers the script for the intent invoked and the Alexa device_ID is printed to an input_text helper, the python_script automatically converts the Alexa device_id in the input_text helper and matches it to a media_player (the last_called device) from AMP and publishes it to a template sensor, then an announcement is made from the echo device I used.
Use cases are - I can add/remove items from the Home Assistant Shopping List and add/remove items from a Task To-Do list. I have GasBuddy setup and can have Alexa tell me who has the cheapest gas by me. I can have Alexa give me a door and window status letting me know if any are open/unlocked. I can have Alexa tell me the temperature in the house and the status of my thermostat.
I have full control of being able to send any data to Alexa to let me know what’s on the up and up.
If anyone is interested in the Lambda script, the python_script, the automation, or other home assistant scripts, let me know. I’m happy to share (albeit, I’ll scrub my webhook ID and other personal info like the alexa_id’s.) If you’ve got experience dealing with AWS and amazon developer cloud by doing the Alexa Smart Home skill or the Dashboard viewer skill, this is quite simple to setup, just time consuming.
My automation has a disabled action that publishes the json payload as a persistent notification so you can get the alexa_id of your echo devices.
I’m not worried about the new Alexa Devices integration in core, either. Should AMP phase out and once Alexa Devices integration has stabilized, all that needs done is a change to the python_script to have the alexa_id map to a speak or announce entity instead of the media_player entity and update the scripts to use that action (at least hopefully it’s that simple when the time comes).
I’m interested in the project. Can you post the scripts and the automation somewhere? I have the last_called working reliably, but it takes too long as I check the entity and verify/reload inside each automation.
The bulk of the code is there and has been scrubbed of my personal details. If you’ve done the Alexa Smart Home Skill for Home Assistant, the process is very similar and you can use that tutorial’s bullet points to guide you. I’m interested in making my own step-by-step tutorial, but I’ll need some time. I’ve only included one example script, but I’ll include more a little bit later. If you’re a tech enthusiast, I’ve no doubt you’ll be able to reverse engineer and modify the code to suit your needs.
You’ll need to go around to each one of your echo’s to invoke the skill, one at a time, to capture each echo device_id and update the python script string.
Good luck!
EDIT: look at the code block version of the readme.md to see the template sensor in yaml format
Thank you very much for this! I adopted this for my needs and finally got it working. My wife is a type 1 diabetic and uses the dexcom integration. I had already set up an Alexa routine to speak her glucose level when asked but to only 1 speaker.
I was struggling to get the last_called to work reliably then came across your post here. I was able to modify your code and use it so now I can ask any Alexa device “what’s my blood sugar” and Alexa will speak to that device with the value.
FWIW, I have recently updated my python_script and all the other scripts to use the Alexa Devices core integration and it was as simple as I presumed in my original comment.
For the python_script, just change the media_player entities to announce or speak entities. For the script, use the notify.send_message action like this (the message and entity_id fields need proper yaml indentation) -
Yes your code is just what I needed to get me going on this! After a lot of trial and error I was finally able to use lambda and also get this to work without using Alexa media player or the Alexa integration to speak directly to Alexa without relying on authentication entirely. I can solely use official Amazon api from start to finish and never have to log in anymore in home assistant.
I have not found a way to send on demand messages to Alexa without needing the short lived token that Alexa grants when invoking the skill, something that Alexa media player and Alexa integration can do unofficially. I can get around this by using a binary sensor being triggered on/off and setting “custom” in the “Alexa will” section of the routine to an invocation in my skill.
However I no longer need to worry about anything breaking whenever home assistant upgrades or if Amazon ever decides to change and break the integrations.
Alexa Media Player (AMP) uses the unofficial api via web access. Alex Devices (the core integration) uses the official api via Alexa Developer Console. At least to my understanding. I’ve been following the aioamazondevices github repository closely. That’s why I switched to using Alexa Devices instead of AMP.
This option is genius, and it’s near instant. I highly recommend it. Full credit to user R2D2 over at community.simon42.com. Essentially, you set up an automation that checks each Echo device for the presence of a ghost attribute. The most recently activated echo will have the ghost attribute missing, and the automation will set an input_text helper with the value of that device. This ghost attribute is written by the automation using a small Python script, found here: Python Script