Tank Fill Percentage from Depth Sensor
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.
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:
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:
- Open the device details page (Entities → Devices → [device name]).
- Navigate to the Attributes tab and select the Server-side scope.
- Click + to open the Add attribute dialog.
- Enter key
tankHeight, set data type Double, and enter the tank’s height (e.g.2.0). - 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
depthargument (e.g.depth→waterLevel,oilLevel). - To use a different calibration attribute — change the
Attribute key on the
tankHeightargument (e.g.tankHeight→vesselHeight,containerCapacity). - To rename the output — change the output Time series key
from
fillLevelPercentto your domain key (e.g.tankFillPercent,containerLevel). - To use a different fallback when the attribute is missing —
change Default value on the
tankHeightargument (defaults to5.0metres). - 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
tsthen 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
Analogue sensor with offset / slope calibration
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.