Last Alexa Sensor using Keaton Taylor Alexa Media Player custom component

Lol, I only have 2 alexa’s. I think you’re all nuts.

EDIT: But I am rethinking the amount I have… maybe i need more…

:smiley:

I recently read a post where someone mentioned he has 13 alexa’s.

I was like “dude, how big is your house” :wink:

I have this in all of my automations that I use to call alexa and get a response. I use the dummy light setup that @lonebaggie resommended. I dont use appdaemon, but the overall process is the same.

So trigger it sh

- alias: "Alexa Report"
  trigger:
  - platform: state
    entity_id: light.alexa_virtual
    to: 'on'
  action:
  - service: homeassistant.update_entity
    data:
      entity_id: sensor.last_used_echo
  - service_template: "notify.{{ states('sensor.last_used_echo') }}"
    data_template:
      message: messgages here based on light level
  - service: light.turn_off
    entity_id: light.alexa_virtual

I have never had an issue with the last echo. I will say I’m using the script at the moment, I may move over the the newer component once I can use notify for my TTS setup

First let me say, I love this component. I have weather alerts broadcast through the house during storms. I recently setup a page where I can type in messages for each device, or broadcast typed in messages to all devices. I can even email messages to specific or all devices. (I use Appdaemon for my development). I think I remember seeing messages about this a while back, but have lost them. How can I send a audio file to this? Lets say I want to send the sound of a dog barking whenever the door opens and no one is home to my den alexa.

@Petro - your yaml code works like a charm with the alexa/media_player version 0.10.2.
Thank you.

1 Like

it’s my understanding that, unfortunately, there’s no way to do it unless you can find the soundtrack on one of the audio channels already provided by Amazon.

The last_alexa sensor will have the last Alexa that was spoken to as it’s value (now that I’m using the right configuration.yaml from @petro.
However, when I execute a script from one echo device (office) it responds back to that office device. If I then go to another echo device (kitchen) and do the same, it responds from the office device. Then, because I just used the kitchen, the kitchen becomes the last_alexa so if I repeat the command in the kitchen (or office) the response comes out of the kitchen.
If I used the office for that repeat command, the last_alexa value updates to the office after the kitchen has responded. Has anyone else seen this behavior and how have you gotten around it?
I’m guessing that it has to do with scan_interval rather than being updated by which alexa the request came from but continuing execution before passing it to the sensor.
Does anyone have any tricks to circumvent this out of sync condition?
Thanks.

is there a way to send ssml to the component to have amazon interpret?

ssml not supported “,” does add a slight pause to the speech, just “spell bably” to change inflection or accent see

see

Thanks @lonebaggie
Are you suggesting that release 1.1.0 will allow a script to call alexa_media.update_last_called service and get the calling echo device in time to respond to it? The example is pointing to an email account update but it’s not clear how it would be used in a script to update the last_called entity_id. I’ll have to check into it further.

if you call “alexa_media.update_last_called” it will update the last alexa sensor immediately and stop you being out of sync

1 Like

@lonebaggie Do you know if calling “alexa_media.update_last_called” works in 0.10.2? Or do I need 1.1.0 to do that? Even if it does, I don’t know how to include it in a script or automation yet - working on it :blush:

I know this may be silly, but I don’t know why I’m reluctant to upgrade to 1.1.0 except it seems to still be in beta. and every time I change something I have to go fix other things. But I agree with many users that this media_player custom component is the most straightforward way to integrate Alexa into Hass.io.

I see folks that have updated to 1.1.0 are having the usual troubles with captcha’s and Alexa’s not working anymore. I try to remain stable until I get my devices and routines working enough where I don’t have to do a lot of time consuming reboots.

On another note:
I was looking through the media_player.py code (and wish I knew more python and code in general) and was thinking that if any Alexa made a request out to Amazon, it’s identity came along in the data packet sent back from Amazon so it would know which echo to execute on. I’m guessing that when it sends a command to a hass device or script, the id isn’t passed along which would have made it instantaneous to update ‘last_called’ as the data packet was processed. But alas, I know too little about the structure of the data packet except what’s documented in the code - calling id will be empty if it’s the same device as last request. I was impressed with how incredibly compact and tidy the script really was. I wish I could write code that well. Kudos to @keatontaylor (and @alandtse )

1.1.0 is the first version to support “alexa_media.update_last_called”

Your running a custom component so you are already on the bleeding edge of HA, but I don’t think 1.1.0 is beta whatever that means :slight_smile: HA is still beta < 1.0

I have tested and 1.1.0 takes an age update last alexa 1 to 3 mins normally . running “alexa_media.update_last_called” updates last alexa immediately. Everything else seems to work . I have good backups , so it now in production.

@lonebaggie : Thanks for that clarification. Also, fair point about HA is still beta and custom components are, well, custom as the warning message during boot says.

I’ve got a simple if not pain in the butt workaround: First I ask Alexa for the time, then I follow with the routine request. Works every time putting the response back on the correct Echo device. So far I am only using scripts, not automations. Since I’m not controlling any other devices, I’m guessing that I don’t need an automation.

I’m making progress. Thanks for all your help.

The only valid use I have found for “last alexa” is if I initiate a spoken response outside of HA . Ie I trigger an alexa routine . The alexa routine then trigger a HA entity dummy bulb , input boolean , etc

At this point if I need to continue the conversation I need to know which alexa has spoken .

If HA initiates the spoken request , I can work out which alexa need to speak .

This. I think the template here may be a good thing to update the wiki with. While right now I’m dedicating time to the wiki and forum on top of the code, I have other components I’m helping with which probably need more help in the short term, so will likely be less active on this end. Any help from the community in answering some of these common questions or explaining how to use the component would be great. The Wiki is probably the best place as all these threads get updated too fast to be useful.

Email is not mandatory. You can run the script without any additional json data. If it’s blank, it’ll update every Alexa account. We support people who have multiple Alexa accounts where there may be Echos only accessible from different accounts.

The issue we had to account for is people interact with Echo devices vocally so HA won’t see any packets and won’t have any idea without checking the Amazon servers. Yes, the individual Echo device should know it was the last one, but that’s not exposed natively by Amazon through the API.

Please note HA will break 0.X.Y line of the component sometime in a future release. I don’t plan to put any resources into maintaining that branch so I’d recommend you consider updating. All new features will end up in the 1.X.Y branch. Of course, you can wait till we get it officially in HA but that’s a larger effort and I don’t think we have a timeline. Yes, it is a breaking upgrade to get to 1.1.0 but we also added the custom_updater which should make upgrades easier.

But this only works if you already have 1.1.0 (right?).
So this will be useful for future updates. This would mean you have to update manually the last time (hopefully).

@alandtse Ok I put the code from @petro into the wiki, instead of the one that was there before. Hope that was ok. The example before did not have the entity id’s, ending in a blank state.

Did not know that it was so easy to change the wiki. It doesn’t need confirmation of you @alandtse? Do you at least get a notification that someone changed it, so in case it is none-sense, you can change it back?

Thanks. Git has a history so we can revert it if someone destroys stuff. If we notice issues, we may lock it down, but for now, I think most people want to help.

If you have 1.1.0, any future updates will be available through custom_updater. So in theory, updating to 1.1.0 is the last one you have to do manually.