try this (untested):
filter:
template: >-
{% for state in states.sensor -%}
{%- if state.entity_id | regex_match("sensor.battery_", ignorecase=False) -%}
{{
{
'entity': state.entity_id,
'name': state.attributes.friendly_name.split(' battery')[0]
}
}},
{%- endif -%}
{%- endfor %}