Seeding Option List from the Attributes of another entity

Hi,
I am trying to add a list of options to an input_select from the attributes of another entity.
So, the input select is:

ground_hvac_vertical_swing:
  name: Ground HVAC vertical Swing
  options:
    - stopped
  icon: mdi:sun-snowflake-variant

and the state_attr(‘entity_name’, ‘swing_modes’) returns a list like:

{{ state_attr('climate.ground_hvac', 'swing_modes') }}
[
  "stopped",
  "fixedtop",
  "fixedmiddletop",
  "fixedmiddle",
  "fixedmiddlebottom",
  "fixedbottom",
  "rangefull"
]

and the action I am using is:

          - action: input_select.set_options
            metadata: {}
            data:
              options: |
                {{ state_attr('climate.ground_hvac', 'swing_modes') }}
            target:
              entity_id: input_select.hvac_vertical_swing_modes

I have tried returning the list as a string like:

              options: |
                {% set modes = state_attr('climate.ground_hvac', 'swing_modes') %}
                {{ '[' }}{% for mode in modes %}{{ mode ~ ',' }}{% endfor %}{{ ']' }}

but I have failed completely to generate anything that works.

Help Please.

The action you said you are using is the correct syntax, but it looks like the entity ID you are using in it does not match the input_select entity you configured…

- action: input_select.set_options
  data:
    options: |
      {{ state_attr('climate.ground_hvac', 'swing_modes') }}
    target:
      entity_id: input_select.ground_hvac_vertical_swing

Thanks, The source of the list is in the climate.ground_hvac, but the target is input_select.ground_hvac_vertical_swing. The resulting error is:

Error:`template value should be a string for dictionary value @ data['actions'][0]['choose'][3]['sequence'][0]['data']. Got {'options': "{{ state_attr(!input hvac_entity_id, 'swing_modes') }}\n", 'target': {'entity_id': 'input_select.loft_hvac_vertical_swing_modes'}}` .

That is what I used in the post above… it is not what you used in your original post.

That is not what I suggested using.

You can’t use !input in templates. If you are creating a Blueprint that needs to get values from inputs into templates, there is a Cookbook article for that. If you are not creating a blueprint it is highly unlikely you actually have any inputs.

Sorry for the confusion. I did replace the !input in the first section, but did not in the second. I will edit to remove the confusion. The error is NOT as you have suggested, as the error is generated by the resulting automation, not the source blueprint.

I need to get the result of the state_attr('climate.ground_hvac', 'swing_modes') into the options of the input_select.set_options using code (jinja2). That is what I am asking, and that is what I am unable to do without error. Any help with the code necessary to do this correctly is much appreciated.

Here is the correct answer to the question (took me a couple of days):

actions:
  - action: input_select.set_options
    metadata: {}
    data:
      options: |
        {% set modes = state_attr('climate.ground_hvac', 'fan_modes') %}
        {{ "[" }}
        {%- for mode in modes -%}
          {% if loop.index == loop.length %}
            {{- mode -}}
          {% else %}
            {{- mode ~ ', ' -}}
          {% endif %}
        {%- endfor -%}
        {{ "]" }}
    target:
      entity_id: input_select.loft_hvac_fan_modes

I’m very doubtful that is actually working. By that I mean it may be populating the options, but the value contained in options will not be a list containing multiple items… it will be a list containing a single list-shaped string like “[auto, on]”.

Correct. Not working:

Here is the correct answer to the question (took me a couple of days):

actions:
    - action: input_select.set_options
      metadata: {}
      data:
        options: |
          {{ state_attr('climate.loft_hvac', 'fan_modes') }}
      target:
        entity_id: input_select.loft_hvac_fan_modes

I did this originally, but it was generating errors. Found the errors in another part of the code that was impacting the variables I was using. All good now.