[Solved] Help with a simple workflow (counting events)


#1

Hi

I have the door sensor kit set-up, and I am trying to create a simple workflow to keep count on how many times a door was Open.

I am still new to the platform, so I am having a hard time figuring out how to Store a new value for a device variable.

Please share from your expertise :slight_smile:


#2

The door sensor kit already reports all the data you’d need to accomplish this. It’s currently reporting { "open" : 1 } when the door opens and { "open" : 0 } when the door closes.

The built-in SUM aggregation can be used to display the total number of door opens using either the Gauge Block or the Time Series block.

The SUM aggregation adds up all the values over a given time range. Summing up all the 1s results in the total count of the number of times the door was opened.


#3

If you do want to use a workflow to keep track, I recommend using the Get and Store Value nodes.

  1. Device Trigger starts workflow with a payload that has a field named data.open, which will either be a one or a zero.
  2. Use a conditional node to check that {{ data.open }} === 1.
  3. Use a Get Value node to grab the count. I’ll assume a key name of “count”. Make sure to set a default value of 0. Put the value on the payload at data.count.
  4. Use a Math node to increment the value by one. {{ data.count }} + 1. Store the result back on the payload at data.count.
  5. Use a Store Value node to save the new value with the same “count” key.
  6. (Optional) Use a Device State node to save the new value on a device attribute.

Now you’ll have a value stored in the workflow that will continually increment whenever a door is opened. You can optionally add a Device State node to store this on another device attribute. A new attribute has an advantage of not losing the count when the data retention period expires and old data starts dropping off.


#4

FYI for the method by which you keep track in a workflow, we just released some updates to the Store Value Node that make this much easier. You can now increment storage values directly in the Store Value Node without first retrieving the original value with a Get Value node.


#5

I love it how you guys will re-visit an old post and update with new solutions, features, etc! keep it up!