Unfortunately I have no idea where and what the difference is to JS template or jinja template i test the examples
What is the right way for installation?
Can I see if everything is installed correctly and Custom UI is working properly?
What about when you need to change the icon color based on the state of an entirely separate entity?
I have a button to execute a script on my dashboard, but because a script has no state the script toggles a boolean on or off. So even though my button entity is for a script, the script icon needs to changed based on the state of the associated boolean.
Hereās what I have in my customization file but itās not working:
did you read the docs and check the examplesā¦?
Guess not, because you use a mix between Jinja and JS templates, and not the required pure JS.
also, there are a couple of āglobalā examples.
# using an attribute of another (global) entity
sensor.power_consumption:
templates:
icon_color: >
if (entities['sensor.smart_meter'].attributes.power > 3000) return 'red';
return green;
Thanks. I did read. Half the docs supplied with integrations and custom cards still say to include resources in the Lovelace file, and examples are relevant assuming itās still 2015. I am also using card-mod.
and refresh webpage or app page after reloading configuration.yaml?
Configuration / server controls / localizations and customizations
if you click on the entity, and select attributes (providing of course you have custom-ui also installed and running), can you see your customized code under attributes
also try (note === rather than == , & else before last āreturnā)
icon_color: >
if (state === 'Idle') return 'rgb(68,115,158)';
if (state === 'Cleaning') return 'rgb(253,216,53)';
else return 'rgb(73,158,68)';
I was facing yesterday same problem and I realized that simply it does not work for all Lovelace card. Some of them are using their own color handling and in such case custom_ui cannot help.
Eg. glances or entity cards work, button card does not.
So first try to use the sensor.washing_machine_cycle in glances card. If coloring works fine then it is an issue of used Lovelace card.
Your templates seem fine. (Top template needs an extra indent though like the one below)
Did you correctly install custom-ui? Check at configuration/info
Note the icon is actually imported by button-card, so I commented that bit, but left it in for educational purposes.
Entity card, one shall have to resort to card-mod, as with picture-glance (which you already know as we talked extensively on that with my pond-pumps card )
btw, you can hide the templates and icon_color attributes from the more-info
in you Number() template: I believe you can simply compare the state of the input_number, the JS will figure it out and treat it as a number?
EDIT:
on the Number(): it is indeed necessary, sorry for the confusion. See in the post below for some extra comments on that.