Intent interogating binary sensor called in sentence

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.

text: >
  {% if is_state('binary_sensor.'~name|lower, 'on') %}
  {{name}} is at home.
  {% else %}
  {{name}} is outside.
  {% endif %}

Perfect, thanks Didgeridrew.

Now it works I’ve realised I have another issue. I have a sensor called minnie (can’t change the sensor name or it’ll show up incorrectly on the dashboards etc.) but obviously Voice assistant is never going to output minnie it’ll always be mini. I’ve tried using a list to convert the sentence input but it doesn’t seem to work. Is lists the right approach and/or have I got the syntax wrong?

language: “en”
intents:
CatLocation:
data:
- sentences:
- “Where is {name}”
- “Is {name} [at] home”
- “Is {name} outside”
- “Is {name} inside”
- “Is {name} indoors”
- “Is {name} outdoors”
- “Is {name} [in] [the] house”
- “Is {name} [in] [the] garden”
lists:
name:
values:
- in: “mini”
out: “minnie”