Use yaml anchors for this template sensor?

HI,

having 11 of these sensors:

frontdoor_motion_sensor_lux:
  friendly_name_template: >
    Frontdoor: 
    {% set lux = state_attr('sensor.frontdoor_motion_sensor','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: >
    {{state_attr('sensor.frontdoor_motion_sensor','lx')}}

I ws wondering if I could use the anchor method for the bit after the first line of the friendly_name template:

frontdoor_motion_sensor_lux:
  friendly_name_template: >
    Frontdoor: 
    {% set lux = state_attr('sensor.frontdoor_motion_sensor','lx') %}
    
#make this an anchor , and insert it in all templates
{% 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: >
    {{state_attr('sensor.frontdoor_motion_sensor','lx')}}

i am a bit confused by the foor and bar explanation https://blog.daemonl.com/2016/02/yaml.html and how I should name the anchor and insert it again…

I just stumbled upon your post because I was looking for yaml “anchors”. This article appears together with yours, maybe it helps. I believe that you can realize what you’re looking for by using the “node anchors and merge key texts” procedure: Howto create battery alert without creating a template for every device

thank you. I am aware of that thread, but havent been able to distill the correct way to use those anchors.
Would you know how to do it correctly given my sensor posted above?

This is the explanation that finally made YAML anchors click for me.

http://www.thomasloven.com/blog/2018/08/YAML-For-Nonprogrammers/

yes, familiar with that one. The author has replied it won’t be possible though… Thanks anyways