Teslamate integration km to miles

I have followed the teslmate official documentation (HomeAssistant Integration | TeslaMate) to get data to homeassistant via mqtt.
The unit of measurements are in km, how to get the value in miles.
If I change the unit in the mqtt_sensors.yaml, although the unit changes, the values are still in km.
Any help is much appreciated.

You could create another template sensor and convert from km to miles. the conversion is 1km = 0.6213712 mile

  - sensor:
    - name: "teslamate_miles"
      unique_id: "teslamate_miles"
      state: >
        {% set km = states('sensor.teslamate_km') | float(0) %}
        {{ km * 0.6213712 }}
1 Like

You can change the unit in the UI. The sensor will remain in km but display in miles.

1 Like

How to do this please

Click on the entity wherever you can see it — dashboard, under Devices, doesn’t matter.

Then click the cog icon and change the Unit of measurement setting.

Not all entities have this option. If yours doesn’t, we’ll need to set up a template sensor as above, although you can do that in the UI under Helpers. Use a state template of:

{{ states('sensor.teslamate_km')|float(0) * 0.621 }}
1 Like

Can I ask another issue I’m facing.
Teslamate data was updated in ha only once.
In the mqtt log, I can see that Teslamate connects to ha, but no data gets updated. Other than that in the log there are multiple entries like this

2024-05-16 22:35:48: New connection from on port 1883.
2024-05-16 22:35:48: Client closed its connection.