Is it possible to have conditional name (label, state…) ? My situation: i have shutter on my window. For this i use esphome on shelly module. So, i HA i get cover sensor, which reports state of cover: from 0 to 100%.
Now… i’d like name (or label…) to show:
word “UP” when cover is at 100% (fully up)
word “DOWN” when cover is at 0% (fully down)
percentage when position is in the middle.
For this i need if—else for cover attribute “current_position”, but i’m searching and trying for two days now with no luck. i tried countless options…
So i created an additional sensor with if–else sentence for that. But, i’d like to know if it’s possible with direct use of if - else in a style:
Here’s what I did to return not only conditional text, but also an icon that changes (color and image) in response to an attribute.
[[[
var fan_mode = entity.attributes['fan_mode'];
var fan_action = entity.attributes['fan_action'];
var color = "lightGrey";
if (fan_mode == "on")
if (fan_action == "running")
color = "lightSkyBlue";
else
color = "white";
else if (fan_mode == "auto")
if (fan_action == "running")
color = "lightSkyBlue";
else
color = "white";
return `<ha-icon icon="mdi:fan"
style="width: 14px; height: 14px; color: ${color};"></ha-icon>
${fan_mode}/${fan_action}`
]]]
Uau… thanks a lot! It “kinda” works… i managed to correct your code to get correct word for fully-up and fully-down, but i still can’t get to show attribute value in between (in percents). I just can’t get to the point to have any attribute value to be shown. When moving code "return state_attr(…) results in an error…
EDIT: yeah!! It works. I replaced “return state_attr(“cover.kitchen” , “current_position”)” with "return cover_mode + “%” (silly me…)
Many thanks again!!!
It seems that i’ll have to learn to use variables…
Hi everyone
following “template: alerter-dual”
I have managed to make the button blink when it is turned on, but how is it done so that it only blinks when it is “unknown”?
Hello, I was using some button-card with a sensor that was reading the value from History Stats attribute (In that way I was able to format the time in a readable way).
This attribute was removed with the last core update and now I can only display the time using the History Stats state but is repoted like 8,5h, is there a wa to convert this value in something like 08:12 (HH:MM) or 8h 12m (XXh YYm) for expample?
I want to show 2 states of different entities in one button.
I’ve got the state of my weather entity but I also want to show the temprature which is another entity so maybe it can be done by label or something.