Value Template, get attributes for new entity does not work

Hi,

and thanks for reading.
I want to “convert” the attributes of one entity to a new entity state, but I can’t see what is wrong in my configuration.yaml.

The attributes of the first entity are (first two lines are UUIDs and distance of BLE devices):

6409fd76-1930-451c-aeec-5053285716a3: 3.95
93cec8c3-49ae-4475-8ef1-0994faf71cc5: 15.88
icon: mdi:bluetooth
friendly_name: Pixel 6 Beacon Monitor

So I can use following “platform:template” in the cofig.yaml to get the “friendly_name” as state of the new entity “Pixel - Beacon 01”

# BLE - Indoor Position
# Andre
      pixel_beacon_01:
        friendly_name: Pixel - Beacon 01
        entity_id:
          - sensor.pixel_6_beacon_monitor
        value_template: '{{ states.sensor.pixel_6_beacon_monitor.attributes.friendly_name }}'

This works great, but if I change the last line of the code to the UUID of one of the BLE devices

value_template: '{{ states.sensor.pixel_6_beacon_monitor.attributes.6409fd76-1930-451c-aeec-5053285716a3 }}'

I get the error “bad indentation of a mapping entry (279:41)”

What am I missing?

value_template: "{{ state_attr('sensor.pixel_6_beacon_monitor', '6409fd76-1930-451c-aeec-5053285716a3') }}"

As a general rule (it’s mentioned in the documentation), avoid using direct referencing like this:

{{ states.sensor.whatever.attributes.something }}

and use the state_attr() function like this

{{ state_attr('sensor.whatever', 'something') }}

What caused the problem you encountered is due to the use of direct referencing and the attribute’s name begins with a number instead of a letter. There’s a note in the documentation about how to handle it but it’s avoided by simply using state_attr().

1 Like

Thank you! I tried this, but missed to close some brackets.

Sorry, for “wasting” your time!