Use same Alexa command to turn on similar device(s) on depending what room I'm in

I have 2 pellet stoves, one in my LR, one in my Shop. Each pellet stove entity is defined in its respective Area.

And I have an Alexa in both places.

Right now I have to say “Alexa turn on Living room pellet stove” if I’m in the LR.
Or Alexa turn on Shop pellet stove" if I’m in the shop.

I’d like ONE automation that can understand which room I’m in when I say “Alexa, turn Pellet Stove ON”. So, Automation trigger by sentence is obviously what starts everything.

But, how do I tell which Alexa the command came from? I’m not seeing it… this would clearly apply to other things like “alexa turn the lights on/off”

I do NOT want to group devices in Alexa (which can be done)- I have literally 100’s of devices and there has to be some way of telling which Alexa triggered the automation.

As soon as the HA Voice Assistant works well enough (still missing Pandora), I’m ditching Alexa for good, so I’d like to implement this once no matter what Voice Assistant I’m using.

If you are willing to go down the rabbit hole of Node Red, there is a pallet for Alexa that gives you a payload of msg.payload.deviceSerialNumber that you can then act on based on that Serial #. The pallet is called node-red-contrib-alexa-remote2-applestrudel but some have found it unreliable. I have been one of the lucky ones and have been using for a few years. I can say “illuminate”, “lumos maxima”, or “make it light” in any room with Echo and those lights will turn on. There are also reverse terms for turning off lights. Also, saying “it’s hot in here” will turn on ceiling fan in room I am in.

If you want to go down this hole, I can give you more details. I don’t know if any of Home Asst’s integrations with Echo provide that information. Someone else did that a few years ago but I think he/she used the Node Red method I did.

It ultimately boils down to how you’ve organized groups/rooms in the Alexa app.

Let’s say you have a group/room called Living Room. You have tied the echo device in the living room to that group and you’ve included the Living Room pellet stove as a device in that group. Now, if you are specifically just asking the echo device in the living room, you can refer to the pellet stove as “pellet stove”. Now, let’s say you were trying to turn on the pellet stove in the living room while you are in your shop, speaking to the echo device in your shop… you would have to call the pellet stove “living room pellet stove”. That’s how Alexa groups work.

With that said, there are a few ways to get an Alexa last_called_device entity. You would need the custom integration Alexa Media Player (AMP), which has a built-in template sensor (you’d still need to add it to your yaml) that pulls the last_called_device.

There’s also a method used known as the “Ghost” attribute. You can find it in this forum.

The last method is to create your own Alexa Skill and use a webhook automation to pull the device_Id of the echo device and map it from a text entity to a template sensor using python. This is what I do.

If you have set up the Alexa Media Player custom integration, each media_player entity has a “last_called” attribute that can be used to determine which device a command was spoken to. However, Amazon has reduced the speed at which updates are pushed for this value, so it’s not going to work quickly and may not be reliable on it’s own.

The most reliable way to get Alexa to handle it is by assigning areas and groups in the Alexa app.

a workaround:

  1. In HA, create a dummy input_boolean (or switch) entity, e.g., input_boolean.pellet_stove_trigger. Expose this to Alexa via Settings > Voice Assistants > your assistant > Expose tab (or manually in configuration.yaml if needed).
  2. In the Alexa app, create a routine:
  • Trigger: Voice command “turn Pellet Stove on” (or whatever exact phrase you want).
  • Action: Turn on the exposed “pellet stove trigger” from HA.
  1. In HA, create an automation:
  • Trigger: State - when input_boolean.pellet_stove_trigger changes to “on”.
  • Actions:
    • Call service: alexa_media.update_last_called (to ensure the sensor is fresh; data: {}).
    • Delay: 1-2 seconds (to allow update).
    • Then, use a template condition or choose action to determine the room and target the right stove:

YAML

- choose:
  - conditions:
      - condition: template
        value_template: "{{ area_name(states('sensor.last_alexa')) == 'Living Room' }}"
    sequence:
      - service: switch.turn_on  # Or whatever domain your LR stove uses
        target:
          entity_id: switch.living_room_pellet_stove  # Adjust to your entity ID
  - conditions:
      - condition: template
        value_template: "{{ area_name(states('sensor.last_alexa')) == 'Shop' }}"
    sequence:
      - service: switch.turn_on  # Or whatever domain your shop stove uses
        target:
          entity_id: switch.shop_pellet_stove  # Adjust to your entity ID
- service: input_boolean.turn_off  # Reset the trigger
  target:
    entity_id: input_boolean.pellet_stove_trigger
  • For “off”, duplicate the routine/automation with “turn Pellet Stove off” and turn_off services.

This same pattern applies to lights: Create a similar dummy trigger, routine, and automation that finds lights in the detected area (e.g., via area_entities(area_id(states(‘sensor.last_alexa’))) filtered to light domain). No need for Alexa groups—the context comes from sensor.last_alexa.

You also have to create this template sensor:

{{ states.media_player 
   | selectattr('attributes.last_called', 'eq', true) 
   | map(attribute='entity_id') 
   | first or 'none' }}

Sure enough, the ouput from that template sensor shows which device got the last command.

Now, IF ONLY that attribute would frigging update.
“Speak a simple command to one Echo (e.g., “Alexa, what time is it?”).
Immediately call alexa_media.update_last_called in Services (add data if multi-account: {“email”: [“[email protected]”]}).”

Calling that service has no effect. I can see the state of the Alexa change from Playing to Paused, but the last_called remains static.

This sure would be elegant (AND SIMPLE) if it worked. I wonder if it’s a bug in the integration or just Amazon being Amazon.

It’s Amazon. It used to work really well when the updates were snappy, but they throttled updates a year or so ago, and it made Alexa so much less functional with HA.

1 Like

I despise Amazon. The ONLY reason I havent dumped all my Alexa devices is my entire family is addicted to Pandora curated playlists (honestly I agree - they are WAY better than any other service). The forced move to Spotify by me caused a household mutiny and if I wanted to be fed and continue to get husbandly favors I was forced to return Pandora and Alexa.

Happy Wife, Happy Life.

Why the opposition to assigning devices to rooms using the Alexa app? You don’t need to make a single change to HA to get the functionality you’re looking for.

In my house, any room with an Echo I can say “turn on the lights” and then only the lights assigned to that room get turned on. It’s been working this way flawlessly for over two years.

Echo doesn’t give the functionality I want. Grouping might work for lights but not the fans also.

Because as soon as Pandora is available on music assistant, I’m dumping all my Echo devices and crappy Alexa service. That will be soon, thankfully. Devs are working on it right now.