Check out the last two minutes

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?

Can you explain a bit more please?

Have you got a flow that you can show us?

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

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

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.

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.

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