This is my first time working with HAOS/YAML, so apologies in advance!
I’ve got multiple binary sensors (presence) and I want to add some custom sentences to query their state via voice assist.
The custom sentences work fine:
language: “en”
intents:
CatLocation:
data:
- sentences:
- “Where is {name}”
- “Is {name} [at] home”
- “Is {name} outside”
- “Is {name} inside”
And the intent works when hardcoded for a binary sensor:
intent_script:
CatLocation:
speech:
text: >
{% if is_state(‘binary_sensor.%{name}%’,‘on’) %}
{{name}} is at home.
{% else %}
{{name}} is outside.
{% endif %}
What I can’t seem to do is pass the {name} from the sentence to set which binary sensor should be interogated. The name passes from the sentence to the response nicely.
I know I could replicate the hardcoded version for every binary sensor but not only does that seem poor coding but it means adding a new binary sensor will require adding a whole new sentence and intent.
Update:
So I realised this is ‘sort of’ working. If I use the name of a binary sensor that exists then I get a response, but it’s always {{name}} is outside. If I use a name that doesn’t match a binary sensor I get an error of no device of that name found. So clearly the name is passing through to some degree.
What I don’t understand is that if i swap out %{name}% for a hardcoded name, the if statement works and the response varies based on the actual location of the sensor.