Where to put create a schedule?

devicetype
schedule

(Peter Sun) #1

I am creating a device handler and I want to run a method every week. Where in the device handler do I create the schedule? I currently have it in the initialize function:

def initialize() {
schedule(“0 0 23 ? * SUN *”,someFunction())
}


(codersaur) #2

My Fibaro Dimmer 2 DTH has a schedule to manage the nightmode feature. I encapsulated the unshedule() and schedule() calls in a private helper function manageSchedules(), which I decided to trigger from the updated() method, as the user needs to set a time for the schedule in the settings page and updated() runs after any settings are saved. There’s no harm in calling it from the installed() command too, which is run after the device handler is installed.