I recently needed to set something up in HA that required a lot of repeated config for lots of similar entities. That was made much simpler using a template instead of writing the plain config (and far less scope for copy/paste errors!).
I found lots of people asking how to use templates in the HA config but no really good answers, so I put together and addon that does exactly that and thought I’d post it here in case anyone else would find it useful.
Here’s a basic example that sets up two smart thermostate climate entities.
This gets saved as a *.yaml.jina file in the HA config folder and automatically compiled to a *.yaml file by the addon, which is then included by the main HA config yaml file.
{% set rooms = [
{
"name": "Living Room",
"id_prefix": "living_room",
"kp": 100,
"ki": 0.01,
"kd": 2500
},
{
"name": "Study",
"id_prefix": "study",
"kp": 100,
"ki": 0.001,
"kd": 1000
}
] %}
{% set presets = {
"min": 7,
"max": 25,
"away": 7,
"eco": 17,
"sleep": 17,
"comfort": 19,
"boost": 21
} %}
climate:
{% for room in rooms %}
- platform: smart_thermostat
name: {{ room.name }} Smart Thermostat
unique_id: {{ room.id_prefix }}_smart_thermostat
heater: switch.{{ room.id_prefix }}_heating
target_sensor: sensor.{{ room.id_prefix }}_temperature
ac_mode: False
kp: {{ room.kp }}
ki: {{ room.ki }}
kd: {{ room.kd }}
keep_alive: 00:01:00
pwm: 00:25:00
min_cycle_duration: 00:5:00
{%- for preset in presets %}
{{ preset }}_temp: {{ presets[preset] }}
{%- endfor %}
target_temp: {{ presets["away"] }}
debug: true
{% endfor %}