Templating minimum value form list

i have problem to make template for battery_level. I get from my sensors sensors which are not updated at the same time because of threshold and sleep. Sometimes aj change configuration of node and start/stop sending some variables which create new sensor and send another battery level. To make it preciese i have to all time manually edit template sensor and and/delete entity ids from it. I try to make some template with for but i dont know how to make list from that and apply filter minimum
This is how look my manual edit:

{{ [state_attr('sensor.bme280_sensor_104_0', 'battery_level')|default(101, True),
state_attr('sensor.bme280_sensor_104_1', 'battery_level')|default(101, True),
state_attr('sensor.bme280_sensor_104_2', 'battery_level')|default(101, True),
state_attr('sensor.bme280_sensor_104_3', 'battery_level')|default(101, True),
state_attr('sensor.bme280_sensor_104_4', 'battery_level')|default(101, True),
state_attr('sensor.bme280_sensor_104_5', 'battery_level')|default(101, True),
state_attr('sensor.bme280_sensor_104_6', 'battery_level')|default(101, True),
state_attr('sensor.bme280_sensor_104_7', 'battery_level')|default(101, True) ] | min  }}

i try to create some for loop (succesfull) but i dont know how to make list from them:

{% set tofind= ‘bme280_sensor’%}
{% for item in states if ( item.entity_id | regex_search(tofind, ignorecase=FALSE)) and not ( item.entity_id | regex_search(‘battery’, ignorecase=FALSE))%}{{state_attr(item.entity_id, ‘battery_level’)|default(101, True)}} {% endfor %}

i found min_max sensor in HA but i have to again do it manualy because entity_id dont support for loop

How can i do it ? i want only fill sensor name and that stuff make it for me :slight_smile:
Thank you

Even if you did get a loop, you’d have to hard code the entity_id’s to the template sensor. Template sensors only update when a ‘found’ entity_id updates. If you use a loop, the parser will not find any entity_ids and therefore never update. You’re in a catch 22. I suggest you use a python script paired with an automation to handle updating this sensor.