right, and something like that’s in my dashboard
I would have shortened the templates, or at least c&p them, if not for the attribute on the entity…
Yaml for Sunchance
type: custom:fold-entity-row
head:
type: section
label: Zonkans KNMI
card_mod: !include /config/dashboard/card_mods/label.yaml
# padding: 0
entities:
- type: custom:hui-element
card_type: entities
card_mod:
style:
hui-attribute-row:
$: |
hui-generic-entity-row {
padding: 0px 16px;
margin: 0px -16px;
border-radius: 24px;
border: 2px solid rgb(49,150,207);
border-shadow: 2pt;
height: 25px;
}
ha-attribute-value {
color: var(--primary-color);
}
/*.text-content:not(.info) {
color: var(--primary-color);
}*/
.: |
ha-card {
color: black;
--card-mod-icon-color: gold;
--mdc-icon-size: 20px;
}
entities:
- type: attribute
entity: binary_sensor.knmi_zon
name: Vandaag
attribute: sun_chance0
suffix: '%'
card_mod:
style: |
hui-generic-entity-row {
background:
{% set kans = state_attr(config.entity,'sun_chance0')|float(0) %}
{% set rest = 100 - kans %}
{% if kans >= 75 %} {% set bar = '255,215,0' %}
{% elif kans >= 50 %} {% set bar = '255,165,0' %}
{% elif kans >= 25 %} {% set bar = '135,206,235' %}
{% else %} {% set bar = '128,128,128' %}
{% endif %}
/*linear-gradient(to left,ivory {{rest}}%, {{bar}} {{kans}}%);*/
linear-gradient(to right, rgb({{bar}}) 0%, rgb({{bar}}) {{kans}}%, rgba({{bar}},0.6) {{kans}}%, rgba({{bar}},0.2) 100%);
}
- type: attribute
entity: binary_sensor.knmi_zon
name: Morgen
attribute: sun_chance1
suffix: '%'
card_mod:
style: |
hui-generic-entity-row {
background:
{% set kans = state_attr(config.entity,'sun_chance1')|float(0) %}
{% set rest = 100 - kans %}
{% if kans >= 75 %} {% set bar = '255,215,0' %}
{% elif kans >= 50 %} {% set bar = '255,165,0' %}
{% elif kans >= 25 %} {% set bar = '135,206,235' %}
{% else %} {% set bar = '128,128,128' %}
{% endif %}
/*linear-gradient(to left,ivory {{rest}}%, {{bar}} {{kans}}%);*/
linear-gradient(to right, rgb({{bar}}) 0%, rgb({{bar}}) {{kans}}%, rgba({{bar}},0.6) {{kans}}%, rgba({{bar}},0.2) 100%);
}
- type: attribute
entity: binary_sensor.knmi_zon
name: Overmorgen
attribute: sun_chance2
suffix: '%'
card_mod:
style: |
hui-generic-entity-row {
background:
{% set kans = state_attr(config.entity,'sun_chance2')|float(0) %}
{% set rest = 100 - kans %}
{% if kans >= 75 %} {% set bar = '255,215,0' %}
{% elif kans >= 50 %} {% set bar = '255,165,0' %}
{% elif kans >= 25 %} {% set bar = '135,206,235' %}
{% else %} {% set bar = '128,128,128' %}
{% endif %}
/*linear-gradient(to left,ivory {{rest}}%, {{bar}} {{kans}}%);*/
linear-gradient(to right, rgb({{bar}}) 0%, rgb({{bar}}) {{kans}}%, rgba({{bar}},0.6) {{kans}}%, rgba({{bar}},0.2) 100%);
}
but… wait could it be possible now that I look at it again…
Yes! we can set the
{% set kans = state_attr(config.entity,config.attribute)|float(0) %} using config.attribute.
I never tried the before and it just works 
Yaml with config.attribute &anchor
- type: attribute
entity: binary_sensor.knmi_zon
name: Vandaag
attribute: sun_chance0
suffix: '%'
card_mod: &style_bar
style: |
hui-generic-entity-row {
background:
{% set kans = state_attr(config.entity,config.attribute)|float(0) %}
{% set rest = 100 - kans %}
{% if kans >= 75 %} {% set bar = '255,215,0' %}
{% elif kans >= 50 %} {% set bar = '255,165,0' %}
{% elif kans >= 25 %} {% set bar = '135,206,235' %}
{% else %} {% set bar = '128,128,128' %}
{% endif %}
/*linear-gradient(to left,ivory {{rest}}%, {{bar}} {{kans}}%);*/
linear-gradient(to right, rgb({{bar}}) 0%, rgb({{bar}}) {{kans}}%, rgba({{bar}},0.6) {{kans}}%, rgba({{bar}},0.2) 100%);
}
- type: attribute
entity: binary_sensor.knmi_zon
name: Morgen
attribute: sun_chance1
suffix: '%'
card_mod: *style_bar
- type: attribute
entity: binary_sensor.knmi_zon
name: Overmorgen
attribute: sun_chance2
suffix: '%'
card_mod: *style_bar