Copy-paste the following template into the Template Editor and confirm it reports the desired results.
If it works the way you want, use it in the message
option.
{% set batteries = state_attr('sensor.batteries', 'entity_id') %}
{% set ns = namespace(weak=[]) %}
{% for b in expand(batteries) if b.state | is_number and b.state | int(0) <= 10 %}
{% set ns.weak = ns.weak + [b.name] %}
{% endfor %}
{{ ns.weak | sort | join(', ') }}