Inside the javascript code, you'll have access to those variables:
* entity: The current entity object, if the entity is defined in the card
* states: An object with all the states of all the entities (equivalent to hass.states)
* user: The user object (equivalent to hass.user)
* hass: The complete hass object
So you can access the entity state with entity.state
Define your config template in the main lovelace configuration and then use it in your button-card.
thought you implied that to be needed in the ui-lovelace.yaml… I take it now you mean the main setup for the card itself? Which would be perfect, thanks!
seeking some more help please. I am trying to get a shallower but wider button to show Icon and label next to each other, centered on the button.
Just like this:
I’ve reached this:
but am lost for now which of the possible options I should change, would you please have a look? (to be precise: I want the icon, name and state centered in horizontal and vertical center…
btw for now Ive ‘guessed’ the width of the top button to be 3 times a single button with something extra, but what would be the precise way of calculating that? Which variable is defining the space between buttons?
i wish that when states[‘sensor.riscoincendio’].state; is iqual to value A then the card is RED. when value is B is green. when Value is C is yellow…and other values
how can i do this?
I understand.
I thought these anchors could only be used in the file they are declared in. Since I try to use my views with !includes this would be in a button_lights.yaml file, and only configuring sets of Lights buttons…
No issues with switches… Might have to think it over, because I am not sure I need the brightness on all buttons, especially the count buttons. Unless there would be an override setting, or maybe use the same trick with the transparent color
no way to override, just make an anchor for count buttons and an anchor for light % buttons. That’s all I do. Still cuts the config down. And next version will have this templating crap so you can just use a template instead of an anchor. I’d guess that templates can merge better than anchors because you won’t get that double config attribute error in your logs with templates. Is that correct to assume @RomRider?
using layout: icon_name_state, what else do I need to set to have these centered vertically and horizontally?
in Lovelace: Button card posted few posts above, I’ve shared my config, and probably should leave out some extra settings I copied from the other buttons. Sofar, I find it rather difficult to accomplish such a simple goal… duh. what am I not seeing…
only thing left is the vertical positioning to the center…
even after heightening the button somewhat, vertical centration wont work…
btw @petro, thanks for your fine counter template! was looking for that. I can confirm you dont need to hardcode the group name there either, and use:
label_template: >
var i;
var entities = entity.attributes.entity_id;
var count = 0;
for (i = 0; i < entities.length; i++) {
var state = states[entities[i]].state;
if (state === 'on') {
count += 1;
}
}
return count.toString() + ' of ' + entities.length.toString();