I recently install Custom-UI and can do a basic icon color change without issue so I know it’s working. But now I’m trying to change the color of an icon based on whether two version sensors match or not. After reading a number of posts regarding similar actions, I still can’t seem to figure out exactly how to compare the sensors. I’ve tried a number of variations of this sort of thing, but none of them seem to work:
sensor.current_version:
icon_color: salmon
sensor.latest_version:
templates:
icon_color: if (state === sensor.current_version.state) return 'green'; else return 'red';
# Have also tried...
state === states.sensor.current_version.state
state === hass.states.get(sensor.current_version)
Can you not do a simple state comparison with customize.yaml?
I’m sorry, I don’t see how this relates to my question. I’m able to do a basic icon color change based on the state of the sensor, but what I’m trying to do is change it based on whether it is equal to the state of a second sensor.
I think there’s a lot of us that are “learning by stealing”! It’s nice that there’s such a good community of people willing to help us newbies. Perhaps at some point I’ll be able to help others as well.
So now that I got this working I figured I’d try something similar for my SSL certificate expiration. Unfortunately that’s not working and I’m not seeing any errors.
sensor.ssl_cert_expiry:
templates:
icon_color: >
if (entities['sensor.ssl_cert_expiry'].state < 20)
return 'red';
else if (entities['sensor.ssl_cert_expiry'].state < 30)
return 'yellow';
else
return 'green';
I guess that makes sense being you’re only dealing with the current sensor and not comparing it to something else. Once I changed it it started to work:
sensor.ssl_cert_expiry:
templates:
icon_color: >
if (state < 20)
return 'red';
else if (state < 30)
return 'yellow';
else
return 'green';