I’m new to writing apps for SmartThings. I’m trying to detect if a contact sensor was in an open state within a specified timeframe. The code below isn’t working reliably. If the log trace shows recent events, doorWasOpen is still false. The code is mostly copied from and modified from “It’s Too Cold”. Can someone explain the use of the {it.value == “”}
Thanks
def deltaMinutes = 10
def timeAgo = new Date(now() - (1000 * 60 * deltaMinutes).toLong())
def recentEvents = contact.eventsSince(timeAgo)?.findAll { it.name == "open" }
log.trace "Found ${recentEvents?.size() ?: 0} events in the last $deltaMinutes minutes"
def doorWasOpen = recentEvents.count { it.value == "open" } > 1