Same, your indentation is off. After a |, >, >-, … All the next lines needs to be indented by 2 spaces in yaml (see how the syntax highlighting is different from your post)
Ok, I’m not sure how you are getting that bad indentation. It actually is indented 2 spaces. When I look at what I posted right above your reply, the syntax highlighting looks correct and the indenting is correct also. Here it is again copied directly from my editor:
All right. I get it now. I was indenting 2 spaces from the ‘-’, not from box-shadow. That fixed it. Thank you so much. I’ve been using yaml a lot this past year mostly with Ansible, but it still tricks me sometimes.
Thanks so much, i didnt know you could add the template option to an existing template. This makes things a lot easier to manage going forward. I really appreciate your help.
The complete card config will help. The text is there but it’s not displayed because outside of the button. I supposed you’ve not properly set the grid styles/element style.
if you defined custom elements in your button you have to place them in the grid, else the result will be random (what you see):
You’ll have to modify those values mainly:
- grid-template-areas: '"i n ." "i n s" "i n l"'
- grid-template-columns: 20% 30% 1fr
- grid-template-rows: min-content min-content min-content
I think people just don’t understand the grid-template-areas when it’s a single line. People should read this and it will instantly click. at least it did for me way back when.
Ohh I see, i thought that the custom fields was displayed ontop of the grid since I can position the icons from absolute position regardless of the grid. I will give it a try. Thanks for the explanation.
I want to use a templated name. I want to show the relative time since last changed of a state (if on) and a text (if off). I’m trying this, but its not working (sorry, not expert of javascript):
color_type: icon
name: |
[[[
if (switch.gosund2_switch.state = 'on') { return "Pumpe an seit " + relative_time(states.switch.gosund2_switch.last_changed) } else { return "Pumpe aus" };
]]]
template: button-card-headers
type: 'custom:button-card'
Nor am I and I’m only responding as I saw this immedialtly after you posted it and if it helps, good. If not sorry for wasting your time.
So, I don’t think you need the curly brackets and there might be one too few semi-colons…
Try this (reformatted to the way I recognise - like I said I’m no Javascript expert),
if (switch.gosund2_switch.state = 'on')
return "Pumpe an seit " + relative_time(states.switch.gosund2_switch.last_changed);
else return "Pumpe aus";
Ok, I’m drawn in to help on a subject I’m ill-equiped to help with
Try this:
var state = states['switch.gosund2_switch'].state;
if (state == 'on')
return "Pumpe an seit " + states['switch.gosund2_switch'].last_changed;
else return "Pumpe aus";
Note the == instead of =
I took out relative_time as I have no idea if it is valid Javascript and if not what the equivalent would be.
I have found the w3schools good as a starting point to look things up.
Ok buddy, yes this is coding the trick. At the same time I found out this is also doing magic:
name: |
[[[
if (states['switch.gosund2_switch'].state === 'on') { return "Pumpe an seit " + states['relative_time(states.switch.gosund2_switch.last_changed)'] } else { return "Pumpe aus" };
]]]
Only the relative_time is the problem now. Your code is showing me the whole date (2020 - 04 - 16 with time) … I want just to show the minutes. Just for understanding: I have a pump and want to show how long it is running in minutes …