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?
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.
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
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’.
Now I want to know the entity_id of the speaker that has the alias ‘Kitchen’.
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:
I was facing the same problem and found my own solution. I don’t know if there is any ‘offical’ one yet.
So I noticed that in .storage/core.entity_registry there are all information we need. With the following shell_command you can extract the entity_ids and aliases: get_entity_alias: jq '[.data.entities[] | select(.options.conversation.should_expose == true and (.aliases | length > 0)) | {aliases, entity_id}]' ./.storage/core.entity_registry
I’ve then made a sensor:
#Sensor für Zuordnung von Alias Namen zu Entity-IDs (Update über Neustart oder Service homeassistant.update_entity)
- trigger:
- platform: homeassistant
event: start
action:
- service: shell_command.get_entity_alias
data: {}
response_variable: result
sensor:
- name: "Assist: Entity IDs mit Alias"
state: '0'
attributes:
entities: "{{result.stdout}}"
And there you have it. In your script you can then use something like this: