Applying same configuration to not only a single sensor, but a set of senor!

I have a set of xiaomi sensors (15), and arround 10 Mqtt sonoff devices. If I want to add extra sensor based of the previous one, I have to duplicate file and setup configuration again and again.

For example, I get a script to display the battery of my xiaomi:

platform : template
sensors:
  battery_xiaomi_door_buanderie:
    friendly_name: 'Batterie capteur porte buanderie'
    unit_of_measurement: '%'
    value_template: >
      {%- if states.binary_sensor.door_window_sensor_d000245d5.attributes.battery_level %}
        {{ states.binary_sensor.door_window_sensor_d000245d5.attributes.battery_level|round }}
      {% else %}
        {{ states.binary_sensor.door_window_sensor_d000245d5.state }}
      {%- endif %}
    icon_template: '{%- if  states.binary_sensor.door_window_sensor_d000245d5.attributes.battery_level <= 5 %}mdi:battery-outline{%- elif states.binary_sensor.door_window_sensor_d000245d5.attributes.battery_level >= 95 %}mdi:battery{% else %}mdi:battery-{{(states.binary_sensor.door_window_sensor_d000245d5.attributes.battery_level|float / 10)|round*10}}{%- endif %}'

I got this snippet somewhere in the form, but I had to setup 15 files to make the conf complete and running, and if there is one day a better template, I will have to change every 15 single file

Another example, I would like to make some test, and want to add some history_stat for a couple of sensor. I need this with count, time ratio.

platform: history_stats
name: Chauffeau en marche (count)
entity_id: switch.sonoff_power_1
state: 'on'
type: count
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'

This is the same here, again I have to copy file

Would be good to be able to apply a group (or class/catergory) of sensor to a template, something like this.