Using named templates for repeated entities

When adding multiple similar entities a way to include a template file, load it with dynamic variables and the result is parsed as configuration. Something like this in configuration.yaml

!include_template: templates/shelly_1pm.j2
  data:
    base_topic: shellies
    ids:
      - aabbccddee
      - ddeeffa339a
      - 3344bbccaa

And the template could hold all the entities that is required for this device

{% for id in data.ids %}
- sensor:
  platform: mqtt
  name: "Shelly {{ id }} power usage"
  state_topic: {{ data.base_topic }}/{{ id }}/meter/power

- switch:
  name: "Shelly {{ id }} relay"
  platform: mqtt
  command_topic: { data.base_topic }}/{{ id }}/relay/0/command
  state_topic: { data.base_topic }}/{{ id }}/relay/0
  payload_on: "on"
  payload_off: "off"
{% endfor %}

A library of templates could be built up for common devices. I’m sure that there could be other uses for templates around the configuration