How to find entity_id using the Voice Alias using templates?

I am not sure if I just missed something, or if it’s not (yet) possible to link an alias to an entity_id.
So in short, is there a way to relate voice aliases to their entity_id?

Here’s my story
I created a small custom sentence to join/unjoin my speakers using a script. The thing is that the variable name holds the alias I mention in the instruction instead of the entity_id where the alias refers to. Since the variables are sent to a script called script.sonos_group_manager, I could just “search” for the entity_id in the script and trigger the actions from that point forward. But I haven’t found a way to get from the alias to the entity_id.

I was hoping for an attribute to filter on or maybe a function, like you have at devices and areas, to trace back the entity_id or device_id.

Anyone an idea how to achieve the goal of linking an alias to an entity_id?

The YAML, for those interested
Sentence:

language: "en"
intents:
  sonos_group_manager:
    data:
      - sentences:
          - "{do_what} [the|speaker] {name} [speaker]"
        requires_context:
          domain: media_player
lists:
  do_what:
    values:
      - in: "(Join|Add)"
        out: "join"
      - in: "(Unjoin|Remove)"
        out: "unjoin"

The intent_script

sonos_group_manager:
  action:
    service: script.turn_on
    data:
      variables:
        room_id: "{{name}}"
        action: "{{do_what}}"
    target:
      entity_id: script.sonos_group_manager

The script script.sonos_group_manager handles the rest, but now needs to know how to find the entity_if of the alias/{{name}}

There are many ways to do this, but we’d need more information on what type of entity you’re trying to get. Multiple entities can have the same name, so you’d need to intellegently select the correct one based on the context.

That’s good to know, great!

In my particular case I want to find entities in the domain media_player and with manufacturer ‘Sonos’.

If I just have a starting point, I might be able to solve the puzzle.
Like if I can get all entities that match on the alias (not the friendly_name) ‘Kitchen’ I more or less know how to drill down using for example:

  • is_device_attr(<entity_id>, 'manufacturer', 'Sonos')
    and
  • select('match', '^media_player.')
{{ states.media_player | map(attribute='entity_id') | select('is_device_attr', 'manufacturer', 'Sonos') | list }}

Yeah, I get that part, but it’s the link to/from the alias.
In the image below I have a media player the alias ‘Kitchen’, so now I can use a voice command that points to the name ‘Kitchen’.

image

Now I want to know the entity_id of the speaker that has the alias ‘Kitchen’.

add a select('is_state_attr', 'friendly_name', 'Kitchen')

No, not the friendly name. That doesn’t hold the Alias, nor is there an attribute aliases that I can use.

If there’s nothing to link it, then there’s nothing that can be chosen…

What I hoped for is something like you can do with areas. There is no link in the attributes from an entity to the area, but you can do this for example:

{{ area_entities(area_id('Kitchen')) | select('match', '^light.') | list}}

or

{{ integration_entities("sonos") | select("match", "^media_player") | list }}

So the link is not always obvious, even when it is there. But if it isn’t there (yet), I might just give it a go as feature request. Thanks