I have successfully set up the HACS / Tesla integration, but the distance units are not as I would like, ie kilometres instead of miles.
My HA Settings / General / Unit System is set to “Celcius, kilograms, metric” as this is what I use for temperatures etc, but how can I force the Tesla integration to show range in miles etc? My car is set to miles, not km.
This code works, but the result has lots of decimal places (that I don’t want).
### Tesla HACS change from km to miles.
- sensor:
- name: Tesla range
unit_of_measurement: "mi"
state: "{{ float(states( 'sensor.baloo_range' ),0) * 0.621371 | }}"
unique_id: tesla_range
So I tried the following, but it didn’t work. What would be the best way to have no decimal places?
### Tesla HACS change from km to miles.
- sensor:
- name: Tesla range
unit_of_measurement: "mi"
state: "{{ float(states( 'sensor.baloo_range' ),0) * 0.621371 | round(0) }}"
unique_id: tesla_range
Neither did this…
state: "{{ float(states( 'sensor.baloo_range' ),0) * 0.621371 | int }}"
for no decimal, giving 191 {{ int(float(states( 'sensor.baloo_range' ),0) * 0.621371) }}
EDIT you can add the icon as well,
### Tesla HACS change from km to miles.
- sensor:
- name: Tesla range
unit_of_measurement: "mi"
state: "{{ int(float(states( 'sensor.baloo_range' ),0) * 62.1371) / 100 }}"
unique_id: tesla_range
icon: mdi:gauge