Ok, thanks first.Itried to adjust your code to my needs, but, and maybe because as i said i am not good in this, i cannot see the number of lights that are ‘on’. My button card displays only the icon but not that number as i would like to have.
This is the actual code:
- type: custom:button-card
color: auto
# name: Luci Casa
entity: group.luci
icon: mdi:lightbulb
label: >
[[[
function flatten(entity_id, result=[], searched=[]) {
var state = states[entity_id];
if (state) {
var entities = state.attributes.entity_id;
if (entities) {
searched.push(entity_id);
entities.forEach(entity_id => {
if (!result.includes(entity_id) && !searched.includes(entity_id))
flatten(entity_id, result, searched);
});
}
else
result.push(entity_id);
}
}
var light_ids = [];
flatten(entity.entity_id, light_ids);
var count = 0;
light_ids.forEach(entity_id => {
var state = states[entity_id];
if (state && state.state === 'on')
count++;
});
]]]
styles:
card:
- font-size: 12px
- font-weight: bold
icon:
- color: >
[[[
if (states['group.luci'].state == 'on')
return "green";
return "red";
]]]
really sorry, but I cant see anything in that black blob.
please allow us to help you…
tbh, I am somewhat surprised after all these years you still dont have a javascript template working somewhere? this cant be the first time you do this
btw the group apparently is off, (red) ?
also, you are Not returning anything at the end of the template. you should at least use return count;
Yes, you are right… not all can understand things in a non native language and i am one of them… i’ll try to improve my things about this aspect… I am medical doctor so very far away from computer language…
Yes, but nothing change when lights are on…
As i said i completely copied that template… my ignorance…
Now i put your template in notification place, but nothing changed.