I’ve been using the hass-lovelace_gen add-on to add jinja support to lovelace cards, and I’ve found it incredibly useful. I really like being able to define re-usable macros. I’m using this for my 3D Floorplan config, and I couldn’t imagine writing this config without it. (If this didn’t exist then I would have to write my own scripts to generate the YAML configuration.)
Now I really miss these features while I’m working on the rest of my Home Assistant configuration. I’ve been splitting up my configuration into different packages, and I’ve come across lots of cases where variables, loops, and macros would be super useful. Here’s one example - I’m working on the configuration for iOS app actions, which currently look like this:
ios:
actions:
- name: Turn Off Lights
background_color: "#073642"
label:
text: Turn Off Lights
color: "#ffffff"
icon:
icon: lightbulb_group_off
color: "#ffffff"
- name: Arm Away
background_color: "#cb4b16"
label:
text: Arm Away
color: "#ffffff"
icon:
icon: alarm_light
color: "#ffffff"
- name: Arm Home
background_color: "#268bd2"
label:
text: Arm Home
color: "#ffffff"
icon:
icon: alarm_light
color: "#ffffff"
...
Here’s what it would look like if I could write a jinja template and set up a macro:
ios:
actions:
{%- macro ios_action(name, icon, bg_color, text_color='ffffff') -%}
- name: "{{ name }}"
background_color: "#{{ bg_color }}"
label:
text: "{{ name }}"
color: "#{{ text_color }}"
icon:
icon: "{{ icon }}"
color: "#{{ text_color }}"
{%- endmacro -%}
{{ ios_action("Turn Off Lights", icon="lightbulb_group_off", bg_color="073642") }}
{{ ios_action("Arm Away", icon="alarm_light", bg_color="cb4b16") }}
{{ ios_action("Arm Home", icon="alarm_light", bg_color="268bd2") }}
{{ ios_action("Disarm", icon="alarm_light_off", bg_color="859900") }}
{{ ios_action("Unlock Front Door", icon="lock_off", bg_color="859900") }}
{{ ios_action("Turn On Coffee Machine", icon="coffee", bg_color="8b4513") }}
{{ ios_action("Disable Bedroom Motion Sensors", icon="motion_sensor_off", bg_color="073642") }}
{{ ios_action("Turn On Bedside Lights", icon="lightbulb_on", bg_color="fdf6e3", text_color="073642") }}
The only downside I can think of is that I would need to start using {% raw %} ... {% endraw %}
in my actual templates for sensors, etc.
Would it be possible add this as an optional feature? I think a lot of people would find this useful once their configuration starts to become more complex. Thanks!