I’m trying to use lovelace_gen and card-mod to create a badge template that will change CSS properties for 1…n family members based on their state…building on this (How to customize the badges at the top of the page? - #11 by Olivier1974).
This template generates properly formatted .yaml from the Developer Template Tool (i.e. if I copy/paste the output back into the .yaml, the badges render properly), but not when placed in the .yaml as a lovelace_gen template:
badges:
{%- set firstnames = [
'firstname1','firstname2','firstname3','firstname4','firstname5'
]
-%}
{% set lastname = 'lastname' -%}
{% for firstname in firstnames %}
- entity: person.{{ firstname }}_{{ lastname }}
name: {{ firstname.capitalize() }}
style: |
:host {
color: white;
{% if is_state('person.' ~ firstname ~ '_' ~ lastname,'home') -%}
--label-badge-red: green;
{%- else -%}
--label-badge-red: red;
{%- endif %}}
{%- endfor %}
Of course, I’ve replaced the strings of my family members’ names with placeholders. The line that was giving me a problem was this one:
{% if is_state('person.' ~ firstname ~ '_' ~ lastname,'home') -%}
But, it seemed to be the only way to get the template to work (i.e. properly set the label-badge-red property). However, this does not work for the actual dashboard (Unknown error - RELOAD UI)
I’ve also tried the following, but they didn’t even result in the proper css setting in the template tool:
{% if is_state('person.{{ firstname }}_{{ lastname }}','home') -%}
{% if is_state('person.' + {{ firstname }} + '_' + {{ lastname }},'home') -%}
{% if is_state('person.' ~ {{ firstname }} ~ '_' ~ {{ lastname }},'home') -%}
What’s the right syntax?
Note - I have lovelace_gen working on other views. Also, this particular .yaml file has the requisite #lovelace_gen as the first line and it is properly !include’d from another main .yaml file.
@thomasloven Any ideas to try? I’ve scoured the Jinja documentation and multiple posts/Google to see the proper way to concatenate. This seems IAW Jinja, so I’m not sure why it’s not working.