I am trying to use the Latching and Events workflow template to create and auto resolve alarm events from multiple sensors on one device (30-40 alarm sensors per device). Is there an efficient way to do this? I have not done much with loops, but I am struggling to find a way to filter the attributes and perform an evaluation across all the attributes in the payload.
Hi @Amelia_Evans and welcome to the Losant forums!
This can certainly be done by maintaining a separate workflow for each of the attributes from which you want to latch / create events, and that might be the easiest way to manage the varying logic you’d be using to evaluate each attribute.
However, let me see if I can come up with a single-workflow example that isn’t too convoluted. I’ll return to the this thread once I have an update.
I’ve created a proof-of-concept workflow based on the template you linked that utilizes a loop to evaluate multiple attributes from a single device and create/resolve events. Feel free to import this workflow and see if it fits your needs.
multiple-attribute-latching-and-events-develop.flow (13.4 KB)
A few considerations:
This example assumes that each device attribute being evaluated has two device attribute tags -
resetThreshold. You can, of course, modify the attribute tags that will be evaluated.
The Virtual Button in this example simulates device state data, as well as device attribute tag values. If you set the
humidity values in the Virtual Button to greater than the
maxThreshold attribute tag values (in this example,
humidity), the requisite events will be created. If you set these values to less than the
resetThreshold attribute tag values (
humidity), the events will resolve
The loop will iterate over all attributes reported by the device. The same numerical comparison is employed when evaluating each attribute value and determining if an event should be created or resolved. If you need to evaluate certain numerical attributes differently, or if you’re evaluating different types of attributes (such as boolen or string attributes), you’ll need to add that logic into the workflow.
As always, please test before using this workflow in any sort of production capacity. Please let me know if you have any questions!
Thank you so much! We were able to come up with something very similar but I think your solution will work great for looking at attributes dealing with larger numbers (ours were just changing from 0 to 1 and back). I’ll post ours in case someone else also has this question.