It seems to me that entity.state is not available if the button is included in a pop-up.
It might of course be that it is actually a ‘problem’ with browser_mod but I have no way of knowing.
Also, you might decide that is too obscure to want to look into but here it is in case you want to look at it.
This is the error when used in a pop-up:
button-card.js:1693 Uncaught ButtonCardJSTemplateError: TypeError: Cannot read property 'state' of undefined in 'var on_icon = 'mdi:checkbox-marked';
var off_icon = 'mdi:checkbox-blank-outline';
if (entit...'
at HTMLElement.eval (eval at _evalTemplate (http://192.168.1.25:8123/hacsfiles/button-card/button-card.js:1691:14), <anonymous>:7:14)
at HTMLElement._evalTemplate (http://192.168.1.25:8123/hacsfiles/button-card/button-card.js:1691:106)
at HTMLElement._getTemplateOrValue (http://192.168.1.25:8123/hacsfiles/button-card/button-card.js:1700:97)
at http://192.168.1.25:8123/hacsfiles/button-card/button-card.js:1958:62
at Array.forEach (<anonymous>)
at n (http://192.168.1.25:8123/hacsfiles/button-card/button-card.js:1957:40)
at http://192.168.1.25:8123/hacsfiles/button-card/button-card.js:1958:40
at Array.forEach (<anonymous>)
at n (http://192.168.1.25:8123/hacsfiles/button-card/button-card.js:1957:40)
at http://192.168.1.25:8123/hacsfiles/button-card/button-card.js:1958:40
I’m struggling with some custom colouring of a button card.
I have a button to control a garage door (cover). I also have an automation that starts a timer when it’s opened. I will get a notification on the companion app when this timer expires (i.e. I regard the door as left open for too long, for safety reasons).
On my button, I want to show an icon to indicate whether the door is open or closed. This works fine when using the cover as the entity. The button has a name displayed at the top, then the icon and underneath it the timer which should either display idle or the remaining time.
I discovered on this thread that for the countdown to work, the button’s entity must be the timer and not the cover. This is fine, as I can still implement the different icons and all that (I think). The config below will show a timer/stopwatch icon – I’m not worried about that for now.
I set the button’s entity to the timer and defined a style for the state with colours for the conditions, but it doesn’t change the red countdown time back to blue when the state changes to idle and I can’t see why.
The label in the config below is just a bit of debugging and also because I tried to do this with the label before I learned that the label won’t update.
Does anybody have an idea why it’s not working as I expect?
The state part of your config should be a main config entry, not under styles.
state under styles is to apply CSS to the state field. state as a main config entry is to apply several settings based on different state of the entity declared in the button.
When I move that section, it colours the icon red but not the state (meaning the timer countdown/idle below the icon), and the icon’s colour doesn’t change (revert) when the state is idle. I must still be doing something wrong but I see the docs say that the colour change will only apply to the icon. How would one apply dynamic colours to the timer state text?
I noticed something else. When I define a minimal config for this button, I get an error in the log. I’m not sure whether this is related to my issue. I’m performing a full upgrade at the moment.
UPDATE:
I’ve upgraded to HA 0.110.5 (latest) and I’m using Button Card 3.3.5 (also latest) and I still see the error. Then I saw this was already reported above and logged as issue #337.
SOLUTION:
I’m quite happy with this. The power was in using an embedded custom button card that represents the timer. I first did it with the main card tied to the timer and then using a lot of JavaScript to get it to show state according to the cover’s status but then one needs to do more work for the actions to be tied to the cover. So, I reversed all the logic, which I think makes more sense and reads easier (but just mentioning it anyway to confirm how powerful this custom button is).
I just installed button-card using HACS in my ‘regular’ install of HA on RPi running HASSOS. Super excited about adding it to my UI! On the HACS screen, when I click on the Plugin, I can see the instructions, including the TOC. The links in the TOC don’t seem to be working. I can see the anchor reference in the URL when clicked, but (at least in Firefox on Windows), it doesn’t take me to the anchor. Also, I would have thought that this web page would be in /config/www, but it’s not there, so I assume it is in a container somewhere, relatively inaccessable. Am I missing something?
Also, is the ui-lovelace-card.yaml still a thing? I thought that went away.
The icon doesn’t get resized any longer. “size:” is ignored, and different sizes of the button don’t change anything. The icon is always displayed very small.
I had this issue last night upgrading to 0.110 and the resource for this custom button. After clearing the cache of my browser and resetting my iOS companion app’s frontend cache all custom buttons and icons were sized correctly.
Thanks David. Do you see the same behavior with the instructions as I reported? It’s not a problem the links don’t work, it just makes me think something isn’t configured correctly.
I have gate, it takes 20s to open/close. I would like to indicate this process on the frontend.
So when I press the button the icon should blink for 20 sec then change to steady on or off.
Is it possible?
I need this too. Have a button for my gate. When I press the button a switch entity toggle 1 sec impulse to one relay and the gate open or close. I have one door sensor which is show that the gate state is open or closed. Is it possible merge this two entity and this button do the opening or closing and show the gate state with color (green-open, red-closed)?