I have Nabu Casa and Alexa set up, and I’m able to trigger scripts or whatnot from alexa routines on an echo dot. That’s nice, but one thing I’m wishing for would be the ability to determine which device sent the command, so that I can have Home Assistant respond appropriately (e.g. routine of play random radio station triggers script which plays random station; I’d preferably want this on a nearby sonos device depending on which speaker sent the command rather than just the same one every time).
The alexa media player integration in HACS does have last_called_summary and last_called_timestamp attributes, but in my limited testing it seems to update way too slowly for me to use as a solution here (e.g. script would run before attributes updated, so music may start playing in whatever room had Last sent the command, rather than the actual current room)
The only other solution I’ve seen in my limited research is to have different amazon accounts linked to each echo device, and set up the same routine command with different scripts, which I’m not interested in doing. I only really plan on using this in my son’s room anyway, but would like the consistency of it working anywhere just in case someone else picks up on it and says the command elsewhere only to have music start playing in my sons room rather than wherever the user is. Not sure it’s possible based on what I’ve looked at so far, but wanted to put it out here in case anyone knows better than I do!
I have Google Home devices rather than Alexa, but this might give you some ideas.
With things directly handled by Google Assistant and Home Assistant there is (currently) no way to detect the source device. However, with Google Assistant routines there are workarounds - so this may apply to Alexa routines too. I will reference Google Home below, because I know that works, whereas I’d just be guessing the equivalent works for Alexa.
Create one entity per Google Home device, and expose them all to Google Assistant with the same name but in different rooms. Then create a group helper containing them all. Say they are toggle helpers (input booleans) all called Current Google, then the first line of a routine can be “set Current Google to on” and it will turn on the one in the same room as configured for the Google Home’s room. Something can then detect this to work out which Google Home was spoken too, and also turn off the group for next time.
Note that I used MQTT switches rather than input booleans because I like to see the messages using MQTT Explorer, but either should work.
Unfortunately, input booleans did not work with alexa. I created the helpers and assigned them to my echo rooms, but when activating the routine I would get an error via alexa about more than one device with that name- apparently alexa won’t intelligently determine which device based on room groups. However, I learned alexa CAN do that for lights, so I set up virtual lights instead of input booleans and now the routine in alexa executes ‘turn on the lights’ which will turn on only the virtual light for that room. HA looks for that as a trigger to the automation, and bob’s your uncle. It does prevent me from grouping actual lights with the echo devices so I have to say ‘turn off the main bedroom lights’ rather than just ‘turn off the lights’ while in the main bedroom, but that is something I was doing anyway since I wasn’t aware of this functionality before this exercise. (unless something has changed, I think that’s not the case in Google Home. I remember trying to set that up years ago but ‘turn off the lights’ would turn off every light in the home, not just the room.)
I have a couple nest hubs as well, so I implemented the input boolean with those and it worked perfectly as you described, just in case anyone else comes to this thread later.
It’s not ideal and can muddy the alex or google home apps to have extra rooms created just for these types of groupings, but I’m not using those apps for their home dashboards, so it was an easy conceit to make myself. Thanks again for the advice and getting me started!