Hi, I am trying to display some data from a sensor I have (BMW) in my panels, I want to display some attribute values in the panel, as well as convert some of them into UK miles.
I have tried to follow the various bits of information to no luck, I someone could point me in the right direction I would really appreciate it.
The sensor name is:
binary_sensor.420d_condition_based_services
It has a state of:
on or off
The attributes are:
brake fluid date: 2020-07-01
brake fluid status: OK
car: 420d
oil date: 2019-07-01
oil distance: 6000 km
oil status: OK
vehicle check date: 2021-07-01
vehicle check distance: 37000 km
vehicle check status: OK
vehicle tuv date: 2020-07-01
vehicle tuv status: OK
friendly_name: Service Status Data
device_class: problem
icon: mdi:door
I want to display the attribute oil distance for example, but in miles (e.g value in KM divided by 1.609, then round to just whole number such as 4566)
If someone could point me in the right direction I am struggling to work out how to add this into my configuration.yaml file and what dependencies it has etc.
Hi thanks for that, it certainly moves me along a bit more. It shows as 0.0 in the sensor, but I think thats because the value of the attribute is 6000 km.
The km bit is going to stop it from being divided (I proved this by removing the maths part and it displays 6000km).
Any ideas how I can just retrieve the numerical value of that attribute?
Youâre welcome! Now please check one of the âthis solves my problemâ check boxes so this topic is marked solved. That way when others come along they know you donât need help with this anymore.
No problem. I just mention it because a lot of people that ask for help donât seem to do it or are not aware that they should. Helps to streamline things.
Certainly. Iâve seen several posts along those lines. Just start a new topic and good luck!
Guys - Hate to resurrect an old thread but Iâm struggling to convert km to miles, I had the following config:
# Addded to convert km to Mi
- platform: template
sensors:
fuel_range:
friendly_name: Fuel Range
unit_of_measurement: mi
value_template: >
{{ (state_attr('sensor.m140i_remaining_range_fuel').replace('km','')|float/1.609) }}
In your example, the state_attr function is assigned only one parameter, namely an entity_id called sensor.m140i_remaining_range_fuel. You need to also supply the name of one of this entityâs attributes.
If your goal was to use the entityâs state, and not one of its attributes, then you should use the states function (it uses one parameter: entity_id).
Thanks for the response - Thats not working for me unfortunately. Iâm trying to convert the value from km to mi and display the new value in a sensor panel, out of the box it displays km and working, but with
Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected ')') for dictionary value @ data['sensors']['fuel_range']['value_template']. Got "{{ states('sensor.m140i_remaining_range_fuel').replace('km','')|float/1.609) }}\n". (See ?, line ?).