Templates - how to use a HA sensor name as a filter parameter?

I want to use a trigger.entity_id as a lookup in a list of dictionaries.

The reason I want this is because I can use the autofill feature to make sure I use the right sensor name when writing these things.

expected results:

input_select.state_bin_collection ---> [ 'bin', 'bin_indicator' ]
sensor.therm_living_current_temperature ----> [ 'house_temp' ]
variables:
  lookup:
    - input_select.state_bin_collection: bin
    - input_select.state_bin_collection: bin_indicator
    - input_select.dishwasher_state: dishwasher
    - input_select.dishwasher_state: utilities_indicator
    - sensor.therm_living_current_temperature: house_temp
  trigger_name: |-
    {%- if trigger.id == 'Data Change' -%}
       {{ lookup | rejectattr('trigger.entity_id', 'undefined') | map(attribute = trigger.entity_id') | list }}
   {%- else -%}
       null
  {%- endif -%}

When I do this the ‘.’ in ‘input_boolean.flag’ gets in the way somehow and I get an error.
If I use replace(‘.’,‘_’) on the trigger id and “hard code” change the data in the list I get what I want.
trigger.entity_id does return the correct name to use in that list.

What input_boolean.flag ?

You lack a quote

My bad - I was trying to simplify it and made a mess!

variables:
  lookup:
    - input_select.state_bin_collection: bin
    - input_select.state_bin_collection: bin_indicator
    - input_select.dishwasher_state: dishwasher
    - input_select.dishwasher_state: utilities_indicator
    - input_select.washing_machine_state: utilities_indicator
    - sensor.openweathermap_condition: weather
  app_names: |-
    {% set x = trigger.entity_id %}
    {{ lookup | rejectattr(x, 'undefined') | map(attribute = x) | list }}

if trigger.entity_id = ‘input_select.state_bin_collection’ I’d expect to get app_names = [ ‘bin’, ‘bin_indicator’ ]

instead I get:

Error: UndefinedError: ‘dict object’ has no attribute ‘input_select’

Changing it to:-

variables:
  lookup:
    - input_select_state_bin_collection: bin
    - input_select_state_bin_collection: bin_indicator
    - input_select_dishwasher_state: dishwasher
    - input_select_dishwasher_state: utilities_indicator
    - input_select_washing_machine_state: utilities_indicator
    - sensor_openweathermap_condition: weather
  app_names: |-
    {% set x = trigger.entity_id | replace('.','_') %}
    {{ lookup | rejectattr(x, 'undefined') | map(attribute = x) | list }}

then this gives me the desired result - ie. I have sidestepped the issue caused by the ‘.’ by replacing it in the attribute I’m matching and the trigger.entity_id

It would be neater to not have to rename the keys.

I know that is a better explaination! I hope it is now understandable.
Thanks,