Hoping for some help with a simple template

Can someone help me with the writing of a template in the exclude portion of the automation below. If this is doable?

I would like to exclude anything that doesn’t have the word “level” in the entity name or possibly even use the device name that the entity is related to. Is this case specific in each instance?

My entities are named as:

water_heater_water_sensor_battery_level

My devices are named as:

Water Heater Water Sensor

alias: >-
  (ACTION- AUTOMATIC- SECURITY- NOTIFICATION) Low battery level detection &
  notification for all battery sensors
description: ""
use_blueprint:
  path: sbyx/low-battery-level-detection-notification-for-all-battery-sensors.yaml
  input:
    time: "19:00:00"
    day: 7
    actions:
      - service: script.text_notify
        data:
          who: parents
          title: LOW BATTERY
          message: There is a low battery on the {{sensors}}.
          data: null
          group: batteries
          tag: null
    exclude:
      entity_id:
        - sensor.westons_iphone_12_battery_level
        - sensor.weston_s_ipad_battery_level
        - sensor.lenovo_tablet_battery_level
        - sensor.garage_door_battery_level

Thank you all so much for your help/ guidance!!

And below is the blueprint the above is referencing:

blueprint:
  name: Low battery level detection & notification for all battery sensors
  description: Regularly test all sensors with 'battery' device-class for crossing
    a certain battery level threshold and if so execute an action.
  domain: automation
  input:
    threshold:
      name: Battery warning level threshold
      description: Battery sensors below threshold are assumed to be low-battery (as
        well as binary battery sensors with value 'on').
      default: 20
      selector:
        number:
          min: 5.0
          max: 100.0
          unit_of_measurement: '%'
          mode: slider
          step: 5.0
    time:
      name: Time to test on
      description: Test is run at configured time
      default: '10:00:00'
      selector:
        time: {}
    day:
      name: Weekday to test on
      description: 'Test is run at configured time either everyday (0) or on a given
        weekday (1: Monday ... 7: Sunday)'
      default: 0
      selector:
        number:
          min: 0.0
          max: 7.0
          mode: slider
          step: 1.0
    exclude:
      name: Excluded Sensors
      description: Battery sensors (e.g. smartphone) to exclude from detection. Only entities are supported, devices must be expanded!
      default: {entity_id: []}
      selector:
        target:
          entity:
            device_class: battery
    actions:
      name: Actions
      description: Notifications or similar to be run. {{sensors}} is replaced with
        the names of sensors being low on battery.
      selector:
        action: {}
  source_url: https://gist.github.com/sbyx/1f6f434f0903b872b84c4302637d0890
variables:
  day: !input 'day'
  threshold: !input 'threshold'
  exclude: !input 'exclude'
  sensors: >-
    {% set result = namespace(sensors=[]) %}
    {% for state in states.sensor | selectattr('attributes.device_class', '==', 'battery') %}
      {% if 0 <= state.state | int(-1) < threshold | int and not state.entity_id in exclude.entity_id %}
        {% set result.sensors = result.sensors + [state.name ~ ' (' ~ state.state ~ ' %)'] %}
      {% endif %}
    {% endfor %}
    {% for state in states.binary_sensor | selectattr('attributes.device_class', '==', 'battery') | selectattr('state', '==', 'on') %}
      {% if not state.entity_id in exclude.entity_id %}
        {% set result.sensors = result.sensors + [state.name] %}
      {% endif %}
    {% endfor %}
    {{result.sensors|join(', ')}}
trigger:
- platform: time
  at: !input 'time'
condition:
- '{{ sensors != '''' and (day | int == 0 or day | int == now().isoweekday()) }}'
action:
- choose: []
  default: !input 'actions'
mode: single

Use the following in your exclude

{{ states.sensor | map(attribute='entity_id')
| reject('search', 'level') | list }}

Thank you for your help with this. I will give it a go in just a few.

Thank you so much!!