Calculating duration between timestamps

Hi all,

new to Losant and I am struggling to find a way to calculate the duration between the timestamps I get displayed in my dashboard in my Device State Table.

The goal is to be able to calculate the average duration between states that go from “Belegt” to “Frei” on a monthly basis. As a first step, it would be great if someone could explain how I can access the timestamps from the Device State Table in my Workflow?

If thats not possible, I can also use the time in my payload.
In regards to my Workflow I have tried the following:

The virtual button sends the payload into the Storage: Set Value Node, which saves the timeNew value from my payload. The Conditional Node checks if there is an timeOld value available. If not, then save the time from the payload also as timeOld, then do a calculation.
Following this, I amend the time in payload to check if the conditional becomes true, but it does not and rather overwrite both the timeNew and timeOld value with the amended time.
I was looking to simulate payloads passing through the Workflow over time with this, as the sensor I am using only sends data every couple of hours.

Hopefully everything in my explanation is clear, I would really appreciate some help on this.

As a sidenote: I am not able to code in JavaScript and was looking to use Losant because of its “low-code” features. If there is no way around learning JavaScript it would be great to know, because then I’ll have to start there.

Thanks and best regards,
Benjamin

Hi @Benjamin_M , sorry for the late reply on this. Our spam filter mistakenly flagged your post.

As a first step, it would be great if someone could explain how I can access the timestamps from the Device State Table in my Workflow?

Check out the Data: Time Series Node. That will allow you to query the “Status” attribute on your device and return the raw data over a given time range. With that, you’ll have the data available on a workflow payload.

If what you really care about is knowing when the value of the Status attribute changes, check out the On Change Node. When the value changes you could store the time as a Unix timestamp (which you can easily do using the {{formatDate}} helper) in workflow storage and, the next time it changes, compare the old timestamp to the new timestamp to get the duration in seconds or milliseconds.

I am not able to code in JavaScript and was looking to use Losant because of its “low-code” features. If there is no way around learning JavaScript it would be great to know, because then I’ll have to start there.

Knowing any programming language helps - and knowing JavaScript helps a lot - but it is our goal that our users can use the workflow nodes available to them to accomplish any IoT use case in the workflow engine. If you come across a case that you would only be able to accomplish using a Function Node, then that is an opportunity for us to develop a node to solve that case. Many of the nodes in our palette today - especially in the light blue “Logic” category - were created for exactly this reason.

Hopefully this is enough info to get you going; if you have any other questions, don’t hesitate to reach out.

P.S. Welcome to Losant!