I have a few entities on an entities card. For every entity I have a card-mod node to style the icon color.
For every entity I have to use almost the same code to change the icon color. Normally, I would change that by putting the code in a function and calling that function with a parameter.
Is that possible? I really don’t know where, how and in what languate it should be done …
Anyone who can point me in the right direction? Don’t need a full solution .
NOW
card_mod:
style: |
:host {
--card-mod-icon-color:
{% set state = states('sensor.SENSOR1') %}
{% if 'WWW' in state %}
LimeGreen
{% elif 'XXX' in state %}
DeepSkyBlue
{% elif 'YYY' in state %}
DarkOrange
{% elif 'ZZZ' in state %}
blue
{% else %}
LightGray
{% endif %};
}
WHAT I WANT
card_mod:
style: |
:host {
--card-mod-icon-color:
GET_ICON_COLOR(states('sensor.SENSOR1') );
}
Function GET_ICON_COLOR
Function GET_ICON_COLOR(in SENSORSTATE string, out ICONCOLOR string) {
{% if 'WWW' in state %}
LimeGreen
{% elif 'XXX' in SENSORSTATE %}
'DeepSkyBlue'
{% elif 'YYY' in SENSORSTATE %}
'DarkOrange'
{% elif 'ZZZ' in SENSORSTATE %}
'blue'
{% else %}
'LightGray'
{% endif %};
}
or something like that. What I wrote before: I dont know the right language for coding this. Hope you get the idea…