Skip to content
Stand with Ukraine flag

Tank Fill Percentage from Depth Sensor

  • Calculated Field
  • 319 installs
  • v1.0.0
  • Jun 15, 2026
  • MIT license
  • v4.2+

Compute tank fill percentage from a depth sensor with per-device height calibration — for fuel tanks, water tanks, chemical storage, and any gauge with per-unit calibration.

Type
  • Simple
Category
  • Custom Formula
Use Cases
  • Tank Level Monitoring
  • Industrial Automation
  • Smart Farming

Who it’s for

Fleet managers, facility operators, water-utility teams, and any team running differently-sized tanks — when each tank needs its own height calibration but the dashboard still needs a consistent percentage formula.

What it does

Reads the live depth telemetry from an ultrasonic sensor mounted on top of the tank, and uses the device’s tankHeight server-scope attribute as the calibration constant, to compute percentage full:

Tank fill level diagram

How to set up

Set the tankHeight server-scope attribute on each tank device with its physical height (in metres). Until this attribute is set on a device, that device’s calculation falls back to the CF default (5.0).

Via UI:

  1. Open the device details page (Entities → Devices → [device name]).
  2. Navigate to the Attributes tab and select the Server-side scope.
  3. Click + to open the Add attribute dialog.
  4. Enter key tankHeight, set data type Double, and enter the tank’s height (e.g. 2.0).
  5. Click Add.

For bulk setup across many devices, see the REST attributes API.

How to customize

  • To use this on a different sensor telemetry — change the Time series key on the depth argument (e.g. depthwaterLevel, oilLevel).
  • To use a different calibration attribute — change the Attribute key on the tankHeight argument (e.g. tankHeightvesselHeight, containerCapacity).
  • To rename the output — change the output Time series key from fillLevelPercent to your domain key (e.g. tankFillPercent, containerLevel).
  • To use a different fallback when the attribute is missing — change Default value on the tankHeight argument (defaults to 5.0 metres).
  • To convert depth into percent differently — change the Expression to fit your geometry (e.g. for a horizontal cylinder, swap the linear formula for the chord-area equation).
  • To change the output precision — adjust Decimals by default on the output to whatever precision your dashboards and alarms need.
  • To timestamp the result with the latest argument reading instead of server time — enable Use latest timestamp. The output’s ts then becomes the max across all non-default input arguments, matching when the source actually updated. Useful for LoRaWAN, batched uploads, or any source where reading time lags wall-clock.

Common variants

The same calibrated-formula shape — one variable measurement plus per-device calibration constants — works for many domains. Each variant lists the telemetry the device must publish and the server-scope attributes that carry the per-unit calibration.

Weight cell

Tank fill level weight diagram

Analogue sensor with offset / slope calibration

Tank fill level analogue diagram

Share Your Calculated Field with the Community

Built a useful data transformation? Export it as a JSON from ThingsBoard and publish it to the IoT Hub. Share it with thousands of ThingsBoard developers worldwide.