Collecting usage time

I have a machine that goes on and off on an irregular basis.
I want to collect the accumulated time it’s on and I can see a few ways of doing that.
Any recommendations?

1 Like

Hi Lars,

The best thing to do would be to use this API:

Then, you can use it to calculate the total time your device was online.

It’s not when it was on line or not. It’s the accumulated time a pressure sensor sees a certain pressure.
Electrically and connectivity wise it’s always on.

Hi @Lars_Andersson,

The way I would solve this is to first store the time once the value is above the threshold you set; you can store this time in workflow storage or within an attribute, whichever you prefer. Then, once the time has dipped back below the threshold, do a comparison of these times and get the difference. You can then store this time value in a device attribute, individually as one single time, or you could do a cumulative count within the attribute.

Let me know if this meets your requirements!
Julia

I’ve done it that way now.
Sure would be nice to have a “run time counter” as a workflow node…

Hi folks. I’ve been working on a similar problem - accumulated run time of devices.

I have a workflow where this is doing what I need. I’m now wanting to put this value on a gauge block in a dashboard but not having any success. I’ve tried saving the value to both a payload attribute (data.runTime) and workflow storage (working.runTime), both with the Storage:Set Value nodes. Neither appear in the Gauge’s Attributes selection. I then added the runTime attribute to my device and set the device to send a zero value in its status. I can then see the runTime attribute in the Gauge setup, however I only get a value of zero on the gauge, even after the workflow updates the value. I’m a bit lost. Help? :slightly_smiling_face:

Hi @Matthew_Small, and welcome to the Losant Forums.

Somewhere in that workflow, you need to add the new value to the already accumulated value and set that value as device state using a Device: State Node. You can retrieve the previous value using the methods Julia described in this thread.

If you haven’t done so already, I recommend going through Losant’s getting started tutorial, which covers device state, workflows, and dashboards - all of the platform components you are working with here to get your desired behavior.

If you have any other questions, please let us know!

Thanks so much, Dylan. I had tried the Device: State Node earlier but I was getting an error and thought I must have been going down the wrong track. Revisiting it on your advice, I got the same error but followed it through further. Looks like this was the fix I needed! I’m now up and running. Thanks for pointing me in the right direction. :+1:

Glad to hear. Since that 2017 post you referenced, we’ve added a feature to the Device: State Trigger to make it easier to stay out of those loops. Hopefully you found that and are taking advantage of it.

Let us know if you have any other questions.