Yarash
December 24, 2024, 3:53pm
1
Hi
I have been reading practically every single post in this regard, but i am unable to find a solution.
I am aware i can use this example:
card_mod:
style: |
:host {
{% if states('light.sample') == "off" -%}
--paper-item-icon-color: black;
{%- else -%}
--paper-item-icon-color: green;
{%- endif %}
}
The above example works fine, my problem is that my picture element has about 50 light icons
and i have four of these.
setting this up will take a huge amount of code, and managing it later
would be impossible.
Is there any way to set the icon state color globally?
i don’t mind if it changes all over the UI.
Thanks.
Sir_Goodenough
((SG) WhatAreWeFixing.Today)
December 24, 2024, 3:58pm
2
Hello Yarash ,
I bet you can use this…
Here are three methods for reusing code in Home Assistant / YAML.
First, be sure you’re using Lovelace YAML mode.
METHOD 1 - Anchors
Define anchors (the code you want to reuse) using the & key
You can define anchors when you’re using code for real, or you can create dummy entries like this in a Lovelace file (Be sure YAML code that creates anchors comes before the YAML code that uses the anchors):
dummy_colors:
color1: &yellow_gradient 'linear-gradient( 135deg, rgb(253, 235, 113) 10…
Also since you are using a custom card that has templates enabled, you could make a custom_template (macro) repeat functions over and over.
Yarash
December 24, 2024, 6:23pm
3
Can you please give me some more details regarding this cusrom template.
Thanks
Yarash
December 24, 2024, 9:44pm
4
When I come to think of it
I am sure I can use some regex find and replace
And even easier, probably AI can easily do it
Update:
I have used the github copilot AI, got it to perform the sample above to all entities from all types, worked great.