I have a number, quite a lot, of value_template sensors, showing the average brightness of the light in a lightgroup. I use the template value in lovelace cards indicating the level of light in a room. Give a good overview of all light in all rooms in the house on a very small space
It all works perfectly, however I would like to clean up my logs In a community of technical people, I think this is a valueable desire:-)
The template working is like this
kokkenlightgroup_brightness:
value_template: "{{ states.light.kokkenlightgroup.attributes.brightness | float }}"
It works perfectly, however shows in the logs as “unavailable” everytime a lightgroup is turned off. I would like the template to only “render” the value when there is an actual value in the brightness attribute, otherwise put in 0 as the brightness value in my template
I have tried a number of different templates setups with no luck. The below is still returning the brightness value when lights are on, however is not returning 0 when the lights are off (state is unavailiable). The value_template still ends as unavailable
sovevaerelselightgroup_brightness:
value_template: >
{%- if is_state ('states.light.sovevaerelselightgroup.attributes.brightness', 'unavailable') -%}
0
{%- else -%}
{{(states.light.sovevaerelselightgroup.attributes.brightness | float)}}
{%- endif -%}
I can not figure out what Im doing wrong. Anyone with good YAML skills. Probably simple.