# Check out the last two minutes

**URL:** <https://discourse.nodered.org/t/check-out-the-last-two-minutes/29036>\
**Category:** General\
**Created:** [26 June 2020 15:42 UTC](https://discourse.nodered.org/t/check-out-the-last-two-minutes/29036 "2020-06-26T15:42:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hasan90](https://avatars.discourse-cdn.com/v4/letter/h/46a35a/32.png) [@Hasan90](https://discourse.nodered.org/u/Hasan90)\
**Post date:** [26 June 2020 15:42 UTC](https://discourse.nodered.org/t/check-out-the-last-two-minutes/29036/1 "2020-06-26T15:42:21Z")

</div>

Hi,  
At a certain point in my flow and Code, I would like to know if the machine is working for the last two minutes or not  
I have Machine status tag: 1=OFF 0=ON  
how can I do that?

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [26 June 2020 16:08 UTC](https://discourse.nodered.org/t/check-out-the-last-two-minutes/29036/2 "2020-06-26T16:08:05Z")

</div>

Can you explain a bit more please?

Have you got a flow that you can show us?

---

<div class="post-metadata">

**Author:** ![Hasan90](https://avatars.discourse-cdn.com/v4/letter/h/46a35a/32.png) [@Hasan90](https://discourse.nodered.org/u/Hasan90)\
**Post date:** [26 June 2020 16:38 UTC](https://discourse.nodered.org/t/check-out-the-last-two-minutes/29036/3 "2020-06-26T16:38:48Z")

</div>

![Flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/6/165e41db97042fc1609f4f5f2b8bd0b8a2a8b6a6.png)

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [26 June 2020 17:39 UTC](https://discourse.nodered.org/t/check-out-the-last-two-minutes/29036/4 "2020-06-26T17:39:51Z")

</div>

One suggestion is to have 2 outputs from the TDS out of range switch node

1 output if its out of range, going to a trigger node that sends nothing then waits two minutes and then sends a message

The other output from the switch should be if the TDS IS in range - feed that to a change node and delete msg.payload and add in a msg.reset = true and then send that into the trigger node as well

I think that will work but if not - it should give you an idea on how to get going

---

<div class="post-metadata">

**Author:** ![Hasan90](https://avatars.discourse-cdn.com/v4/letter/h/46a35a/32.png) [@Hasan90](https://discourse.nodered.org/u/Hasan90)\
**Post date:** [26 June 2020 18:46 UTC](https://discourse.nodered.org/t/check-out-the-last-two-minutes/29036/5 "2020-06-26T18:46:30Z")

</div>

For example:  
At time = 10:45:00 TDS value is out of range.  
I want to send a notification email if the filler is running continuously from 10:43:00 to 10:45:00

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [26 June 2020 20:57 UTC](https://discourse.nodered.org/t/check-out-the-last-two-minutes/29036/6 "2020-06-26T20:57:12Z")

</div>

You need to set a time when the fill starts or otherwise create some time frame for reference. For instance - fill starts at 10:00:21, then when it goes out of range check if current time is greater than 2 minutes. Look at context and how to save a variable.  
when fill starts get the time and save it.  
let currentTime = new Date();  
let hours = currentTime.getHours();  
let minutes = currentTime.getMinutes();  
let seconds = currentTime.getSeconds();  
if (minutes \< 10) {  
minutes = "0" + minutes;  
}  
if (seconds \< 10) {  
seconds = "0" + seconds;  
}  
let z = hours + ':' + minutes + ':' + seconds;

context.set('fill\_start', z)

Then when you need to check and see if the time is greater than two minutes --  
let currentTime = new Date();  
let hours = currentTime.getHours();  
let minutes = currentTime.getMinutes();  
let seconds = currentTime.getSeconds();  
if (minutes \< 10) {  
minutes = "0" + minutes;  
}  
if (seconds \< 10) {  
seconds = "0" + seconds;  
}  
let z = hours + ':' + minutes + ':' + seconds;  
let y = context.get('fill\_start')  
is z - y greater than two minutes?  
There is an easier / quicker way to get the time but I want to show a more complete explanation. Do whatever is quicker or easier for you.  
There are other ways to save the variables as well, look at context saves, flow save or global saves to see which fits you the best.  
This is off the top of my head so there may be some syntax issues but the general idea is sound. And of course this is one of what is probably numerous ways to solve it.  
For instance you could just use epoch time to do the math and it would be much simpler than the above. That would be get epoch time when fill starts, save it. When you need to check for two minutes get epoch time again then subtract.

---

<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:** [27 June 2020 20:08 UTC](https://discourse.nodered.org/t/check-out-the-last-two-minutes/29036/7 "2020-06-27T20:08:47Z")

</div>

I would vote for @cymplecy's concept using a Trigger node so you always know whether it has be running for the last two minutes or not.

---

<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:** [26 August 2020 20:08 UTC](https://discourse.nodered.org/t/check-out-the-last-two-minutes/29036/8 "2020-08-26T20:08:54Z")

</div>

Closed on 26 August 2020 20:08 UTC

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