HI,
Have 20 or so sensors like this:
control_room_motion_sensor_lux:
friendly_name_template: >
Control room:
{% set lux = states.sensor.control_room_motion_sensor.attributes.lx %}
{%- if lux <=1 %}
moonlight
{%- elif lux <=2 %}
night light
{%- elif lux <= 10 %}
dimmed light
{%- elif lux <= 50 %}
‘Cosy’ living room
{%- elif lux <= 150 %}
‘Normal’ non-task light
{%- elif lux <= 350 %}
working / reading
{%- elif lux <= 700 %}
inside daylight
{%- elif lux <= 2000 %}
maximum to avoid glare
{%- elif lux <= 10000 %}
clear daylight
{%- elif lux <= 120000 %}
direct sunlight
{%- else %}
Too bright
{%- endif %}
value_template: >
{{states.sensor.control_room_motion_sensor.attributes.lx}}
how can i lift this rather large template out of each individual sensor and compress the yaml file considerably?
would be cool if something like:
friendly_name_template:
{% set lux = states.sensor.control_room_motion_sensor.attributes.lx %}
{{ luxtemplate(lux) }}
would be possible for each sensor where luxtemplate would be defined globally as
{% set luxtemplate(lux) =
{%- if lux <=1 %}
moonlight
{%- elif lux <=2 %}
night light
{%- elif lux <= 10 %}
dimmed light
{%- elif lux <= 50 %}
‘Cosy’ living room
{%- elif lux <= 150 %}
‘Normal’ non-task light
{%- elif lux <= 350 %}
working / reading
{%- elif lux <= 700 %}
inside daylight
{%- elif lux <= 2000 %}
maximum to avoid glare
{%- elif lux <= 10000 %}
clear daylight
{%- elif lux <= 120000 %}
direct sunlight
{%- else %}
Too bright
{%- endif %} %}
could be set just once…
if at all possible maybe even go one step further, and changing the sensor name through a template also, since im rather meticulous on that subject, might be an option.
in this sensor control_room is used 4 time, 3 times as such once as Control room…
can this be done:
{% set name = Control room %}
and then create the sensor using
sensor. {{name | replace(’ ‘, ‘’_)|lower() }}motion_sensor_lux:
friendly_name_template: >
{{name}}:
{% set lux ={{states.sensor.{{name | replace(’ ', '’)|lower() }}motion_sensor.attributes.lx}} %}
{{ luxtemplate(lux) }}
value_template: >
{{states.sensor.{{name | replace(’ ', '’)|lower() }}_motion_sensor.attributes.lx}}
of course there’s issue with templates in templates ?