Water Tank Level and Water Volume with ESPHome

This code will get you a sensor which shows the centimeters:

  - platform: template
    name: "CM"
    id: watertank_cm
    icon: 'mdi:water-well'
    unit_of_measurement: 'cm'
    lambda: |-
        return id(watertank_voltage).state;
    update_interval: 1s #the delta filter will ensure it only sends values when something changes. 
    filters:
      - calibrate_linear:
          # Measured value of X volt maps to y cm
          - 0.464 -> 0
          - 0.994 -> 55.2
          - 1.424 -> 102.0
          - 1.818 -> 144.0
      - delta : 0.001 #only send the result if the difference with the last sent result is higher than this

This code will give you a percentage of how full your tank is:

- platform: template
    name: "usable %"
    id: watertank_percent
    icon: 'mdi:water-well'
    unit_of_measurement: '%'
    lambda: |-
        return id(watertank_cm).state / 165.0 * 100; 
      #divide by max water level height to get a percentage
    update_interval: 1s #the delta filter will ensure it only sends values when something changes. 
    filters:
      - delta : 0.001 #only send the result if the difference with the last sent result is higher than this

This code will give you the liters:

  - platform: template
    name: "usable liters"
    id: watertank_liter
    icon: 'mdi:water-well'
    unit_of_measurement: 'l'
    lambda: |-
        return id(watertank_cm).state / 100 * 3.14159265 * 1.13751599 * 1.13751599 * 1000.0;
      #height (meters) times pi times radius (meters) squared times 1000 gives liters. This works if your water tank is a cilinder shape. Otherwise you have to use different calculations.
    update_interval: 1s #the delta filter will ensure it only sends values when something changes. 
    filters:
      - delta : 0.001 #only send the result if the difference with the last sent result is higher than this
1 Like