With the recent webcore issues and chatter around performance, I'm starting to try and move some of my simpler pistons to native HE.
One simple one I'm struggling with is this. I can't set such a short timer (10 seconds) and I dont seem to be able to set the color tempreature using simple lighting/rule machine.
I think this should work. In most cases you shouldnt need the "Turn on". Set Level should automatically turn the light on to the level specified. Ignore the FADE part...I must have clicked that by miistake.
I've deleted my original post, because, although I can't explain why, I I ended up moving this out of the hue group being controlled by the by the switch. What I cant explain is why the switch would operate after a power cycle correctly... and why it only started occurring when I moved this from webcore to rule engine. But I dont think it has anything to do with Hubitat - perhaps a coincidence on timing.
Can I ask why? In ST, I recall the unschedule function was reported to be expensive/slow--is it the same on Hubitat? Or are you just suggesting that the flow would be cleaner if that's how the code worked? (Asking because, like the original poster, I'm about to port some lighting pistons to native apps. I already have the logic worked out if I can use unschedule but want to avoid anything slow or otherwise not recommended on the platform. )
I ran a quick test from above and it looks like it takes 4-8ms to unschedule in the example above on my hub:
def motionHandler(evt){
runIn(turnOffAfter, "noMotion")
def start = now()
unschedule()
log.debug "Unschedule called in ${now() - start}ms"
}
[app:2025](http://192.168.2.124/logs#app2025)2018-08-31 20:59:36.294:debugUnschedule called in 5ms
[app:2025](http://192.168.2.124/logs#app2025)2018-08-31 20:59:34.701:debugUnschedule called in 4ms
[app:2025](http://192.168.2.124/logs#app2025)2018-08-31 20:59:23.985:debugUnschedule called in 6ms
[app:2025](http://192.168.2.124/logs#app2025)2018-08-31 20:59:22.945:debugUnschedule called in 8ms
I'm not sure what the typical response time was in ST. I know unschedule was expensive, though, and was typically only used in the installed and updated methods for performance reasons from what I've read.
@mike.maxwell I'm creating my own occupancy app that is coded similarly to @jp0550. If we set a state variable to hold the the status of the motion sensor, it would only tell the noMotion method the state at the time that method is run (after the delay). Wouldnt we want the motion active event to cancel the scheduled noMtion method altogether? Otherwise it would run if the motion happens to go inactive just before the end of the timeout.
An earful I know...hard to put in words but I hope you get the jist.
I forgot about this important part of the equation. I was thinking a bunch of events would be scheduled even if they didn't fire because of an evaluation.
I'll give your code a shot sometime today. Thanks for posting.