Display Total per Day on Dashboard

I have a machine running that applies grease to train track. It applies once per train that passes it. One cycle = one application. Data from controller is just a counter that only resets when the controller is restarted. I want to display a bar graph that shows how many cycles it ran on that day. Is there a way to achieve this without resetting the machine once a day?

Hi @Lyndon_Walker !

There are a few different ways to accomplish this. From a high level, my recommendation is to create a workflow that utilizes:

  • A Timer Trigger set to run daily (at 00:00 for example).

  • Storage Get / Set Nodes to maintain workflow storage values that can be used to compare the most recently reported value with the previously reported value.

  • A Device: Update Node that updates a new attribute value, which can then be referenced in your dashboard block.

Give me a bit and I’ll return to this thread with an example workflow.

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.