Display Total per Day on Dashboard

I’ve attached a workflow file that will hopefully help get you started. You’ll definitely want to tweak it to fit for your use:

set-daily-count-develop.flow (4.2 KB)

Here’s an explanation of the nodes used:

  • Device: State Trigger - Activates any time the selected device sends a device state report containing any attribute other than the newCount attribute that we’ll be defining downstream. For this example, let’s say the “total cycles since boot” attribute is called totalCount and is available on the initial payload at data.totalCount.

  • Storage: Get Value Node) - We’re using workflow storage to store the previously reported totalCount value, from the previous execution of this workflow. Let’s call this lastTotalCount and place it on the payload as working.lastTotalCount.

  • Math Node - Here I used max( ( {{ data.totalCount }} - {{ working.lastTotalCount }} ), 1 ). This determines the difference between data.totalCount and working.lastTotalCount. The result is stored as working.newCount.

    • This example uses the max function to ensure the result is always at least 1, that way if the machine is reset and the totalCount attribute goes back to, say, 0 or 1, you never have a resulting value of less than 1 when subtracting the previously reported lastTotalCount value. Of course, you’ll want to adjust this logic to your use-case.
  • Device: Update Node - Creates a new attribute on the device called newCount, if the attribute doesn’t already exist on the device.

  • Device: State Node Output Node - Sets the newCount attribute value on the device from {{working.newCount}}.

  • Storage: Set Value Node - Now that we’re done referencing the old working.lastTotalCount value from workflow storage, we’re going to update it to the newly reported value we received on the payload at data.totalCount.

Now you have a newCount attribute on the device. In a Bar Chart (or other time series dashboard block), you can set the Aggregation to Sum, which will add up all of the newCount values reported within the selected Duration (e.g. 24 hours):

Hopefully this is helpful! If you have any other questions, please don’t hesitate to ask.