Convert number value for gauge

Hi All,

I have connected my car to HA but it reports its efficiency as Wh/km, but I would like to convert to Miles/kwh. I know the maths (1/(SENSOR/1000))/1.6 but I haven’t been able to find how/where I can do the conversion.

I did try to search for converting C to F to see if I could find out something similar and use as a template, but I didn’t understand where to put the template(?) code and didn’t want to resurrect a really old thread.

Sorry for being an idiot :cry:

Here’s an example of how I combined a few sensors and set maxes and mins. You probably want to do something similar:

- sensor:
  - name: "FTX Supply Delta T"
    unique_id: ftx_supply_delta_t
    state: >
      {{ [[-30, (states('sensor.ftx_supply_temperature')|float(0.0) - states('sensor.ftx_outdoor_temperature')|float(0.0))|round(1)]|max,30]|min }}
    unit_of_measurement: "°C"
    device_class: temperature
    state_class: measurement

This is a file that is included from configuration.yaml under “template:”
You can see an even better example of as the first example here: Template - Home Assistant

1 Like

Thanks for the pointers!

I managed to get it working after a small tripup in that the sensor I was pulling from seemed to give the number in a string and not an int. So as soon as I tried to do any maths on it (like the divides above) it threw an error. Wrapped the (states('sensor....')) in an int() and works like a charm, many thanks!!

Would you mind sharing the code for this?