Is it possible to set an entity name as an var and use it in template. I got an card it already partially templated but want to move the rest over to the template side, because all the setting is the same with the exception of entity name.
############## Picture Element Main Light Entities ##############
- type: "custom:button-card"
entity: light.hall_way_walkway
template: light_element_button
style:
left: 54.5%
top: 33%
######### want to move this section into template #########
entity_picture: |
[[[
if (states['light.hall_way_walkway'].state == 'off')
return "/local/photos/lovelace_photos/general/recessed_light_off.png";
return "/local/photos/lovelace_photos/general/recessed_light_on.png";
]]]
custom_fields:
light_bri: |
[[[
var bri = states['light.hall_way_walkway'].attributes.brightness;
if (bri > 0)
return Math.floor(bri/255 * 100) + '%';
return
]]]
######### want to move this section into template #########
Hello
Do you know how can I achieve circular brightness indicator like implemented in homekit card?
I’m going to migrate from hk to button card, but I like this “circles”.
Author of hk card mentions he got idea from other source, but link he provided directs to an image.
epic… thank you!
What does the syntax starting with & in your code?
it works for me without &info_light and &circle_pos. once entered and saved, after reopen those “things” disappeared being converted to:
@Mariusthvdb Nice, I have been looking for good examples of YAML Anchors!! Is there a way to use YAML Anchors to set a couple Styles that I can recall other places? I reuse style configs constantly and making even a small change means I need to update tons of different places…
Do it exactly like I did above, create the anchor on the fly using the & and inject it using the *
Of course , button-card has the templates possibility which is even better… you can use them globally in your config ( on button cards), while anchors can only be used in the specific file you create them
I don’t suppose you had a chance to have a look any further did you? I spotted when trying this that the event handler was attached but the code in the handler never seemed to fire.
Apologies if this has been covered in the past, I’ve had a good search but can’t quite seem to find the answer!
I’m trying to change and icon colour based on the state of 2 other entity attributes. I have it working with either but I’m trying to use a form of AND condition. Is this possible? Apologies I don’t have the exact code to sent here at the moment but in short looking to show the following.
media_player.lounge.attribute.volume_level is > 2
AND
media_player.kitchen.attribute.volume_level is > 2
return icon colour red otherwise return grey.
I know you can do this with templates but is it possible to do directly in the custom button coding? I understand the styling/icon colours/values. Any help much appreciated.
Hi everyone
I’m trying to learn how to configure the custom card. My setup is by using the grid, and four buttons.
The question at hand is how I add data for icon and text size…
I think you need to post the full button config (including all the nested custom fields).
Is the custom field itself a button card? Does the inner button card have an entity ID set?
Even so, I think from what I’ve tried before that the answer is no (even if the inner card has no entity set.
It’s not specified how the inheritance works for variables but you could experiment with that. You could define e.g. my_entity and set the parent card’s entity from that and if it works, reference it also in the inner card. Just an untested idea.