There are a bunch of places in the code where I have to covert between minutes/seconds/milliseconds in a few different sets. I figured I’d try to avoid making mistakes and use java.util.concurrent.TimeUnit I didn’t see it on the list of things not allowed in the sandbox
That said when I try to use TimeUnit I get the following error in my logs: Getting properties on class java.lang.Class is not allowed
The existing code should handle dropping to idle. That’s what “Minimum amount of below wattage time to trigger off” represents and functions as since most machines obviously idle for a brief period during the load. You would simply make that var longer than your longest idle and it skips those. It delays the actual notification, but knowing when the laundry is done isn’t exactly something that has to be accurate to the second.
Regardless though, Groovy isn’t a fully fledged java language and most of the built in functions of java won’t be available. Did you try an import call?
So the existing code didn’t handle the case where the power values go something like:
HHHLLLHHHLLLHHHLLL
....^...........^.
If the time between those two carrots was 60s then the existing code claims that the laundry is done. What I added is some more state tracking so that if the power goes high after a low it resets the last-low timestamp.
I also added a callback and a timer to check if the value is still low after the timeout. The other behavior I saw with the original script is that my drier would be done and just turn off. It would only have a few seconds below the min power threshold. Since the original app only checked/updated on power change events this meant I never actually got the alert that laundry is done. That may be to different hardware, I’m using the SmartThings Outlet which only sends power events when the power value changes.
I did have the import, here is the commit I removed it in. The SecurityException is something that would be thrown by the SmartThings sandbox due to how they have the Java PolicyManager configured. Things that are valid Java but not valid Groovy are more gotchas like new keywords, array initialization, etc.