TIme remaining on Trigger node - debug or msg.property

#1

Guys, Suggestion to add a debug for time remaining on a trigger node to allow that to be output to the debug window or as a property

So i have a trigger node that counts down for 4 hours - i have no idea when it was set though and how much time is left until it resets or does the next action - would be nice to know - either through a property that could be output on a timed basis to the Debug window - or simply as a debug output

Craig

0 Likes

#2

I am a newbie also, but I use the BigTimer node for something similar. For observing the time remaining, I use the second output of the timer and the following function to tell me how much time remains.

Hope this helps.
Steve Mann

Function:
var myTime = msg.timer;
var hours = Math.floor(myTime / 3600);
myTime = myTime - hours * 3600; //Remaining minutes
var minutes = Math.floor(myTime / 60); //Minutes
var seconds = myTime - minutes * 60; //Remaining seconds

//Format into hh:mm:ss
msg.payload = (β€œ0” + hours).slice(-2) + β€œ:” + (β€œ0” + minutes).slice(-2) + β€œ:” + (β€œ0” + seconds).slice(-2);
return msg;

0 Likes

#3

+1… I have it also solved with bigtimer and some function but will be great to have a simple dedicated node that can handle it easier

0 Likes

#4

FYI, here’s a trick I have used to convert a number of seconds into a readable time string:

var sec = +msg.payload;  // assuming the payload contains seconds
var dtm = new Date(1970, 0, 1, 0, 0, sec); // add seconds to the epoch
var hms = dtm.toTimeString().substring(0, 8); // convert to time string

This seems to work in any timezone, because this new Date(yy,mm,dd,hh,mm,ss,ms) function assumes local time. (of course, you could also pass in numeric hours or minutes)

NB: this technique won’t handle more than 1 days worth of seconds, because it will roll-over to 00:00:00. For more complex time shifting/formatting, take a look at the node-red-contrib-moment nodes.

0 Likes

#5

Thanks SteveMann, will incorporate this - I had forgotten about how good Peters BigTimer was.

It would still be nice to have the option with the standard trigger also

Craig

0 Likes

#6

An alternative approach... assuming you want to monitor the remaining timeout in the edit page (not in the dashboard). How about branching your flow in the trigger node to include a function that will display a status decoration (https://nodered.org/docs/creating-nodes/status) ?

Testing flow:

[{"id":"ce1de646.75e118","type":"trigger","z":"f17da547.15ef68","op1":"start","op2":"stop","op1type":"str","op2type":"str","duration":"40","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":412.10008239746094,"y":249.00000381469727,"wires":[["bf803970.becfc8","a9a68a8c.e31a38"]]},{"id":"50e205c7.c5e3ec","type":"inject","z":"f17da547.15ef68","name":"","topic":"","payload":"start","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":251.10000228881836,"y":250.00000381469727,"wires":[["ce1de646.75e118"]]},{"id":"bf803970.becfc8","type":"debug","z":"f17da547.15ef68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":671.1000595092773,"y":214.00000381469727,"wires":[]},{"id":"a9a68a8c.e31a38","type":"function","z":"f17da547.15ef68","name":"Branch to display time remaining","func":"var counting = function () {\n  let counter = flow.get('counter');\n  counter += 1;\n  node.status({text:counter + \" seconds\"});\n  flow.set('counter',counter);\n   return counter;\n}\n\nif (msg.payload === \"start\") {\n    flow.set('counter',0);\n    node.status({text: \"Started..\"}); \n    let timer1 = setInterval(counting, 1000);\n    flow.set('timer1',timer1);\n} else if (msg.payload === \"stop\") {\n    node.status({}); // clear the status decoration\n    clearInterval(flow.get('timer1')); \n    \n}\n\nreturn msg;","outputs":1,"noerr":0,"x":683.1000595092773,"y":305.00000381469727,"wires":[["e66bad9a.b704a"]]},{"id":"e66bad9a.b704a","type":"debug","z":"f17da547.15ef68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":896.0000114440918,"y":304.00000381469727,"wires":[]}]
1 Like