Help with template state calculation - gas/propane bottle weight as a percentage

Hi There, I started this project off a couple of months ago testing with a 10kg weight (10kg is 100% full, 0kg is 0% full) and had it all in my head, now coming back to this with a real gas bottle I need a bit of assistance to get the right calculation… in other words my head is going WTF :smiley:

Full Gas Bottle: 80kg
Empty Gas Bottle: 35kg

rockgas_bottle_1_weight is currently reporting 53kg. Now I need help with rockgas_bottle_1_level please. How do I set 80kg is 100% full and 35kg (or less) is 0%?

  - sensor:
    - name: "Rockgas Bottle 1 Weight"
      unique_id: rockgas_bottle_1_weight
      unit_of_measurement: "g"
      device_class: weight
      state: >
        {{ states('sensor.tasmota_hx711_weightraw') | float - 927 }}
    - name: "Rockgas Bottle 1 Level"
      unique_id: rockgas_bottle_1_level
      unit_of_measurement: "%"
      state: >
        {{ ([(states('sensor.tasmota_hx711_weightraw') | float - 927) / 10000 * 100, 100]|sort)[0] }}

I’ll start off by spelling it out a bit so you can see what I’m doing.

{% set weight = 53 %}
{% set full_weight = 80 %}
{% set empty_weight = 35 %}
{{ [(( weight - empty_weight) / (full_weight - empty_weight)),0] | max  }}

then using your values:

{{ [((states('sensor.rockgas_bottle_1_weight') | float - 35) / 45),0] | max  }}

Thank you heaps for the quick reply and very helpful!. At first it was not working, but sensor.rockgas_bottle_1_weight is in grams, and I have changed the entity in the gui to display in kgs! So just needed to add “* 100” to it! Perfect and it works:

{{ [(((states('sensor.rockgas_bottle_1_weight') | float - 35) / 45) * 100),0] | max  }}

tada!

1 Like

How are you weighing the bottle?

See here: Home Assistant - New Zealand - #46 by Greminn