Using a Particle Variable In Losant

Yesterday I spent some time getting to know Losant. In the process I found that it supports Particle Events out of the box with an Integration but what if you're using a registered Particle Variable instead of an event? There is no built-in Integration for fetching a Particle variable but it's still possible and quite easy to do. Let me show you how I did it.

Workflow Magic

Since there isn't an Integration for a Particle variable we'll just have to use the Workflow designer and work some magic. Particle variables are always available via an HTTP GET request so really all we need to do is set up a timer to hit the Particle Cloud API on a given interval. The workflow looks like this:

You can set the Timer block up to trigger on whatever interval you desire. In the HTTP block you specify the URL Template to be the Particle Cloud URI for your variable. The format will be something like this:

https://api.particle.io/v1/devices/[YOUR DEVICE NAME OR ID]/[VARIABLE NAME]?access_token=[YOUR ACCESS TOKEN]

You can get your access token from the Settings panel in the Build Web IDE.

The other important part of the HTTP block is at the very bottom of the settings there is an option to store the response of the request in the current payload. You need to specify "data". Otherwise your variable information will not be passed along to the next block which in my case is Device State.

In the Device State block you can use the variable information to set an attribute on one of your configured devices by referencing the payload data as .

That's it! That's all there is to assigning a Particle Variable value to one of your devices in Losant.