Is it possible to create a template that can be called from other templates. For instance, I have sensors that report battery status that I have to create a “value_template” and an “icon_template” that is a large block of code. So could I create a template that contains the “value_template” and “icon_template” and call that template by name from another template?
Example:
front_door_hinge_battery:
friendly_name: "Front Door Battery"
entity_id: sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2
value_template: >-
{% if is_state('sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2', '0') %}
100%
{% elif is_state('sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2', '1') %}
90%
{% elif is_state('sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2', '2') %}
80%
{% elif is_state('sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2', '3') %}
70%
{% elif is_state('sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2', '4') %}
60%
{% elif is_state('sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2', '5') %}
50%
{% elif is_state('sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2', '6') %}
40%
{% elif is_state('sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2', '7') %}
30%
{% elif is_state('sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2', '8') %}
20%
{% elif is_state('sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2', '9') %}
10%
{% endif %}
icon_template: >-
{% if is_state('sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2', '0') %}
mdi:battery
{% elif is_state('sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2', '1') %}
mdi:battery-90
{% elif is_state('sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2', '2') %}
mdi:battery-80
{% elif is_state('sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2', '3') %}
mdi:battery-70
{% elif is_state('sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2', '4') %}
mdi:battery-60
{% elif is_state('sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2', '5') %}
mdi:battery-50
{% elif is_state('sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2', '6') %}
mdi:battery-40
{% elif is_state('sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2', '7') %}
mdi:battery-30
{% elif is_state('sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2', '8') %}
mdi:battery-20
{% elif is_state('sensor.ge_32563_hinge_pin_smart_door_sensor_alarm_level_2', '9') %}
mdi:battery-10
{% endif %}