Value Template Help

Trying to get the fuel of my truck in as a state so I can announce it as part of my morning office script. Other value_templates working fine…is it because the name of the entity has a number?

Error -

Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: expected token ‘end of print statement’, got ‘_ford_f150’) for dictionary value @ data[‘sensors’][‘f150_fuel_level’][‘value_template’]. Got ‘{{ states.device_tracker.2017_ford_f150.attributes.fuel_level | float | round(1) }}’. (See ?, line ?).

Config of reference:
f150_fuel_level:
value_template: ‘{{ states.device_tracker.2017_ford_f150.attributes.fuel_level | float | round(1) }}’

it’s becuase your entity id starts with a number. change the name of your device tracker to anything other than starting with a number. How about ford_f150_2017 for example?

in the mean time you could also use:

{{ state_attr(‘device_tracker.2017_ford_f150’, ‘fuel_level’) | float | round(1) }}

@petro is correct on both counts. But, for completeness, the following should also work:

value_template: "{{ states.device_tracker['2017_ford_f150'].attributes.fuel_level | float | round(1) }}"
1 Like

How do I change the name? I can set the friendly name via the known_devices but looks like it is set for the actual device name. It is pulled from Automatic Component. THanks for the help.

ya so none of that worked…I guess I need to figure out how to change the entity name to not have it start with a number. Any ideas?

As far as I can tell by browsing through the Automatic code is it uses the “Vehicle ID” from Automatic. I think you need to change the ID there.

If you look through home-assistant.log you should see an event named ‘automatic_update’. In the details of that event you’ll probably see 2017_ford_f150. That’s just being used as is, so you have to change it at the source.