Again yet another cm to liter transformation - Water Tank Level

Hi there,

i hope you are all fine.

I need to seek some help here again as i am little lost again.
As the topic allready says its again yet another cm to liter transformation.
I just don*t get it.
Normaly i would say its easy and there are enough examples out there but my brain just cant connect them together to a working solution.

What i found is this, which should fit perfect my need as this is the exact same combination i have, only the tank size is different and a cube (ibc container)

So the relevenat part, and where i have to make changes are here:

     # The actual distance sensor
     - platform: ultrasonic
       trigger_pin: D1
       echo_pin: D2
       name: garden_watertank_distance
       update_interval: 600s
       pulse_time: 50us
        - filter_out: nan
        - median:
           window_size: 7
           send_every: 4
           send_first_at: 3
                - calibrate_linear:
                   - 0.23 -> 1.86
                   - 2.41 -> 0.0
         - sensor.template.publish:
            id: garden_watertank_liter
            state: !lambda 'return x * 3141.592653589793238;'
         - sensor.template.publish:
            id: garden_watertank_percent
            state: !lambda 'return x * 53.979255216319471;'		


          - calibrate_linear:
             - 0.23 -> 1.86
             - 2.41 -> 0.0

I am not quite sure how to handle this, my numbers are:

100% Full, distance to water is 20cm
000% Empty, distance to Water/Ground is 170cm

So i have 150cm of possible water level.
The tank does have a possible volume of 1000 Liter

If its is 50% the sensor will get around 85cm distance wich equals to 500 Liter

How do i need to configure the linear numbers ?
Also i am not sure how to handle the !lambda numbers.

Any help would be much appreciated.
If someone does have an easier solution i would be happy with this too.
Dienst matter if % or liter in the end.

Thanks in advance

Is the tank regular? I.e. does it get narrower or wider?

In short I think you need

  - 20 -> 1000.0
  - 170 -> 0.0
1 Like


thanks for reply, i will try the new numbers this evening as i am not home right now.

And the tank ist just a square just a normal small ibc container

You can have a look around here too for a similar example and “copy sensor” based approach.

Copy sensors can be handy if you want a few derived/processed variants of a sensor (progressively add more filters).

Scroll down…

My mistake, I should have googled IBC container, and seen the word cube. If I get a moment I’ll post another way to work it out, but the calibrate_linear should work, given that the formula will be linear foot a cube.


i had some trouble with the sensor, but now after resoder etc it does work fine again.

The Link you provided seems a little bit over enginerred for my case and also i du not really know whre need to change the numbers as this is quite complex :frowning:

And no sorry for not knowing what a ibc tank is, i though its something almost erveryone knows :smiley:

What i found in the meanthime is the following link:

Espaciallay this part:

  - platform: ultrasonic
    trigger_pin: D1
    echo_pin: D2
    name: "Tank Level Sensor"
    unit_of_measurement: "L"
    device_class: volume_storage
    icon: "mdi:water"
    accuracy_decimals: 0
    update_interval: 1s
      - median:
         window_size: 59
         send_every: 60
         send_first_at: 3
      - lambda: return (1-x) * 1000.0 - 55;
      - filter_out: nan

This works fine for me, but nit really accurate as i am not sure where to tell the system the min and max value of the sensor, so when it is full/empty

Right now the result ist around 724 Liters, but thats not accurate.

Where do i need to tell the system thos values ?