Hello I want to loop through a variable subset of 6 entities, and for each entity, I want to run a script with 2 parameters, the name of the entity, and a second parameter that is different for each entity, which can be found in a json-style variable.
E.g. List of entities:
airco_1
airco_2
E.g. List of parameters
airco_1: param1
airco_2: param2
I found an example to loop through a dynamicly-created list of entities, and I can use the entity name inside the loop by calling e.g. ac_off[repeat.index-1]
in the code below , however I can’t figure out how to retrieve the adhoc parameter from within the json list, where the key to search for would be ac_off[repeat.index-1]
.
Here is the code that I’m stuck with:
alias: Test airco script
variables:
ac_off: >
{{ expand(area_entities('Clims')) | selectattr('state','in', ['off']) |
map(attribute='entity_id') | list }}
ac_off_count: >
{{ expand(area_entities('Clims')) | selectattr('state','in', ['off']) | list
| count }}
map_attributes: >
{ "climate.ac_salon_haut": "salon_haut", "climate.ac_salon_bas": "salon_bas", "climate.ac_chambre_haut_fond": "ch_haut_fond"}
sequence:
- repeat:
count: "{{ ac_off_count }}"
sequence:
- service: script.airco_action_an_ac_with_params
data: |
{"ac_name": "{{ ac_off[repeat.index-1] }}", "ac_mode": "heat", "ac_prefix": "{{ map_attributes[ac_off[repeat.index-1]] }}" }
mode: single
This returns blank for the “ac_prefix” attribute.
I also tried
map_attributes['ac_off[repeat.index-1]']
or
map_attributes.ac_off[repeat.index-1]
and nothing works…
Than must not be too difficult but I’m a total newbie…
Thanks for any hint!