# Collecting usage time

**URL:** <https://forums.losant.com/t/collecting-usage-time/2045>\
**Category:** Help\
**Tags:** workflow\
**Created:** [August 1, 2019, 8:47pm UTC](https://forums.losant.com/t/collecting-usage-time/2045 "2019-08-01T20:47:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lars\_Andersson](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Lars\_Andersson](https://forums.losant.com/u/Lars_Andersson)\
**Post date:** [August 1, 2019, 8:47pm UTC](https://forums.losant.com/t/collecting-usage-time/2045/1 "2019-08-01T20:47:41Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![anaptfox](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/anaptfox/32/873_2.png) [@anaptfox](https://forums.losant.com/u/anaptfox)\
**Post date:** [August 1, 2019, 9:00pm UTC](https://forums.losant.com/t/collecting-usage-time/2045/2 "2019-08-01T21:00:17Z")

</div>

Hi Lars,

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

> **[Device Actions](https://docs.losant.com/rest-api/device/#get-log-entries)**
>
> A detailed look at the various REST actions supported by the Device resource of the Losant API. Learn more.

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

---

<div class="post-metadata">

**Author:** ![Lars\_Andersson](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Lars\_Andersson](https://forums.losant.com/u/Lars_Andersson)\
**Post date:** [August 1, 2019, 9:19pm UTC](https://forums.losant.com/t/collecting-usage-time/2045/3 "2019-08-01T21:19:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JuliaKempf](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/juliakempf/32/2446_2.png) [@JuliaKempf](https://forums.losant.com/u/JuliaKempf)\
**Post date:** [August 2, 2019, 5:42pm UTC](https://forums.losant.com/t/collecting-usage-time/2045/5 "2019-08-02T17:42:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Lars\_Andersson](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Lars\_Andersson](https://forums.losant.com/u/Lars_Andersson)\
**Post date:** [August 20, 2019, 3:26pm UTC](https://forums.losant.com/t/collecting-usage-time/2045/6 "2019-08-20T15:26:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Matthew\_Small](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Matthew\_Small](https://forums.losant.com/u/Matthew_Small)\
**Post date:** [October 23, 2023, 6:33am UTC](https://forums.losant.com/t/collecting-usage-time/2045/8 "2023-10-23T06:33:13Z")

</div>

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? 🙂

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [October 23, 2023, 2:05pm UTC](https://forums.losant.com/t/collecting-usage-time/2045/9 "2023-10-23T14:05:36Z")

</div>

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](https://docs.losant.com/devices/state/) using a [Device: State Node](https://docs.losant.com/workflows/outputs/device-state/). 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](https://docs.losant.com/getting-started/walkthrough/), 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!

---

<div class="post-metadata">

**Author:** ![Matthew\_Small](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Matthew\_Small](https://forums.losant.com/u/Matthew_Small)\
**Post date:** [October 24, 2023, 12:26am UTC](https://forums.losant.com/t/collecting-usage-time/2045/10 "2023-10-24T00:26:48Z")

</div>

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](https://forums.losant.com/t/workflow-reentrant-loop-for-device/616/2) was the fix I needed! I’m now up and running. Thanks for pointing me in the right direction. 👍

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [October 24, 2023, 11:58am UTC](https://forums.losant.com/t/collecting-usage-time/2045/11 "2023-10-24T11:58:19Z")

</div>

Glad to hear. Since that 2017 post you referenced, we’ve added a [feature to the Device: State Trigger](https://docs.losant.com/workflows/triggers/device/#filter-by-attributes) 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.
