Input_select templating

I would like to have an input_select with the states of some sensors. In my case these sensors show the name of a certain file. I don’t think it’s possible with templating, but is there a workaround or maybe a custom component?

I’m looking for something like this:

input_select:
  options:
    - {{ states('sensor.name_file_1') }}
    - {{ states('sensor.name_file_2') }}

etc

There is a service to set the options of an input select.

You could trigger an automation any time one of your file sensors changes and set the options as you want them.

automation:
  - alias: set_input_select_options
    trigger:
      platform: state
      entity_id: 
        - sensor.name_file_1
        - sensor.name_file_2
    action:
      - service: input_select.set_options
        data_template:
          entity_id: input_select.files ### or whatever you called it (not shown in your example)
          options: ["{{ states('sensor.name_file_1') }}", "{{ states('sensor.name_file_2') }}"]

Thanks for your reply! This points me in the right direction. What should I add in my configuration.yaml to show the file names as options?

input_select:
  name: Select file name
  options:
    - ???

Anything you want. The first time the automation is called they’ll be overwritten.

You should probably call the automation on start-up too.

By the way, this is all theoretical. I’ve never tested using templates in the set options list.

Just figured out the automations override the set options. But I don’t think the template works, because the options show {{ states('sensor.name_file_1') }} instead of the file name. Was this my last option or is it still possible to show the correct file name as an option in another workaround?

Remove the quotes from around the templates and try again.

action:
  - service: input_select.set_options
    data_template:
      entity_id: input_select.files ### or whatever you called it (not shown in your example)
      options: >
       [{{ states('sensor.name_file_1') }}, {{ states('sensor.name_file_2') }}]

Tried all combinations and ended up with this working:

  - service: input_select.set_options
    data_template:
      entity_id: input_select.files
      options:
        - Select
        - '{{ states("sensor.name_file_1") }}'
        - '{{ states("sensor.name_file_2") }}'
        - '{{ states("sensor.name_file_3") }}'

Thanks for you help @tom_l