you’ve been at it while Ive been away thanks!
and no, I haven’t tried that yet, though I did try to understand the code, and especially this on friendly_names.
Thats why I was confused friendly_name
not to be mentioned in the documentation. Given the fact it is such a system wide default configuration variable, it does feel awkward we should now configure it under the manually added attributes (templates), and not have it as a default option perse. (hence my FR…)
Please let me ask if I overlooked another possible feature, namely the much anticipated template variables? It would be so great if we could set a variable, to be used in all following templates of the same sensor. Or maybe even better, use the state of the main state in all other templates, as a config entity.
It would shorten Add (bring back) friendly_name to template sensors - #8 by petro Petro’s template dramatically.
that would allow me to do what I have been trying for a very long time now, in the friendly_name_template:
(declare once in an anchor, and insert that anchor in the other 22):
corridor_terrace_sensor_light_level_raw:
value_template: >
{{state_attr('sensor.corridor_terrace_sensor_light_level','lightlevel')}}
# friendly_name_template: >
# Corridor terrace:
# {% set light_level = state_attr('sensor.corridor_terrace_sensor_light_level','lightlevel')|int %}
# {% if light_level < 1 %} dark
# {% elif light_level < 3000 %} bright moonlight
# {% elif light_level < 10000 %} night light
# {% elif light_level < 17000 %} dimmed light
# {% elif light_level < 22000 %} 'cosy' living room
# {% elif light_level < 25500 %} 'normal' non-task light
# {% elif light_level < 28500 %} working / reading
# {% elif light_level < 33000 %} inside daylight
# {% elif light_level < 40000 %} maximum to avoid glare
# {% elif light_level < 51000 %} clear daylight
# {% else %} direct sunlight
# {% endif %}
Because the above needs to be repeated for all (23) sensors individually with the legacy format, I do it in a customization:
friendly_name: >
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
}
var id = entity.entity_id.split('.')[1].split('_sensor_light_level_raw')[0].replace(/_/g,' ');
var id = capitalizeFirstLetter(id);
if (state < 1) return id + ': dark';
if (state < 3000 ) return id + ': bright moonlight';
if (state < 10000) return id + ': night light';
if (state < 17000) return id + ': dimmed light';
if (state < 22000) return id + ': \'cosy\' living room';
if (state < 25500 ) return id + ': \'normal\' non-task light';
if (state < 28500) return id + ': working / reading';
if (state < 33000) return id + ': inside daylight';
if (state < 40000) return id + ': maximum to avoid glare';
if (state < 51000) return id + ': clear daylight';
return id + ': direct sunlight';
which would be the anchor if the template variables would be available.
now back to your findings above which I havent studied completely yet.