I’ve been playing around with making custom sentence templates and intents using the new Year of the Voice features.
According to the documentation you can use the <name> and <area> lists within custom sentence templates as these are provided by Home Assistant. This is working but I’m noticing that you get the name of the entity, not it’s entity id, for use with an intent. I’m struggling with how to use this within a custom intent to actually pull up state information.
As an example, say I have a sentence to make the presence of a person:
- sentences:
- "is <name> at home right now"
requires_context:
domain: 'person'
In my custom intent_script I get the name “Rob” but would like to get “person.rob” so I can pull in the state information. For built in intents like HassGetState the name must be turned in to a useable entity somewhere. Just curious if there is a way within an intent_script to get the entity id or if I’m going to end up having to make my own custom lists to map inputs. I’d rather not do this since the context matching is awesome so I don’t have to spell out each individual entity option.
Hopefully this makes sense and someone as either encountered this or knows if there is a workaround.
I somewhere found this line of code that lists all available entitites, filters by name and then returns the entity_id. It works perfectly with the FriendlyName.
you probaly want to change states.cover to states.person
I am now trying to understand how to use aliases since the intent is recognised when useing aliases but the line of code I just provided does not work.
There is no attribute Alias so probably there is something like for Area where you filter the entities with this:
I think this is template I was looking for, at least until a better way to map these comes along. Ideally Home Assistant would pass in a variable “entity_id” or something with the matched ID from the matched entity name or alias. I can use this for now - thank you!
@DonNL - I did play around with making a list but for more advanced use cases this would get tedious really quickly. My goal would be to add something to the system and just have the intent work without having to update all the sentence lists each time. Thanks though.
I think you mean the keyword name in the custom_sentence.
and it will automatically do the search between all friendly names and aliases of hassio, so you need no list. to limit the search only to the person domain you have to use require_context
language: "en"
intents:
PersonHome:
data:
- sentences:
- "is {name} [at] home right now"
- "where is {name}"
requires_context:
domain: person
then I still have not find a cleaner way, but the following should address to the entity state
intent_script:
PersonHome:
speech:
text: The {{name}} is at {{ states.person | selectattr('name', 'in', name) | map(attribute='state') | list | first | default }}
you can also use entity_id instead of state to return the string to use in a service