Device State History for a time duration

I did not see a way to query device state for a time duration. If I try using experience API workflow for the same, assuming I would need to use Data: Time Series Option, I don’t see any option to pass start and end time there.

Hey @Nishit_Saurabh,

The Data: Time Series Node can be a little confusing. Instead of start and end times, it’s configured as an end time and a duration leading up to that end time.

To access these fields, you must first change the Time Range drop down to Custom…:

Range End is configured as milliseconds since epoch. You can also use 0 to represent “now”.

Range Duration is how much time to query before the end time. This is also specified in milliseconds.

Example - 7 days of data leading up to “now”:

  • Range End = 0 (now)
  • Range Duration = 604800000 (7 days as milliseconds)

Example - 7 days between March 1st, 2023 and March 7th, 2023:

  • Range End = 1678165200000 (March 7th - milliseconds since epoch)
  • Range Duration = 604800000 (7 days as milliseconds)

The Date/Time Node and the formatDate helper are both useful tools to convert dates to milliseconds since epoch values.

1 Like

Hi @Brandon_Cannaday our requirement is we will get start and end time in the request, how do I a way to use the start and end time variable in the API and map it to custom date range here. If there is a straight forward out of the box API available for this, that would serve the purpose perfectly(I can avoid experience end point complexity). But if its not, question would be how to do it via Experience API.

What is the format of the dates you’ll be receiving in the request?

we are doing just a POC for now, so we have the flexibility of sending in a format that would work out of the box on Losant side.

@Nishit_Saurabh, I am providing an example below that is using a GET request that has the end time and range duration as query parameters.

I created an endpoint that allows the serial number to be included in the endpoint (or you could include it as a query parameter).

I then created an experience workflow that starts with the Endpoint Trigger Node and selected the endpoint that I just created.

I then call the endpoint (using the serial number in the URL) and provide the endTime and rangeDurationMilliseconds as query parameters in the request as shown below.

https://myURL.onlosant.com/data/acz8bpA5ajz6?endTime=0&rangeDurationMilliseconds=604800000

I can then reference the endTime and rangeDurationMilliseconds (and the serial number) in the workflow.

Device: Get Node configuration

Data: Time Series Node configuration

Finally, this data can be returned using the Experience Endpoint Reply Node.