Dusk-to-Dawn Dimming Motion Light - RC1

Thanks for the feedback, @DITPL!

Yes, support for multiple motion sensors has been there since the original code @pstuart put together. However, I have never tested this and really haven’t thought about how this would work. I think I need to add one line of code, unschedule(modeDim):

def handleMotionEvent(evt) {
	log.debug "handleMotionEvent() Motion detected . . . ."
    
    if (state.ambient == "dark") {
    	switches?.setLevel(state.BrightLevel)
        state.Level = state.BrightLevel

        unschedule(modeDim)   //in case motion has stopped on another motion sensor and modeDim was scheduled

    	log.debug ". . . set the dimmers to level $state.BrightLevel"
    }
    else 
    {
    	log.debug ". . . but its light, so do nothing"
    }
}

This handles the scenario where one motion sensor posts a ‘motion stopped’ event, modeDim() is scheduled, however, in the meantime, the other sensor post a ‘motion’ event. In this case, you would want to cancel the scheduled modeDim(), Actually, now that I’m thinking about it, this should be the case even if there is only one motion sensor . . . that is, if motion is sensed during the time delay between motion ending and the modeDim() call, the call should be cancelled. The modeDim() call should be based on the motion stopped event of the last sensor that sensed motion.

I’m going to chew on this before I commit the change but if you want to try it, please do so and report back.

EDIT: After looking into this, I determined I just needed to move the unschedule(modeDim) from the handleEndMotionEvent() handler to the handleMotionEvent() handler. This should now correctly handle the case of motion being sensed during a delay before dimming - regardless of how many motion sensors are used. I have update the code on GitHub and that’s what you will get if you follow the link I have earlier on this thread. Thanks, @DITPL for bringing this up.