Converting mm to %

Hi all!

I have a Mopeka Pro Ultrasonic gas bottle sensor. Which measures how much gas is left in the bottle. In the Mopeka App I have a % but the HA intergration only gives me the measurement in mm.

sensor.front_bottle_tank_level
gas bottle maximum level: 900mm

And yes, I’m new to this templating etc.

Any assistance on how I can do this would be much appreciated. as always.

Add this to a template sensor state and give it a % unit of measurement:

{{ ((states('sensor.front_bottle_tank_level') | float(0) / 900 ) *100) | round(0) }}

You can select your device and the sensor will appear in the device listing

The other option is the compensation sensor:

#configuration.yaml

compensation:
  tank_level_pct:
    unique_id: tank_level_pct
    source: sensor.front_bottle_tank_level
    unit_of_measurement: "%"
    lower_limit: true
    upper_limit: true
    data_points:
      - [0, 0]
      - [900, 100]
1 Like