Your var_sensor_temp (and similarly var_sensor_kwh) are probably being defined as strings, so they wouldn’t have a .state property. Try replacing variables.var_sensor_temp.state with states[variables.var_sensor_temp].state
Thank you for your answer. I’m looking for a way to make an icon/img cell background color opaque and in this case - unfortunately! - opacity won’t work.
Thank you so much for your research. But this only seems to take effect with a defined color. That’s the reason why I asked for the source of the variable.
In this case animation works. Is it a bug or am I doing something something wrong? Do I need to create two different templates for animated and non-animated buttons?
Not sure it works then. The source of the variable is the light entity itself, so it’s always different depending on the entity used on. This is the line in the button-card that sets this variable I believe:
But you want this to not be transparant? I use this variable myself in light entities. but it’s not transparent for me. What do you use now for styling of the button-card?
These are templates using JavaScript. You’re going in the right direction with entity.name. The missing piece is to use search or indexOf. In your case, you need search if you want to ignore case, but you also need to switch your two conditions around, because (to use your syntax) '*refrigerator*' will also match '*refrigerators*'. In fact, if these are the only two options, you can simplify it even further (it’s a best practice to always have an else).
Try:
icon: |
[[[
var icon = 'mdi:brain';
if (entity.attributes.friendly_name.search('/refrigerators/i') != -1) {
var icon = 'mdi:fridge-variant-outline';
} else {
var icon = 'mdi:fridge-industrial-outline';
}
return icon;
]]]
So, search will find the string and return the index of the start of the match, using a regular expression, and ignoring case.
I assumed that entity.name would exist. Could you check that it’s the case (maybe your entity is undefined or some other issue)? You can also try entity.friendly_name too (I think it might work too).
I’m using --button-card-light-color as icon color and drop-shadow color and would love an opaque background (let’s say 0.3) based on --button-card-light-color .
Sorry, I got my syntax a bit wrong. I’ve updated my post to at least work in some way.
Now that you’ve shared your sensors I don’t think my solution will work for you, since you want to match on e.g. sensor.haos_vir_kitchen_refrigerators_power which I don’t think is possible (this is the entity, not the name).
From the button card’s perspective, name refers to the name set in the card’s config, or will default to the friendly name.
Hello i just implemented the amazing custom button @tismondo originally posted in May 2020 (thank you @tismondo !!). the last piece im trying to figure out is getting the popup to work when you click on the card. I followed all instructions and made sure i installed the Browser Mod. Below is the code im using for the card it self. Any assistance anyone can provide is greatly apricated!
There’s nothing in your code relating to browser-mod, so that makes it impossible to tell you what might be the cause of your issues. Please post the full decluttering template and the code for the card.
Also, please use proper formatting for your code so it can be copied over for testing.