How to create a timer/delay in Thingsboard rule chain?

I have a device that outputs the following telemetry onto thingsboard: pressure (number), flow (number), and flushing(0 or 1). Below is the semi-pseudo code that I want to implement through the rule chain using the script nodes. Currently, I am trying to store the time as a server attribute/metadata and compare the values after 30 seconds, but I have been unsuccessful. Any help is appreciated!

// create alarm when below criteria is met

// when flushing occurs
// wait 30 seconds
// after 30 seconds check values of pump1 & pump2 statuses & pressure value
// if all criteria is met
// return true (send to create alarm node)
// else return false

var FLUSHING_DURATION = 30 *
1000; // 30 seconds in milliseconds

// Retrieve the flushing start time from the metadata
var flushingStartTime = metadata.flushingStartTime;

if (msg.flushing==1) {
if (flushingStartTime === undefined ||
flushingStartTime === null) {
// If flushing is active and we don't have a start time, set it
flushingStartTime = Date.now();
metadata.flushingStartTime = flushingStartTime;
console.log(flushingStartTime);
}
} else {
// If flushing is not active, reset the start time
flushingStartTime = null;
metadata.flushingStartTime = null;
}

if (flushingStartTime && Date.now() - flushingStartTime >=
FLUSHING_DURATION) {
// Check conditions after 30 seconds of flushing
return msg.pressure1_psi < 40 && msg.pump1_status ===
2 && msg.pump2_status === 2;
}

return false;