How to read text file and add to input select

Good work! :+1:

BTW, the file_list attribute already contains a list so there’s no need to use a for-loop to create a list.

All that’s need is just to slice off the file-path information for each item in the list and that’s easily done like this:

    action:
      - service: input_select.set_options
        target:
          entity_id: input_select.mp3_files
        data:
          options: >
            {{ state_attr('sensor.alarm_clock_sounds', 'file_list') | map('replace', '/config/www/alarm_clock_sounds/', '') | list }}

Here’s an example using some files on my test machine located in /config/data.

2 Likes