Send device attribute updates from a workflow

We’re working on a project where we want to be able to set some “derived attributes” on a Losant device. For example, our real device can send a “successful event” attribute to Losant, and we’d like the device to be associated with a count of the number of “successful event” messages it’s sent. However, we don’t really need the device itself to remember or track how many of the messages it sends, so it makes sense to compute that value on the server side instead of the client side.

One option for creating some computed or derived attributes would be to assign them to a virtual device corresponding to the real device (which we’re also playing with). Workflows already have support for sending output to a virtual device. However, we thought it would be cool to be able to create derived attributes on the main Losant device, using a workflow. Then we could show those properties in the device’s dashboard just by looking through its list of attributes, instead of associating it with a corresponding virtual device. We think of these as “virtual attributes.” If only there were a “Device” output node in the workflow editor… It turns out we can make one with a Lambda function!

I’m posting to Show Losant in case anyone else wants to do something similar. It might slightly break the clean separation between Device and Virtual Device in Losant, but perhaps it will be useful. We created an AWS Lambda function which acts essentially as a “Device” output node in the workflow. You send it the ID of the device you’d like to update, and you also send the attributes you’d like to set. It logs in to Losant as that device and sends the attributes.

The update appears to come from the device itself, so it will trigger Device triggers in the workflows, just like a normal attribute report. Be careful not to create an infinite loop of reports :slight_smile: If you end up using this in workflows with a Device trigger, you’ll likely want to have a conditional node after the Device trigger to check whether the updated properties are “real” or the computed “virtual” ones coming from Lambda.

Here’s the repo: https://github.com/ottobonn/losant-lambda-device

Travis

1 Like

This is a novel work-around to the virtual device / regular device separation. It’s also a good piece of feedback that reinforces the need to remove the separation. We’ve been seeing this need for a long time and have been implementing a change that will definitely help your scenario. We are replacing virtual devices with virtual attributes. This will allow you to put virtual attributes on a regular device and set them using workflows. All virtual devices will simply automatically migrate to a standalone device with all virtual attributes (no implementation changes will be required on your side). We hope to have this released in the next few weeks.

Sounds great! Y’all are awesome!

Hi Brandon

Any idea when the virtual attribute feature will be available ?
we have device data coming with varying unit types e.g. BAR vs KPA and the graphing functions don’t support any transformation (that would be nice) so was looking at using a workflow to transform. At the moment we need to use a virtual device, but a virtual attribute would be a whole lot better :wink:

T

I’d like to try to get it out either next week or the week after.

Graph transforms are also an interesting idea. Wouldn’t be too difficult to support simple transforms on the resulting data. We’ll investigate that a little as well.

Hi Brandon.

That would be awesome. For graph transform in my case I would covert BAR -> KPA (which is just multiply * 100).
Other examples of transforms would generally shifting scales so you can see patterns more easily. For instance 2 engines running in unison but at different RPM. One might be at 1200rpm and the other at 1800rpm. You want to look at them in a single chart to look at the operation in relation to each other (spikes/dips, latency) But on a normal graph the numbers a very far apart. Simple transform of adding 600 to the smaller value would then put the two into range that allows better detail.

Cheers

T

I am an idiot :wink: Much of the scale shift I can do in the graph. But transforming unit’s still make sense :wink:

We’ve released an update that removes the separation between virtual devices and standalone devices. Workflows, etc can now directly report state for all device types. Details here: https://www.losant.com/blog/rethinking-virtual-devices

1 Like