Restore/save dynamic input_select options and state after HA restart

Hello, i have multiple scrips/automations that modifies serval input_select helpers, all work correctly until an HA restart when all the dynamic input_select revert to the static one.
I have searched all topics and info and did not find any solution to this, if someone has any idea will be greatly appreciated.

The closest and best idea that I can see is using pyscript to create a service call to save and restore the input_select after restart, unfortunately I have no knowledge of python, but I can follow some simple coding to a point. Best example is this old post
What i understand is that is creating a service call to run a python script that saved the input_select helper options and state to a .ini file and after restart repopulate the helper.
What I want is to use it with multiple entities (input_select helpers) so it needs to generate the ini file based on the name of the entity.

Here is the code that I coped from the other post:
For save

# Write file from input_select.

import sys

# File I/O is done in a called module - ensure the path includes it. Note that this only needs to be added
# to one file ... pyscript picks it up when loading the files.
if "/config/pyscript_modules" not in sys.path:
    sys.path.append("/config/pyscript_modules")

import file_ops


# This runs as a service, and is normally run from an automation.
@service
def save_input_select(entity=None, result=None):
    log.debug(f"got entity {entity}, result {result}")

    # Inputs are required. They are defined as optional so we can just log an error instead of encountering
    # an exception.
    if entity is None or result is None:
        log.error("entity and result are both required, exiting")

    # Domain must be input_select.
    elif not entity.startswith("input_select."):
        log.error("input entity must be domain input_select, exiting")

    # All seems well.
    else:
        # List of all movies
        movies = result['movies']
        all_movies = []
        for movie in movies:
            all_movies.append(movie['label'])
        all_movies.sort()
        log.debug(f"movie list {all_movies}")

        # Populate the input select.
#        input_select.set_options(entity_id=entity, options=all_movies)

        # Write the list to a file so we can restore the input select after a restart.
        task.executor(file_ops.write_movie_file, all_movies)

For restoring the helper

# Restore the given input select from the previously saved list.

import file_ops


# This runs as a service, and is normally run from an automation.
@service
def restore_input_select(entity=None):
    log.debug(f"got entity {entity}")

    # Input entity is required. It is defined as optional so we can just log an error instead of encountering
    # an exception.
    if entity is None:
        log.error("entity is required, exiting")

    # Domain must be input_select.
    elif not entity.startswith("input_select."):
        log.error("input entity must be domain input_select, exiting")

    # All seems well.
    else:

        # Read the backup file.
        try:
            all_movies = task.executor(file_ops.read_movie_file)
        except FileNotFoundError:
            log.error(f"saved movie file not found, exiting")
            sys.exit(f"file not found")
        except pickle.UnpicklingError:
            log.error(f"saved movie file not usable, exiting")
            sys.exit(f"file not usable")

        log.debug(f"movie list {all_movies}")

        # Populate the input select.
        input_select.set_options(entity_id=entity, options=all_movies)

Anyone can help me with modifications to the code to fit my needs?

Maybe I’m wrong and your use case is different from mine, but I faced the same problem when I wanted to dynamically display the Hue scenes of my lamps listed as attributes.
Since then I’ve been using Template Select in combination with input_text and have not had any problems, even after a restart.

Thanks for the info but it does not help me, in my automations I create a dynamic input_select by removing options one by one and is necessary to keep that after restart for the automation to continue to work correctly.
Example here:

service: input_select.set_options
data:
  options: >-
    ({% set ns = namespace(list=[]) %} {% for option in
    state_attr("input_select.type_of_meal_filtered", "options") if option !=
    states("input_text.type_of_meal_random") %} {% set ns.list =
    ns.list+[option] %} {%endfor%} {{ns.list}})
target:
  entity_id: input_select.type_of_meal_filtered
enabled: true

How large is the complete list? If it isn’t too long, you might be able to change the way your input_text works so that it hold all the “used” options. That would let you add a trigger for home assistant restart to run your input_select.set_options.

The lists can get pretty large, and they will grow with time.
The functionality of them all is to recommend an random meal every day, but do not repeat any category or meal until all of them where recommended. I use two lists for every category/meal type/salad, one “full” that is fixed and can be edited from the HA UI to add meals, one “filtered” where the meals remaining to be recommended are stored.
All is functional until restart when the “filtered” list get’s reset and then some of the meals can’t get recommended and randomly you can get consecutive previously recommended meals.

The UI is still a work in progress but the main functionality is here.

I think your best bet is to move your filtered lists to Trigger-based template sensor attributes which will survive restart.