Difference between current and last incrementing pulse count values reported by sensor

First, it sounds like you may be storing device telemetry data in a data table, something we strongly recommend against as data tables lack the performance, aggregation methods, and scalability of our native time series database.

Now for your question, you have a couple options here …


First, you said it’s a “LoRa water meter”, which leads me to believe that the data is coming into Losant via a webhook or experience endpoint - and thus you are using a workflow to record the device state. So one thing you could do in your workflow is …

  1. Fetch the device you are recording state for using the Device: Get Node, also retrieving the composite state values for your pulse count and Unix timestamp (though you could also just use the time that the pulse count was received).
  2. Calculate the difference between the value that just came from the LoRa sensor and the value that was last recorded to the device. You could do this easily using a Math Node.
  3. In addition to recording the new pulse count and timestamp in your Device: State Node, also now record the calculated differences as separate attributes on the device (i.e. “pulsesSinceLastReport” and “timeSinceLastReport”).
  4. Now, in a dashboard, you can display those calculated differences several different ways, such as using a Gauge Block.

Alternatively, you mentioned that what you are trying to do “would take seconds in code normally”, and you’re right. Luckily there’s a block for that - the Custom HTML Block or, if you’re familiar with Vega, the Custom Chart.

In either case, you could set up two time series queries in the block: one for the pulse count and one for the timestamp. Each would use the “Last” aggregation method and would use a duration and resolution appropriate for how frequently your device reports data; I would aim for the lowest possible values that would ensure you always receive at least two data points that would reflect the most recent and the second-most recent state reports.

With that data in hand, you can calculate the difference between the last pulse count and the one before it, and same for the timestamps. And then you can visualize those two values however you see fit.