I am not sure what I am doing wrong here:
My device tracker attributes look like this:
I configured the sensors as follows:
###########################################
# Location Sensor
###########################################
- platform: template
sensors:
audi_status:
value_template: "{{ 'Home' if is_state('device_tracker.2015_audi_rs_5', 'home') else 'Driving' }}"
###########################################
# Fuel Level
###########################################
- platform: template
sensors:
audi_gas:
friendly_name: "Fuel Level"
unit_of_measurement: "%"
value_template: >-
{%- if 'states.device_tracker.2015_audi_rs_5' %}
{{ 'states.device_tracker.2015_audi_rs_5.attributes.fuel_level' | round }}
{% else %}
{{ 'states.device_tracker.2015_audi_rs_5.attributes.fuel_level' | round }}
{%- endif %}
icon_template: mdi:gas-station
I don’t understand what I am doing wrong. Anyone see it?
treno
(travis reno)
September 2, 2017, 11:36am
2
I don’t understand what you are trying to do. It looks like you are trying to evaluate a sensor in the template window, and that’s not ever going to give you any meaningful result.
I got it to work for the location sensor and it functions, I am trying to create a sensor the fuel level. I have used this before for my batteries on my z-wave devices as well. There is something to do with the fact that it starts with a number.
It looks like you built your template around the ios battery level example on the Hass website. Try this instead to simplify it.
- platform: template
sensors:
audi_gas:
friendly_name: 'Fuel Level'
unit_of_measurement: '%'
icon_template: mdi:gas-station
entity_id: device_tracker.2015_audi_rs_5
value_template: '{{ states.device_tracker.2015_audi_rs_5.attributes.fuel_level | round(0) }}'
gregg098:
platform: template
sensors:
audi_gas:
friendly_name: ‘Fuel Level’
unit_of_measurement: ‘%’
icon_template: mdi:gas-station
entity_id: device_tracker.2015_audi_rs_5
value_template: ‘{{ states.device_tracker.2015_audi_rs_5.attributes.fuel_level | round(0) }}’
Getting there but I am getting some funkiness because the device starts with a number:
armills
September 3, 2017, 10:23pm
6
You need to change it from states.device_tracker.2015_audi_rs_5.attributes.fuel_level
to states.device_tracker['2015_audi_rs_5'].attributes.fuel_level
1 Like
bachoo786
(Bachoo786)
September 4, 2017, 2:33pm
8
Hi @pauldgifford
Can I just ask you what sensor are you using to obtain the fuel level from your vehicle and how have you linked it to HA?
Many thanks.
It’s the Automatic Sensor. I have a Pro in both my vehicles.
bachoo786
(Bachoo786)
September 4, 2017, 6:09pm
10
sorry do you mean its an automatic sensor which is built in your car?
Do you mind posting the config you use, I tried as above but keep getting errors.
After you get the automatic sensor functioning (fixed in 0.52.1), I created these:
###########################################
# Location Sensor for Vehicles
###########################################
- platform: template
sensors:
audi_status:
value_template: "{{ 'Home' if is_state('device_tracker.2015_audi_rs_5', 'home') else 'Driving' }}"
- platform: template
sensors:
f150_status:
value_template: "{{ 'Home' if is_state('device_tracker.2013_ford_f150', 'home') else 'Driving' }}"
###########################################
# GPS Information for Vehicles
###########################################
- platform: template
sensors:
audi_longitude:
friendly_name: 'Audi Longitude'
icon_template: 'mdi:crosshairs-gps'
entity_id: 'device_tracker.2015_audi_rs_5'
value_template: "{{ states.device_tracker['2015_audi_rs_5'].attributes.longitude }}"
- platform: template
sensors:
audi_latitude:
friendly_name: 'Audi Latitude'
icon_template: 'mdi:crosshairs-gps'
entity_id: 'device_tracker.2015_audi_rs_5'
value_template: "{{ states.device_tracker['2015_audi_rs_5'].attributes.latitude }}"
- platform: template
sensors:
f150_longitude:
friendly_name: 'F150 Longitude'
icon_template: 'mdi:crosshairs-gps'
entity_id: 'device_tracker.2013_ford_f150'
value_template: "{{ states.device_tracker['2013_ford_f150'].attributes.longitude }}"
- platform: template
sensors:
f150_latitude:
friendly_name: 'F150 Latitude'
icon_template: 'mdi:crosshairs-gps'
entity_id: 'device_tracker.2013_ford_f150'
value_template: "{{ states.device_tracker['2013_ford_f150'].attributes.latitude }}"
###########################################
# Fuel Level for Vehicles
###########################################
- platform: template
sensors:
audi_gas:
friendly_name: 'Fuel Level'
unit_of_measurement: '%'
icon_template: 'mdi:gas-station'
entity_id: 'device_tracker.2015_audi_rs_5'
value_template: "{{ states.device_tracker['2015_audi_rs_5'].attributes.fuel_level | round(0) }}"
- platform: template
sensors:
f150_gas:
friendly_name: 'Fuel Level'
unit_of_measurement: '%'
icon_template: 'mdi:gas-station'
entity_id: 'device_tracker.2013_ford_f150'
value_template: "{{ states.device_tracker['2013_ford_f150'].attributes.fuel_level | round(0) }}"
I had a similar issue with a template sensor for a z-wave thermostat. There is an issue with templating entity attributes for an entity that starts with a number. I found that buried deep somewhere while googling the issue I was having. The solution was exactly like armills suggested. Glad you got it working.
Putting the numbered name in brackets does not work for me. And i cannot change the name.
Is there another way to do
value_template: “{{ states.device_tracker.[‘988837433348514e30’].attributes.battery}}”
I think you need some spaces between the brackets and apostrophes. Also between battery and the brace.
Customize:
device_tracker.988837433348514e30
friendly_name: What ever you like
Remove the period after device_tracker and add a space after battery.
value_template: “{{ states.device_tracker[‘988837433348514e30’].attributes.battery }}”
@armills
How do I apply the following to one vehicle?
As is, it fire’s each time any vehicle is started.
automation:
- trigger:
- platform: event
event_type: automatic_update
event_data:
type: "ignition:on"
action:
- service: light.turn_off