Skip to content
Stand with Ukraine flag

Daily Water Consumption Total

  • Calculated Field
  • 0 installs
  • v1.0.0
  • Jul 22, 2026
  • MIT license
  • v4.2 - 4.3

Calculates the total water consumed by a device from the start of the current day (00:00) up to the present moment. Ideal for tracking daily usage in real time, spotting unusual consumption patterns, and building clear daily reports. Resets automatically every midnight and updates continuously as new telemetry arrives. Simple to add to any device — just apply this calculated field and start monitoring daily water usage instantly on your dashboards.

Type
  • Script
Category
  • Aggregation
  • Custom Formula
  • Energy
Use Cases
  • Smart Metering
  • Smart Farming
  • Smart Building
  • Smart City
  • Smart Energy
  • Tank Level Monitoring

Who it’s for

Facility managers, utility teams, and dashboard authors asking “how much water has this building used today?”, “are we on track for our daily water budget?”, “why did consumption spike this morning?” — when devices report incremental flow readings but the question is about total usage since midnight.

What it does

Reads the deltaWater time series key (each value representing the incremental water consumption since the previous reading, over a rolling 24-hour window) and sums every value whose timestamp falls between the start of the current day (00:00:00:000, local time) and the current time: dailyWaterConsumption = Σ(deltaWater_i) for all i where startOfDay <= timestamp_i <= now. The result is rounded to 2 decimal places and written back as a new dailyWaterConsumption time series key on the same entity, recalculating on every new deltaWater value. Because the window naturally rolls forward and the sum only counts points after today’s midnight, the total resets to reflect “today only” once a new day begins.

daily_water_consumption_diagram

A script calculated field reads up to about 1000 readings per daily window, regardless of the time window you choose. If a device reports more often than that in a day, the total counts only the most recent readings. ThingsBoard 4.3 and later offer a built-in Time series data aggregation type that does this without the limit — this template is for 4.2, where that type is not yet available.

How to set up

If your device already publishes a per-period water delta (liters used since the last reading), the template works as-is — set the argument’s Time series key to your key.

Many water devices publish a cumulative meter reading or a dropping tank level instead. Pair with one of the upstream Script templates below — it turns the raw reading into a per-period delta this template can add up. To connect, change the argument’s Time series key to the upstream field’s output key readingsDelta.

For cumulative meters that only climb (water meter totals, pulse counters):

Calculate Delta from Pulse Counter Dmytro Shvaika

For dropping levels that fall as water is used (tank level, reservoir level):

Calculate Delta from Tank Level Sensor Dmytro Shvaika
  1. Assign this calculated field to the device profile or entity where deltaWater is reported.
  2. Save and wait for the next telemetry update, or send a test value manually.
  3. Open the entity’s Latest Telemetry tab and verify that dailyWaterConsumption appears and increases as new deltaWater values arrive, resetting shortly after midnight.

How to customize

  • To use a different telemetry key — change the Time series key on the source argument from deltaWater to match what your devices publish.
  • To rename the output key — change the dailyWaterConsumption key in the script’s return statement (return { "dailyWaterConsumption": toFixed(sum, 2) }) to your domain key.
  • To change the rounding precision — edit the toFixed(sum, 2) call in the script to use more or fewer decimal places.

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.