below is some sample code with some commented areas to help ask the question, note: this code is written only to help the conversation. Once I get the answer, I’ll write finished code back so everyone can see it*
preferences {
section(“When there’s movement anywhere…”) {
input “allmotion”, “capability.motionSensor”, title: “What Motion Sensors”, multiple: true
}
}
def installed()
{
subscribe(allmotion, “motion.active”, motionActiveHandler)
}
def updated()
{
unsubscribe()
subscribe(allmotion, “motion.active”, motionActiveHandler)
}
/* start commenting code improvement question…
**instead of forcing user to select all motion sensors can the smartapp
**schedule once a day to resubscribe to allmotion sensors in case an new
**one was added that day. Something like this:
def someEventHandler(evt) {
** execute handler in 24 hours from now
runIn(60*24, handler)
}
def handler() {
//get the global list of allmotion sensors then …
unsubscribe()
subscribe(allmotion, “motion.active”, motionActiveHandler)
}
**end code improvement question/idea */
def motionActiveHandler(evt) {
//do something for all motion events
//log all motion events over time
}