Script - sequence - for loop for service not working

I’m trying to build a script to store the volume level in each echo in the house using the efficiency of a for...loop so I’m not writing out more code each time I add an echo in the future.

The loop is building the number of services entries needed in the script. HA is giving me this error that I can’t seem to get past.

Error from the log:

... Invalid config for [script]: expected dictionary @ data['sequence'][0]. Got None. ...

How can I phrase the template text so the the sequence does not appear to be None?

Script text:

  alias: "Store echo volume levels"
  sequence: >
    {%- for echo in state_attr('input_select.echo_entity_listing', 'options') %}
    - service: input_number.set_value
        entity_id: {{'input_number.'+echo+'_volume'}}
        value: {{state_attr('media_player.'+echo, 'volume_level')}}
    {%- endfor -%}

Here is the output of the script using the Dev Tools template display, which looks just fine to me:


You can’t generate complex data structures from a template like that - you can only generate a value for a key. I believe you could do something like this with a YAML loop: Script Syntax - Home Assistant

That’s disappointing. It seems like this would be a thing easily digested by HA.

I’ll have to go back to making individual entries for each device. Thanks for your feedback.

Only because you have misunderstood a template’s purpose. It is used to compute an option’s value. You’re trying to use it to generate YAML statements (in other words to generate additional options). That has never been a valid use-case in Home Assistant (and the documentation contains no description or examples of it).

There is no service call to create an input_boolean entity. However, if you have already created all of the required input_booleans, it is possible to loop through them and assign values. Let me know if this is the case and I can help you compose the script.

Thanks for the background and your offer to help. I did misunderstand its capabilities/purpose.

All of my of the entities used in the script are predefined. Essentially I have a list of my echoes using input_select:
{{state_attr('input_select.echo_entity_listing', 'options')}}

Which yields:


and I have the same number of input_number entities that have the same name as the echo with “_volume” appended (e.g. input_number.garage_echo_volume):

And I want to loop through them to store the volume before I modify it, so I’m able to set it back to the stored level later in the script.