How to schedule a handler that running everyday at 00:00 based on the hub location timezone?

Hi Guys,

Need some guide on how to schedule a handler that running everyday 00:00 based on the hub location timezone?

example code

def someEventHandler(evt) {
   def now = new Date().format("dd MMM yyyy hh:mm:ss a", location.timeZone) // This function use to get date time in current location timezone
   def startDay = "00:00" // I want to start to run the handler everyday at 00:00 with current location timezone
   schedule(startDay, handlerMethod)
}

def handlerMethod() {
   ...
}

Or is there any available API from SmartThings that provide same function?
like runInDay(somehandler)?

You can find the related Scheduling APIs and examples in the API docs here:
http://docs.smartthings.com/en/latest/smartapp-developers-guide/scheduling.html

Yes, I did, the API that match my question is schedule(), but I have no idea how to run the handler once a day at 00:00 based on hub location time.

I’m pretty sure that it already takes into account the Time Zone of the hub, so you can use any of the methods that rely on time. What about just using the cronExpression version and setting it to run that way.

Btw, using midnight is always dangerous anyway since you could get a double fire around daylight savings times. See the notes here: http://quartz-scheduler.org/documentation/quartz-1.x/tutorials/crontrigger

So based on this code

def someEventHandler(evt) {
   def now = new Date().format("dd MMM yyyy hh:mm:ss a", location.timeZone) // This function use to get date time in current location timezone
   def startDay = "00:00" // I want to start to run the handler everyday at 00:00 with current location timezone
   schedule(startDay, handlerMethod)
}

def handlerMethod() {
   ...
}

What what would be the value for the startDay?

And how to use cronExpression on SmartApp?

user this I believe:

schedule("0 0 0 * * ?", handlerMethod)

Thanks @StrykerSKS, will try this out :smile: