# TIme remaining on Trigger node - debug or msg.property

**URL:** <https://discourse.nodered.org/t/time-remaining-on-trigger-node-debug-or-msg-property/343>\
**Category:** Core Development\
**Created:** [24 May 2018 06:03 UTC](https://discourse.nodered.org/t/time-remaining-on-trigger-node-debug-or-msg-property/343 "2018-05-24T06:03:54Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [24 May 2018 06:03 UTC](https://discourse.nodered.org/t/time-remaining-on-trigger-node-debug-or-msg-property/343/1 "2018-05-24T06:03:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SteveMann](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stevemann/32/3810_2.png) [@SteveMann](https://discourse.nodered.org/u/SteveMann)\
**Post date:** [24 May 2018 16:22 UTC](https://discourse.nodered.org/t/time-remaining-on-trigger-node-debug-or-msg-property/343/2 "2018-05-24T16:22:53Z")

</div>

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;

---

<div class="post-metadata">

**Author:** ![davidcgu](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@davidcgu](https://discourse.nodered.org/u/davidcgu)\
**Post date:** [24 May 2018 17:10 UTC](https://discourse.nodered.org/t/time-remaining-on-trigger-node-debug-or-msg-property/343/3 "2018-05-24T17:10:13Z")

</div>

+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

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [24 May 2018 22:10 UTC](https://discourse.nodered.org/t/time-remaining-on-trigger-node-debug-or-msg-property/343/4 "2018-05-24T22:10:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [24 May 2018 22:41 UTC](https://discourse.nodered.org/t/time-remaining-on-trigger-node-debug-or-msg-property/343/5 "2018-05-24T22:41:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [24 May 2018 22:43 UTC](https://discourse.nodered.org/t/time-remaining-on-trigger-node-debug-or-msg-property/343/6 "2018-05-24T22:43:08Z")

</div>

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](https://nodered.org/docs/creating-nodes/status)) ?

 ![display-timer](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/2fdd14e5492793821f489f2894d86e74241c0d74.PNG)

Testing flow:

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![877](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/877/32/8207_2.png) [@877](https://discourse.nodered.org/u/877)\
**Post date:** [21 May 2019 19:47 UTC](https://discourse.nodered.org/t/time-remaining-on-trigger-node-debug-or-msg-property/343/7 "2019-05-21T19:47:21Z")

</div>

I know this is an old thread, but I just used @Andrei 's flow and it's good for showing the 'running' time of the trigger (thanks).

In my case, I have the trigger set for 2 minutes and "extend delay if new message arrives" is ticked. Evertime the PIR detects motion, the trigger starts again.

It would be good if the function would re-start counting from zero at **every** trigger.

Did anyone find a solution?

 ![28](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/69cdec372b2efb9e48d8d35b339e1129ac27c0e7.png)

This is Andrei's function:

```auto
var counting = function () {
  let counter = flow.get('counter');
  counter += 1;
  node.status({text:counter + " seconds"});
  flow.set('counter',counter);
   return counter;
}

if (msg.payload === "true") {
    flow.set('counter',0);
    node.status({text: "Started.."}); 
    let timer1 = setInterval(counting, 1000);
    flow.set('timer1',timer1);
} else if (msg.payload === "false") {
    node.status({}); // clear the status decoration
    clearInterval(flow.get('timer1')); 
    
}

return msg;

```

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [21 May 2019 20:19 UTC](https://discourse.nodered.org/t/time-remaining-on-trigger-node-debug-or-msg-property/343/8 "2019-05-21T20:19:16Z")

</div>

Hi , I will have a look tomorrow (going out now). There are a couple of things I dislike in this old flow. It would be better to refactor.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [21 May 2019 23:05 UTC](https://discourse.nodered.org/t/time-remaining-on-trigger-node-debug-or-msg-property/343/9 "2019-05-21T23:05:26Z")

</div>

Check Peter Scargills blog - i am sure i remember that he has updated his Timeout node (or maybe his Big Timer) to support a function such as this.

Craig

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [21 May 2019 23:08 UTC](https://discourse.nodered.org/t/time-remaining-on-trigger-node-debug-or-msg-property/343/10 "2019-05-21T23:08:44Z")

</div>

Here you go

[https://tech.scargill.net/node-red-contrib-timeout/](https://tech.scargill.net/node-red-contrib-timeout/) - looks like it will do what you want ?

Craig

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [22 May 2019 04:15 UTC](https://discourse.nodered.org/t/time-remaining-on-trigger-node-debug-or-msg-property/343/11 "2019-05-22T04:15:55Z")

</div>

HI @877,

Considering the flaws existing in the old flow my recommendation is to stop using it in favor of another solution. I modified the flow by adding an additional trigger node to function as a heartbeat and changing the code in the function node (more simple). This new flow will restart the counter each time the trigger node named monitor starts a new cycle. The trigger node does not provide any information on its output when the delay is extended. I can't, therefore, reset the counter when the delay is extended, only when a new cycle is started (when the blue icon appears).

The idea of a custom node for monitoring the timing is appealing but I was unaware of the timeout contrib node. Perhaps I will try it in the future.

```auto
[{"id":"f23c5499.aabc68","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"fe71ea4c.17d5c8","type":"trigger","z":"f23c5499.aabc68","op1":"trigger","op2":"newcycle","op1type":"str","op2type":"str","duration":"2","extend":true,"units":"min","reset":"stopcounting","bytopic":"all","name":"monitor","x":400,"y":160,"wires":[["8b20690f.508318","2d881ab3.88a7d6","61fec400.84239c","9756a5b6.a95ee8"]]},{"id":"8b20690f.508318","type":"debug","z":"f23c5499.aabc68","name":"Right Kitchen light","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":750,"y":160,"wires":[]},{"id":"152df4c1.e36c1b","type":"inject","z":"f23c5499.aabc68","name":"Data from PIR (MQTT)","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":160,"wires":[["fe71ea4c.17d5c8"]]},{"id":"61fec400.84239c","type":"function","z":"f23c5499.aabc68","name":"Display time","func":"if (msg.payload === \"count\") {\ncc = (flow.get('counter') || 0);\ncc = cc + 1;\nnode.status({text:cc + \" seconds\"});\nflow.set('counter', cc);\n} else {\n if (msg.payload === \"newcycle\") {\n flow.set('counter' , 0);\n node.status({text:\"Stop\"});\n }\n}\nreturn msg;","outputs":1,"noerr":0,"x":690,"y":220,"wires":[[]]},{"id":"2d881ab3.88a7d6","type":"trigger","z":"f23c5499.aabc68","op1":"count","op2":"fail","op1type":"str","op2type":"str","duration":"-1","extend":true,"units":"s","reset":"newcycle","bytopic":"all","name":"heartbeat","x":460,"y":220,"wires":[["61fec400.84239c"]],"outputLabels":["send \"fail\" if not feeded"]},{"id":"9756a5b6.a95ee8","type":"debug","z":"f23c5499.aabc68","name":"Left Kitchen light","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":740,"y":120,"wires":[]}]

```

 ![t-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/8188098e7d49ba0e568678d60617c711d728e63a.png)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [22 May 2019 05:45 UTC](https://discourse.nodered.org/t/time-remaining-on-trigger-node-debug-or-msg-property/343/12 "2019-05-22T05:45:04Z")

</div>

> [@Andrei](#):
>
> The trigger node does not provide any information on its output when the delay is extended

... But the input does...

---

<div class="post-metadata">

**Author:** ![877](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/877/32/8207_2.png) [@877](https://discourse.nodered.org/u/877)\
**Post date:** [22 May 2019 07:06 UTC](https://discourse.nodered.org/t/time-remaining-on-trigger-node-debug-or-msg-property/343/13 "2019-05-22T07:06:28Z")

</div>

Thanks guys I will test it out when I get back from work 👍

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [22 May 2019 12:54 UTC](https://discourse.nodered.org/t/time-remaining-on-trigger-node-debug-or-msg-property/343/14 "2019-05-22T12:54:37Z")

</div>

> [@dceejay](#):
>
> . But the input does...

Indeed, in which case I would add an additional wire to the function node and do some processing on the data coming from the sensor. So, it is possible just requiring some additional thought.

Edit: in fact not much thought required...😄

```auto
[{"id":"760faf65.70c2b","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"be79017b.ada3b","type":"trigger","z":"760faf65.70c2b","op1":"trigger","op2":"newcycle","op1type":"str","op2type":"str","duration":"6","extend":true,"units":"s","reset":"stopcounting","bytopic":"all","name":"monitor","x":400,"y":140,"wires":[["cf8b1b07.16c518","5c274368.b7f35c","3681edac.7f5c72"]]},{"id":"cf8b1b07.16c518","type":"debug","z":"760faf65.70c2b","name":"Right Kitchen light","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":750,"y":140,"wires":[]},{"id":"57510a4d.ef00e4","type":"inject","z":"760faf65.70c2b","name":"Data from PIR (MQTT)","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":140,"wires":[["be79017b.ada3b","72817943.f6bb28"]]},{"id":"bf7c304f.8d5ec","type":"function","z":"760faf65.70c2b","name":"Display time","func":"if (msg.payload === \"count\") {\n cc = (flow.get('counter') || 0);\n cc = cc + 1;\n node.status({text:cc + \" seconds\"});\n flow.set('counter', cc);\n} else {\n flow.set('counter' , 0);\n node.status({text:\"Restarted\"});\n}\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":200,"wires":[[]]},{"id":"5c274368.b7f35c","type":"trigger","z":"760faf65.70c2b","op1":"count","op2":"fail","op1type":"str","op2type":"str","duration":"-1","extend":true,"units":"s","reset":"newcycle","bytopic":"all","name":"heartbeat","x":460,"y":200,"wires":[["bf7c304f.8d5ec"]],"outputLabels":["send \"fail\" if not feeded"]},{"id":"3681edac.7f5c72","type":"debug","z":"760faf65.70c2b","name":"Left Kitchen light","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":740,"y":100,"wires":[]},{"id":"e5b4631e.403ca","type":"link in","z":"760faf65.70c2b","name":"","links":["72817943.f6bb28"],"x":535,"y":260,"wires":[["bf7c304f.8d5ec"]]},{"id":"72817943.f6bb28","type":"link out","z":"760faf65.70c2b","name":"","links":["e5b4631e.403ca"],"x":320,"y":260,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![877](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/877/32/8207_2.png) [@877](https://discourse.nodered.org/u/877)\
**Post date:** [22 May 2019 18:08 UTC](https://discourse.nodered.org/t/time-remaining-on-trigger-node-debug-or-msg-property/343/15 "2019-05-22T18:08:12Z")

</div>

Thank you, I actually already use the timeout node for detecting whether my devices are online, a very useful node. I use it to change the colour of the readings on the Blynk app. I will have a tinker and see how it fits this application 🙂

 ![45](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/34035b2750e6bb324cd600f058bd7fca23944afa.png)

---

<div class="post-metadata">

**Author:** ![877](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/877/32/8207_2.png) [@877](https://discourse.nodered.org/u/877)\
**Post date:** [22 May 2019 18:17 UTC](https://discourse.nodered.org/t/time-remaining-on-trigger-node-debug-or-msg-property/343/16 "2019-05-22T18:17:41Z")

</div>

> [@Andrei](#):
>
> Edit: in fact not much thought required...😄

@Andrei thanks for the flow, first impressions are that it works very well. I need to study it a little more, did you just use the link nodes to keep the flow tidy? First time I have seen them, as I am quite new 👍

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [22 May 2019 18:58 UTC](https://discourse.nodered.org/t/time-remaining-on-trigger-node-debug-or-msg-property/343/17 "2019-05-22T18:58:27Z")

</div>

I am happy it works 😃  
I have added the link nodes, as you well notes, to keep the flow tidy. They are very handy.
