If a device obtained data at a certain time in the past

I would like to know a way to check through a workflow, if a device obtained data at a certain time in the past. By means of the payload I will receive a start time and an end time in epoch, to use for example the losant API, or something else.

Thank you very much!

Hi @Maximiliano_Gibert !

This should certainly be possible. Give me a few to put together an example for you.

There are several ways of accomplishing this, but if the goal is only to see if a specific device obtained any device state data between a specified start time and end time, I believe the most performant way to do so is the following:

  • Payload contains a device ID, and start / end times formatted in milliseconds since epoch. For this example, I’m using a Virtual Button with the following payload:
{
    "deviceId" : "64790c69de15df66c7fd40f0"
    "startTime" : 1684152000000,
    "endTime" : 1684324800000,

}
  • A Losant API Node using the Device: Get Composite State endpoint. This will return the last complete device state received for a given device during a specified timeframe. If no device state was reported during that timeframe, it will return no objects. In this example, we’re referencing the deviceId, startTime, and endTime values from the above payload, and storing the result under working.apiResult:

  • A Conditional Node that evaluates if any data was returned from the API request. This can be done using the expression {{working.apiResult.[0]}}, which will evaluate if at least one object was returned. If yes, it will execute the path on the right (shown in this example as a Debug Node named “Data”). If no, it will execute the path of the left (shown as “No Data”).

Hopefully this is helpful. Let me know if you have any additional questions!

It looks very good, but in case you want to know the same thing but with more than one device… the deviceId field doesn’t seem to accept an array of ids.

Thank you so much in advance