Reuse template sensor

I would like to display the remaining battery capacity of my thermostats. Therefore I wrote a template sensor which maps the battery voltage to a percentage value.

Currently I have 6 thermostats in my house. Is there a smart way to reuse this configuration for the remaining thermostats or do I have to copy and paste everything?

sensor:
  - platform: template
    sensors:
      bath_thermostat_battery:
        friendly_name: 'Bath Thermostat Battery'
        value_template: >-
            {%- if states.climate.bath.attributes.battery < 2.8 %}
                90
            {%- elif states.climate.bath.attributes.battery < 2.6 %}
                70
            {%- elif states.climate.bath.attributes.battery < 2.5 %}
                55
            {%- elif states.climate.bath.attributes.battery < 2.4 %}
                35
            {%- elif states.climate.bath.attributes.battery < 2.3 %}
                20
            {%- elif states.climate.bath.attributes.battery < 2.2 %}
                10
            {% else %}
                100
            {%- endif %}
1 Like

I need this as well, did you find a solution for this?

Maybe this topic can be helpful to you guys.

1 Like