# Simple possibility to measure time

**URL:** <https://discourse.nodered.org/t/simple-possibility-to-measure-time/23561>\
**Category:** General\
**Created:** [24 March 2020 13:01 UTC](https://discourse.nodered.org/t/simple-possibility-to-measure-time/23561 "2020-03-24T13:01:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cyber](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@Cyber](https://discourse.nodered.org/u/Cyber)\
**Post date:** [24 March 2020 13:01 UTC](https://discourse.nodered.org/t/simple-possibility-to-measure-time/23561/1 "2020-03-24T13:01:09Z")

</div>

Hello,

I am new to node red. I searched a lot, but I gess with the wrong searchterms. :-/  
I would like to have a possibility to measure the "on" time of a device.  
It is switched with HTTP, I have it already in place in a flow and added e.g. a working GUI-switch which works well (displaying "on" and "off", able to switch).

now I need to measure how long it is "on" to calculate the power consumption, as I know much the device consumes exactly I only need to track the time it is switched on.

I would be able to do this with variables and timestamps, but I think this is not the first time somebody need this, so can me please point somebody which element I can use for?

Thank you in advance!

Best regards

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [24 March 2020 13:25 UTC](https://discourse.nodered.org/t/simple-possibility-to-measure-time/23561/2 "2020-03-24T13:25:42Z")

</div>

As far as I am aware, there is no special node that will do this for you.

Most likely, the best approach would be to use a flow or global variable to track the on time. If you have multiple devices to track, I personally would make that variable an object that is keyed on a unique identifier for the device. Then you can track as many as you like (subject to memory limitations).

Once a device sends an off, you would use the on time, calculate and send on the elapsed time and delete the entry in the object. If you end up with 000's of devices, you can make the flow/global variable handling more efficient but by and large, it is likely enough to just retrieve and save the whole thing.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [24 March 2020 13:44 UTC](https://discourse.nodered.org/t/simple-possibility-to-measure-time/23561/3 "2020-03-24T13:44:04Z")

</div>

This may be helpful, it measures the time between messages so if you send it the On and the Off then it will tell you how long it was On. I haven't tried it but it is one of @BartButenaers so I would expect it to work fine.

---

<div class="post-metadata">

**Author:** ![juntiedt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/juntiedt/32/58357_2.png) [@juntiedt](https://discourse.nodered.org/u/juntiedt)\
**Post date:** [24 March 2020 14:56 UTC](https://discourse.nodered.org/t/simple-possibility-to-measure-time/23561/4 "2020-03-24T14:56:33Z")

</div>

have a look  
[measure run time](https://discourse.nodered.org/t/iot-engine-run-time/21075)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [24 March 2020 15:28 UTC](https://discourse.nodered.org/t/simple-possibility-to-measure-time/23561/5 "2020-03-24T15:28:32Z")

</div>

Oops, forgot the link.

> **[node-red-contrib-interval-length](https://flows.nodered.org/node/node-red-contrib-interval-length)**
>
> A Node Red node to measure the interval length between successive messages

---

<div class="post-metadata">

**Author:** ![Cyber](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@Cyber](https://discourse.nodered.org/u/Cyber)\
**Post date:** [24 March 2020 15:30 UTC](https://discourse.nodered.org/t/simple-possibility-to-measure-time/23561/6 "2020-03-24T15:30:28Z")

</div>

thank you colin, the "interval length" I have had already found, but it looked like in my case it is only a misuse ...  
thank you juntiedt I will take a look at the flow. 😃

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [24 March 2020 15:36 UTC](https://discourse.nodered.org/t/simple-possibility-to-measure-time/23561/7 "2020-03-24T15:36:48Z")

</div>

I don't think that is a misuse of the node, it is exactly the sort of thing it is designed for.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [23 May 2020 15:36 UTC](https://discourse.nodered.org/t/simple-possibility-to-measure-time/23561/8 "2020-05-23T15:36:52Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
