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 calledtotalCount
and is available on the initial payload atdata.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 thislastTotalCount
and place it on the payload asworking.lastTotalCount
. -
Math Node - Here I used
max( ( {{ data.totalCount }} - {{ working.lastTotalCount }} ), 1 )
. This determines the difference betweendata.totalCount
andworking.lastTotalCount
. The result is stored asworking.newCount
.- This example uses the
max
function to ensure the result is always at least1
, that way if the machine is reset and thetotalCount
attribute goes back to, say,0
or1
, you never have a resulting value of less than1
when subtracting the previously reportedlastTotalCount
value. Of course, you’ll want to adjust this logic to your use-case.
- This example uses the
-
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 atdata.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.