# Timer (node-red-contrib-interval-length)

**URL:** <https://discourse.nodered.org/t/timer-node-red-contrib-interval-length/7789>\
**Category:** General\
**Created:** [10 February 2019 01:36 UTC](https://discourse.nodered.org/t/timer-node-red-contrib-interval-length/7789 "2019-02-10T01:36:59Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![VictorStela](https://avatars.discourse-cdn.com/v4/letter/v/439d5e/32.png) [@VictorStela](https://discourse.nodered.org/u/VictorStela)\
**Post date:** [10 February 2019 01:36 UTC](https://discourse.nodered.org/t/timer-node-red-contrib-interval-length/7789/1 "2019-02-10T01:36:59Z")

</div>

Hello,

I'm developing a OEE (Overall Equipment Effectiveness) counter using the Dashboard to show this informations, but I want create a flow to calculate the machine availiability and I can't create a timer to count the running time and stop time of the machine.

I tried use the node-red-contrib-interval-length, but when the flow receive the stop signal I can't stop the count of interval-length.

Does anyone have a different idea to create a timer? Basically I have a msg.topic and when it's "good" the flow continue counting the running time. When the flow don't receive this information anymore, the running time is reset and the stop time begins to count.

Regards,  
Victor Stela.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [10 February 2019 09:16 UTC](https://discourse.nodered.org/t/timer-node-red-contrib-interval-length/7789/2 "2019-02-10T09:16:41Z")

</div>

Hi Victor,

> [@VictorStela](#):
>
> I tried use the node-red-contrib-interval-length, but when the flow receive the stop signal I can't stop the count of interval-length.

If you want me to change my interval node, please describe a bit more in detail what extra functionality you need. Then I will see if I can add it ...  
Bart

---

<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:** [10 February 2019 10:46 UTC](https://discourse.nodered.org/t/timer-node-red-contrib-interval-length/7789/3 "2019-02-10T10:46:43Z")

</div>

> [@VictorStela](#):
>
> Basically I have a msg.topic and when it's "good" the flow continue counting the running time. When the flow don't receive this information anymore, the running time is reset and the stop time begins to count.

I don't fully understand what you mean by that, can you try to explain it again please?

---

<div class="post-metadata">

**Author:** ![VictorStela](https://avatars.discourse-cdn.com/v4/letter/v/439d5e/32.png) [@VictorStela](https://discourse.nodered.org/u/VictorStela)\
**Post date:** [10 February 2019 10:47 UTC](https://discourse.nodered.org/t/timer-node-red-contrib-interval-length/7789/4 "2019-02-10T10:47:57Z")

</div>

Hello Bart,

Basically, If your 'interval-length' had the option to stop time counting, maybe my flow would work properly. See below my flow:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d6f17e026b615ffd24d2f537363455806f5a673f.png)

When the 'production' link sends the 'good' or 'bad' msg.topic, the 'start time' function block starts the running time count. When the block stops receiving this information, the 'interval-length' is reset, but starts a count again.

> `[{"id":"75f070de.d7a7a","type":"ui_text","z":"56fadb09.f90304","group":"93c3eb17.38ef38","order":10,"width":"11","height":"2","name":"","label":"Machine run time","format":"{{msg.payload}}","layout":"col-center","x":763.5,"y":186,"wires":[]},{"id":"8c93adf9.35dbe","type":"change","z":"56fadb09.f90304","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"runtimef","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":542.5,"y":186,"wires":[["75f070de.d7a7a"]]},{"id":"aab89673.bed658","type":"stoptimer","z":"56fadb09.f90304","duration":"5","units":"Second","payloadtype":"str","payloadval":"reset","name":"","x":334,"y":240,"wires":[[],["932e02d5.0818c","bb487422.480cf8"]]},{"id":"932e02d5.0818c","type":"function","z":"56fadb09.f90304","name":"Get Run Time","func":"hours = parseFloat(msg.payload.hours);\nmin = parseFloat(msg.payload.minutes);\nsec = parseFloat(msg.payload.seconds);\n\nvar time = context.get(\"time\") || [];\nnow = sec + (min*60) + (hours*360);\n\nif(msg.topic === \"good\" || msg.topic === \"bad\"){\nif(time.length === 0){\n time = 0;\n}\n\ntime = time + now;\n\nfunction format(number){\n\tif (number <= 9){\n\t\tnumber = \"0\" + number;\n }\nreturn number;\n\t}\n\nvar fhour = format(Math.round(time/3600));\nvar fmin = format(Math.floor((time%3600)/60));\nvar fseg = format((time%3600)%60);\n\n}\n\nif(msg.payload === 'reset'){\n time = 0;\n fhour = 0;\n fmin = 0;\n fseg = 0;\n msg.payload = 'stop';\n}\n\ncontext.set(\"time\",time);\nvar formated = fhour+\":\"+fmin+\":\"+fseg;\nmsg.runtime = time;\nmsg.runtimef = formated;\nreturn msg;","outputs":1,"noerr":0,"x":337,"y":185,"wires":[["8c93adf9.35dbe","aab89673.bed658"]]},{"id":"c6d2c1b3.17f","type":"interval-length","z":"56fadb09.f90304","format":"json","bytopic":true,"minimum":"","maximum":"","window":"","timeout":false,"msgTimeout":"","minimumunit":"msecs","maximumunit":"msecs","windowunit":"msecs","msgTimeoutUnit":"msecs","reset":true,"startup":false,"msgField":"payload","timestampField":"timestamp","repeatTimeout":false,"name":"","x":115,"y":186,"wires":[["932e02d5.0818c"],[]]},{"id":"f71f9977.fd2628","type":"change","z":"56fadb09.f90304","name":"","rules":[{"t":"change","p":"reset","pt":"msg","from":"reset","fromt":"str","to":"true","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":114,"y":222,"wires":[["c6d2c1b3.17f"]]},{"id":"bb487422.480cf8","type":"change","z":"56fadb09.f90304","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":115,"y":258,"wires":[["f71f9977.fd2628"]]},{"id":"93c3eb17.38ef38","type":"ui_group","z":"","name":"Linha 1","tab":"bb3a6fe6.a0e13","disp":true,"width":"25","collapse":false},{"id":"bb3a6fe6.a0e13","type":"ui_tab","z":"","name":"OEE Online","icon":"dashboard","disabled":false,"hidden":false}]`

---

<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:** [10 February 2019 10:56 UTC](https://discourse.nodered.org/t/timer-node-red-contrib-interval-length/7789/5 "2019-02-10T10:56:19Z")

</div>

Does the Interval Length node pass on the topic of the incoming message? If so then you can insert a switch after it to only pass on messages resulting from a Bad topic message.

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [10 February 2019 11:00 UTC](https://discourse.nodered.org/t/timer-node-red-contrib-interval-length/7789/6 "2019-02-10T11:00:41Z")

</div>

@VictorStela  
As an alternative for your use case see [operating-time](https://github.com/cflurin/node-red-contrib-dsm/wiki/Operating-time)

---

<div class="post-metadata">

**Author:** ![VictorStela](https://avatars.discourse-cdn.com/v4/letter/v/439d5e/32.png) [@VictorStela](https://discourse.nodered.org/u/VictorStela)\
**Post date:** [10 February 2019 11:03 UTC](https://discourse.nodered.org/t/timer-node-red-contrib-interval-length/7789/8 "2019-02-10T11:03:01Z")

</div>

> [@Colin](#):
>
> Does the Interval Length node pass on the topic of the incoming message? If so then you can insert a switch after it to only pass on messages resulting from a Bad topic message.

The time will count independent of bad or good topics. So I think this isn't necessary. The time needs stop when the node 'interval-node' don't receiving more bad or good topics.

---

<div class="post-metadata">

**Author:** ![VictorStela](https://avatars.discourse-cdn.com/v4/letter/v/439d5e/32.png) [@VictorStela](https://discourse.nodered.org/u/VictorStela)\
**Post date:** [10 February 2019 11:07 UTC](https://discourse.nodered.org/t/timer-node-red-contrib-interval-length/7789/9 "2019-02-10T11:07:16Z")

</div>

> [@cflurin](#):
>
> @VictorStela  
> As an alternative for your use case see [operating-time](https://github.com/cflurin/node-red-contrib-dsm/wiki/Operating-time)

Hey cflurin,

Yes, this may work on my system. I was searching the forum and found this in an answer from you in another discussion. Thanks for the tip, I'm already testing this flow on my system.

---

<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:** [10 February 2019 11:11 UTC](https://discourse.nodered.org/t/timer-node-red-contrib-interval-length/7789/10 "2019-02-10T11:11:21Z")

</div>

> [@VictorStela](#):
>
> The time will count independent of bad or good topics. So I think this isn't necessary. The time needs stop when the node 'interval-node' don't receiving more bad or good topics.

Don't know what you mean by that. I thought the count should restart each time it receives a message, provided you have not ticked Topic Dependent.

**[Edit]** Perhaps I misunderstand what you are trying to do, I thought you wanted to time between the Good topic message and the Bad topic message.

---

<div class="post-metadata">

**Author:** ![VictorStela](https://avatars.discourse-cdn.com/v4/letter/v/439d5e/32.png) [@VictorStela](https://discourse.nodered.org/u/VictorStela)\
**Post date:** [10 February 2019 11:26 UTC](https://discourse.nodered.org/t/timer-node-red-contrib-interval-length/7789/11 "2019-02-10T11:26:48Z")

</div>

> [@Colin](#):
>
> Perhaps I misunderstand what you are trying to do, I thought you wanted to time between the Good topic message and the Bad topic message.

Relax Colin, maybe I didn't explain it well. I did not want time between the topics, but now I've used the 'operating-time' and got a good result. Thank you for trying to help me.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [11 February 2019 20:26 UTC](https://discourse.nodered.org/t/timer-node-red-contrib-interval-length/7789/12 "2019-02-11T20:26:54Z")

</div>

Hey @VictorStela,  
I have created a Github [issue](https://github.com/bartbutenaers/node-red-contrib-interval-length/issues/9), to make sure I don't forget to develop your request. Did you manage to get it solved by the operating-time tip from cflurin, or are you currently waiting for me to implement this feature?  
Bart

---

<div class="post-metadata">

**Author:** ![VictorStela](https://avatars.discourse-cdn.com/v4/letter/v/439d5e/32.png) [@VictorStela](https://discourse.nodered.org/u/VictorStela)\
**Post date:** [11 February 2019 22:20 UTC](https://discourse.nodered.org/t/timer-node-red-contrib-interval-length/7789/13 "2019-02-11T22:20:03Z")

</div>

Hi Bart,

Yes, I got the solve with the 'operating-time' metod. I think will be not necessary develop my request.

Thanks for the care.

Victor Stela.
