Hello,
Is this normal that this code below can take between 1 up to 10 seconds and even more sometimes to execute (whether it's with one or 3 iterations)? I added a time stamp before and after its execution to figure this out. Once these lines written, my hub would become painfully unresponsive and back to normal once commented out.
Here is my question: despite this instance involving only 3 devices, is it a known thing that such code would inherently take so much ressource or am I doing something wrong?
logging("motion test is running and collecting events at $motionSensors")
long deltaMinutes = noMotionTime * 1000 * 60
int s = motionSensors.size()
int i = 0
def before = new Date()
before.format("yyyyMMdd-HH:mm:ss.SSS", TimeZone.getTimeZone('UTC'))
log.info "Before the shit happens: ${before}"
for(s != 0; i < s; i++)
{
// as soon as I would comment out this line below, the bug would become responsive again.
thisDeviceEvents = motionSensors[i].eventsSince(new Date(now() - deltaMinutes)).findAll{it.value == "active"} // collect motion events for each sensor
events += thisDeviceEvents.size()
events += thisDeviceEvents.size()
}
def after = new Date()
after.format("yyyyMMdd-HH:mm:ss.SSS", TimeZone.getTimeZone('UTC'))
log.info "AFTER the shit happened: ${after}"