need some js help pleaseā¦
id like to show something like this:
state_display: >
[[[ var fakestate = `<span style="color: var(--active-color);"> ${entity.state}:</span>`;
var id = entity.entity_id.split('.')[1];
var fakelabel = `<span style="color: var(--active-color);"> ${Math.round(entity.attributes.brightness/2.55)} % - ${states['sensor.' + id + '_power'].state} W</span>`;
return (entity.state == 'on') ? fakestate +' ' + fakelabel : null; ]]]
but only show the wattage provided a sensor.id_power is available. iow the fakelabel is either
var fakelabel = `<span style="color: var(--active-color);"> ${Math.round(entity.attributes.brightness/2.55)} % - ${states['sensor.' + id + '_power'].state} W</span>`;
or when the sensor_power isnt available:
var fakelabel = `<span style="color: var(--active-color);"> ${Math.round(entity.attributes.brightness/2.55)} % </span>`;
what would be the best way to accomplish that? please have a look? thanks!
thought not yet perfect, this is getting close (decided to take out the brightness in the fake state, as I have that already in the notification circle:
state_display: >
[[[ var fakestate = `<span style="color: var(--active-color);"> ${entity.state}:</span>`;
var id = entity.entity_id.split('.')[1];
var power = states['sensor.' + id + '_power'];
var bri = Math.round(entity.attributes.brightness/2.55)
var content = power? power.state + ' W': null;
var fakelabel = `<span style="color: var(--active-color);"> ${content} </span>`;
return fakestate +' ' + fakelabel; ]]]
@romrider, pardon my direct question please, but isnt there another way to do that (I know I can enter a hardcoded sensor I have for all light power sensors summed, but that would update all fields on any power changeā¦ also, I could do:
- type: custom:button-card
template: button_light
entity: light.kist
triggers_update: sensor.kist_power
but that would still require me to hard code that for all buttons.
I will if I must of course, but looking for a more elegant way first