Find the total sum of a variable starting from a specific time in the past and up until the newest data point


I’m trying to figure out a way to find the total sum of a variable and record it in the device data - for example, in my case, say, there is a device which records alarms and with the Data: Gauge Query block it’s easy to keep track of the last hour or 24 hours or any of the (pre)defined time ranges.

I, however, would like to be able to display the total amount of alarms since the device started sending data; given, I have an attribute which keeps track of how many times the event happened per each message. Is there an easy way to set-up a counter with an initial default value that I could calculate myself?

Maybe using the sum aggregation in some specific way? I’ve tried defining a custom time, but I need the time window to increase incrementally as we move away from the date that the device started sending data and I don’t think that’ll happen automatically. Maybe I can pass in a variable that has the right time calculated each workflow call? That’s probably computationally intensive and inefficient.

The other thing it seems that I can do is simply display the total value separately on the dashboard from the other counts and set the time range for that to be greater than ‘x’ of time with the sum aggregation. This would allow me to proceed without altering the workflows that I have, but would it sum a variable past 180 days?

What would be a reasonable way forward or what would you suggest I do?

Thank you in advance!

Hi @Nikolay_Stepin and welcome to the Losant forums!

As you suggested, you can use the sum aggregation method in the Gauge dashboard block to display the sum of up to 180 days of historical data for a single device attribute across one or more devices.

If you want to display a longer duration, or if you want to run other calculations, I suggest using workflow storage to maintain an iterative value that can be stored as a new device attribute. I created an example of this a few months ago for somebody with a similar use-case. You’ll want to tweak this to fit your specific needs, but hopefully will get you on the right track if you pursue this option:

Let us know if one of these options will work for you, and once again, thanks for joining us on our forums!


Thank you for your reply! I did see that post, but I was wondering if there was a simpler way to do it; I’ll go ahead and try to tweak that workflow to my needs and post in this thread if I need further help :slight_smile:

If it works out, I’ll let you know and close this out.

Thanks again!