Mabaelst
(Bart Teuwen)
May 10, 2025, 2:20pm
1
Hello everyone,
Is it possible to use a repear for each in a repeat for each.
See below:
actions:
- repeat:
for_each:
- min
- max
sequence:
- repeat:
for_each: |
{% set Lijst = states
|selectattr('domain', '==', 'input_number')
|selectattr('entity_id', 'search', 'vandaag')
|selectattr('entity_id', 'search', repeat.item)
|map(attribute='entity_id')
|list
%}
{{Lijst}}
sequence:
- data:
value: >
{% if states('sensor.' +
repeat.item.split('.')[1].split('_')[-5:-3]|join('_')+
'_nu_temp')|float <
states('input_number.' + repeat.item.split('.')[1].split('_')[-5:-3]|join('_') + '_vandaag_' + repeat.item + '_temp')|float %}
{{states('sensor.' + repeat.item.split('.')[1].split('_')[-5:-3]|join('_')+ '_nu_temp')|float}}
{% else %}
{{states('input_number.' + repeat.item.split('.')[1].split('_')[-5:-3]|join('_') + '_vandaag_' + repeat.item + '_temp')|float}}
{% endif %}
target:
entity_id: >
input_number.{{repeat.item.split('.')[1].split('_')[-5:-3]|join('_')}}_vandaag_{{repeat.item}}_temp
action: input_number.set_value
But this does not work.
If this is possible, how do I do this.
123
(Taras)
May 10, 2025, 2:33pm
2
Mabaelst:
how do I do this.
Eliminate the outer repeat
then change this line:
|selectattr('entity_id', 'search', repeat.item)
To this:
|selectattr('entity_id', 'search', (min|max))
Mabaelst
(Bart Teuwen)
May 10, 2025, 2:40pm
3
Thanks for your response.
Did you mean like this:
- repeat:
for_each: |
{% set Lijst = states
|selectattr('domain', '==', 'input_number')
|selectattr('entity_id', 'search', 'vandaag')
|selectattr('entity_id', 'search', (min|max))
|map(attribute='entity_id')
|list
%}
{{Lijst}}
sequence:
- data:
value: >
{% if states('sensor.' +
repeat.item.split('.')[1].split('_')[-5:-3]|join('_')+
'_nu_temp')|float <
states('input_number.' + repeat.item.split('.')[1].split('_')[-5:-3]|join('_') + '_vandaag_' + repeat.item + '_temp')|float %}
{{states('sensor.' + repeat.item.split('.')[1].split('_')[-5:-3]|join('_')+ '_nu_temp')|float}}
{% else %}
{{states('input_number.' + repeat.item.split('.')[1].split('_')[-5:-3]|join('_') + '_vandaag_' + repeat.item + '_temp')|float}}
{% endif %}
target:
entity_id: >
input_number.{{repeat.item.split('.')[1].split('_')[-5:-3]|join('_')}}_vandaag_{{repeat.item}}_temp
action: input_number.set_value
123
(Taras)
May 10, 2025, 2:49pm
4
Yes.
The single repeat
will iterate through all input_number
entities whose entity_id
contains “vandaag” and “min” or “max”.
Mabaelst
(Bart Teuwen)
May 10, 2025, 3:04pm
5
Thanks for your response.
But this is not the intention,
The intention is:
actions:
- repeat'(1)':
for_each:
- min
- max
sequence:
- repeat'(2)':
for_each: |
{% set List = states
|selectattr('domain', '==', 'input_number')
|selectattr('entity_id', 'search', 'today')
|selectattr('entity_id', 'search', repeat.item'(2)'
|map(attribute='entity_id')
|list
%}
{{List}}
sequence:
- dates:
value: >
{% if states('sensor.' +
repeat'(2)'.item.split('.')[1].split('_')[-5:-3]|join('_')+
'_now_temp')|float <
states('input_number.' + repeat'(2)'.item.split('.')[1].split('_')[-5:-3]|join('_') + '_today_' + repeat.item'(1)' + '_temp')|float %}
{{states('sensor.' + repeat'(2)'.item.split('.')[1].split('_')[-5:-3]|join('_')+ '_now_temp')|float}}
{%else%}
{{states('input_number.' + repeat'(2)'.item.split('.')[1].split('_')[-5:-3]|join('_') + '_today_' + repeat'(1)'.item + '_temp')|float}}
{%endif%}
target:
entity_id: >
input_number.{{repeat.item'(2').split('.')[2].split('_')[-5:-3]|join('_')}}_today_{{repeat.item'(1)'}}_temp
action: input_number.set_value
repeat'(1)' is 1st repeat
repeat'(2)' is 2nd repeat
123
(Taras)
May 10, 2025, 4:19pm
6
Mabaelst:
The intention is:
Your “intention” is code that doesn’t work.
It attempts to set values using two passes, the first pass for min
entities and the second pass for max
entities. It fails because repeat.item
in the inner repeat
cannot reference the outer repeat
.
What I suggested sets the values, referencing both min
and max
entities, in one pass.
If that’s unacceptable, you’ll need to explain why it’s important to process all min
entities first before processing the max
entities.
NOTE
Your updated example indicates you want to reference the repeat.item
from both the inner and outer repeat
within the same template. To my knowledge, that’s not possible because it cannot distinguish between the inner and outer repeat.item
.
You will need to redesign your template to work in a single repeat
.
1 Like
Mabaelst
(Bart Teuwen)
May 11, 2025, 9:23am
7
Thanks for your response.
So if I understand correctly I have to create 2 actions for this, in 1 this does not work