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

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.

Hi Victor,

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

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

Hello Bart,

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

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}]

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.

@VictorStela
As an alternative for your use case see operating-time

1 Like

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.

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.

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.

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.

1 Like

Hey @VictorStela,
I have created a Github issue, 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

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.

1 Like