State_attr() always returns None

Hello,

I have the fordpass integration installed.
This integration provides the entity “sensor.fordpass_fuel”.
This entity has an attribute “DistanceToEmpty”.

The idea is, that rhasspy can tell me, how many kilometers are left in my tank.
The problem is, i can’t access this attribute.

I used this manual:

and this code:

service: mqtt.publish
data:
  topic: test/test
  payload: "\"{{ state_attr('sensor.fordpass_fuel','DistanceToEmpty') }}\""

When i run the code, the payload is always “None”.
I also tried different entitys with attributes, but it always says “None”.

next try was to create a template-sensor in the configuration.yaml:

sensor:
  - platform: template
    sensors:
      ford_range:
        friendly_name: Ford range
        value_template: "{{ sensor.fordpass_fuel.attributes.DistanceToEmpty }}"

i reloaded my configuration, but the new sensor was not displayed anywhere.

Does someone knows a good way to access attributes?

You most likely have the wrong entity_id or attribute in your template. Double check it in the developer tools → states page.

I found it.
On the dashboard the Attribute is displayed as “DistanceToEmpty”.
On the “state page” the attribute is “distanceToEmpty”

Thank you!