Yes, thatās another option, but I didnāt want to whole line to be a clickable, thatās why I went this way. Also because it only works for 1 icon, not multiple
Struggling a bit here, because I am not yet familiar enough with JS, so please help me:
I need to truncate the last 14 characters of an entities state. In this case a variable with as its state the last triggering motion sensor. Since all of these motion sensors have āmotion_sensorā as the end of their names, I need to cut that, to be able to show only āFrontdoorā on the Button.
I have fiddled a bit, and now use a label_template to show the truncated State Could we set this in the State field somehow?
As you can see Ive also added the last_changed to the label, because show_last_changed which I use otherwise, takes up the space of the label, ā¦ but, how to format that so it says ā1 minute agoā, just like the show_last_changed does, as we can do in Jinja with relative.
fwiw, this is the variable construction automation:
You canāt as it will not update automatically in the frontend, thatās why there is a specific show_last_changed option.
Why donāt you just put the name of your motion sensor in the last_motion variable (without the timestamp in the string), and just use show_last_changed: true and show_state: true? That would be way more easy, more clean and working
Keep things simple, thatās the rule, do not try to bend things to do something they are not supposed to do
of course itās a bit difficult to see, since it falls off off the button, but the label shows the latest changed, doesnt it?
Ill experiment with that, but the start of this was I needed to truncate the entity.state, which still had āmotion_sensorā at the end of all states.
to answer this suggestion, which in itself is viable of course:
I need to have this historic view:
so need to have the timestamp in there somewhere.
yep, agree, if and when possible. Sometimes we need to get crafty though
agree, again. of course. But now I have to bend my variable for state and attributes, to fit the button ā¦
which comes close, only takes out the name of the entity:
If only we could template ( and in this case truncate) the entity.stateā¦ all would be perfectā¦
Or, maybe another workaround: have the name_template accept the so we can do:
adding to the above reasons for the feature request is this:
Ive followed your suggestion to change the variable only using the name. so the button can use State, Name and show_last_changed. Seems nice at first sight:
further testing however shows a huge deficit of this setup:
the Last motion variable doesnāt change states, when it gets retriggered by the same triggerā¦ which is also depicted on the Button. So the button wont really reflect the action in the Houseā¦
Then keep your time string in the state and remove it in a name_template and append the state to the name template. Iāll fix the <br> issue that you have, so you can use multi lines name. I forgot about this one, thatās why posting FR/Bugs in this forum is not effective, it should go over to github so that I can track them.
Ok wow. I will certainly try. Thank you so very much
Of course we needed the line brake already because of longer entity namesā¦ so hope this solution will suffice.
If not Iāll come back begging for a state template
please see if you could help me out here. Ive defined a simple button to show the state of my cpu temp. With a few icon color state templates. Iād like the border of the button to follow the icon color and set it to use the active icon color. Which I forgot is the HA default color yellow, and not the color set in the state templates. Could this somehow be set to follow that, or do I have to add a box border shadow in all state too:
Box shadow in the state with a specific color definition every time. var(--paper-item-icon-active-color) doesnāt contain a dynamic color, it comes from your theme (or the default value from HA core if you donāt hace a theme)
A trick though (didnāt try but it should work):
styles:
card:
- box-shadow: 0px 0px 2px 1px var(--local-color)
icon:
- color: var(--local-color)
state:
- operator: '<'
value: 50
styles:
card:
- '--local-color': yellow
Etc with all the other states...
yes! it does work. very nice, though I am a bit confused you set the āālocal-colorā under the card setting in the state, and it is also valid for the icon in the main configā¦still, grateful for this ātrickā which does exactly what I was after, albeit the other way round
it also works setting the color in the card config (so it pertains to name, state, label, and border)
I probably will have the name use another color, but now have the knowledge to play with all that. Cool!
You might want to add this to the Button Card documentation since it is a great tool!
asked before, but probably in a post with too many questions (sorry):
If one of the fields on a card it too long for the card, it gets the ā¦ at the button border. What it also does is move the line a few px to the right, which looks a bit shambled. Could you find a way to have the files always respect the padding settings on the left side. Have a look:
top Dorm is fine, middle one shifts the state (Corridorā¦) and bottom shifts State (and not the Name, which is also too longā¦)
on mobile this is even more visible, and the 2 lines get shifted if too long:
ps note that the āClearā is translated to Niet gedetecteerdā in Dutch, and even that looks silly. Probably need a PR to change that, or a template to have it show Clear when it is Off
we can use āāpaper-card-background-color: rgba(255, 255, 240, 0.3)ā to set opacity on background color only (opposed to the opacity: setting which sets opacity on all items of a button).
I use a lot of buttons with a background color, mostly defined by color name. It appears we canāt use the āāpaper-card-background-colorā setting with color name and opacity together?
Made me want to set the opacity in the template, and only use the background color in the button config, since that is button specific. Background-color is defined in State: mostly, since it is state dependent.
The opacity should only hit the background color, and none of the child items of the button. In this case, it would always be set, so not state dependent, hence the desire to set it in the template.
Would the be possible? If yes, please how is that best done?
thanks!
Thatās just how CSS works, nothing special related to button card worth documenting.
That doesnāt happen with me so itās probably your card styles which make this happen. If you share it Iām going to have a look.
Thatās the translation from HA core, I donāt do anything with that. And no, I will not introduce a state template.
Youāre complicating your life manā¦ --paper-card-background-color can be replaced by just background-color. Also, no you canāt use color names with opacity, that not related to --paper-card-background-color, itās how CSS works.
The only thing you could do is something like: background-color: rgba(1, 2, 3, var(--my-opacity)) in your states styles.
And set:
styles:
card:
- '--my-opacity': 0.5
In the main config part.
But I guess thatās not what you expected. Thereās no way in CSS to specify the opacity of the background outside of background-color: rgba(x, y, z, opacity)
if it is caused by my config, it would have to be the last button_body probably. I have other buttons, using a same setup albeit in 1 config and they behave likewise.
thanks for having a look!
what would be the optimal way to call/run a script on a button?
can we simply set an entity: script.to_run, or do we need to set the tap_action: call-service, service: script.to_run ?
Iām not getting any icons showing up. Has anyone run into this before? This is part of a larger config, so maybe the issue is somewhere else. If this looks right, Iāll drop the config thing in.
H all,
Sorry if it was already asked, and I missed it.
Button templates configuration is not working with iOS app?
It is working perfectly in Chrome, but the very same configuration is failing to be loaded in iOS app.
I have one more question.
Is there an option to reflect a press on a button? I mean in case when a button is executing a script and does not have on and off states, just to change for a second a then go back, to be sure that ui got my tap.
It is really missing for example on a wall tablet when something supposed to happen in another room.
Would be nice.