Scheduling via cron

I am having an issue getting a scheduled cron job to run that is for a specific time on a day of the week.

My cron job looks like: “44 14 * * 4 ?”

This should be 44min after 2pm on Thursday however I can not seem to get it to execute ever. I attempted to apply my EDT -4 modification to “44 10 * * 4 ?” but that had no effect either. I can see in the log that the scheduling is being created . Any assistance would be greatly appreciated.

I reviewed some of the suggested replies on the forum but they are from 2013 and appear to be less than helpful.

I think this should work: "0 44 14 * * 5 ?"
Here is the syntax
http://quartz-scheduler.org/documentation/quartz-1.x/tutorials/crontrigger

@stephchen

That string provided me an invalid string error.

I then tried a few direct examples from that website dealing with days of week including “0 15 10 ? * MON-FRI” and also got invalid errors. Perhaps the implementation in ST is lacking on day of week support? I really didn’t want to make a poller that checks the current day of the week since cron jobs are superior and require less overhead. I even tried replacing MON-FRI with 1-5 or just a numerical day representation and had the same result.

All my other schedulers run just fine it is the one that is specific for a day of the week.

Basically I am working on an Irrigation app and need to say start watering at X time on Y days of the week.

Perhaps the implementation in ST is lacking on day of week support

Perhaps. I seem to remember someone had the same trouble. I have never used day of week myself so can’t say for sure.

The docs refer to some schedule examples:

http://docs.smartthings.com/en/latest/smartapp-developers-guide/scheduling.html

And just in case…there is a SmartThings limitation of only 4 scheduled jobs per smart app that can be hard to debug if you aren’t looking for it:

To prevent any one SmartApp or device-type handler from using too many resources, only four jobs may be scheduled for future execution at any time.

It doesn’t appear that any of the advance examples dealing with data after the ? field are working. I have instead created a function that checks the current time/date then schedules the next day to water the plants from that date as a single scheduled date. The recurring days-of-week either silently fail or reject as a valid cron statement.

@Jim ? Sounds like the doc for this section may be out of date. (Ironic.)

1 Like

I am looking into it.

I think you’ve uncovered a bug in how we handle the day-of-week field with cron expressions.

For this specific case, to run at 2:44pm on Thursdays, you should be able to do:

'0 44 14 ? * 5'

The values here are:

  • 0 - seconds
  • 44 - minutes
  • 14 - hour (2pm)
  • ? - day-of-month, which should be ? if you are specifying day-of-week
      • month (all months in this case)
  • 5 - numerical value for Thursday (1 is Sunday)

Now, to make it easier, you should be able to replace that 5 with THU like this '0 44 14 ? * THU', but that is broken.

I am a little surprised that it was failing, but clearly it is. Some expressions work that use strings, like if you want to specify months, you could do '0 44 14 * JUN-AUG ?' and I think it would work. So it isn’t just that using string names are breaking it. Using ranges for the day-of-week is failing too, so it is something with that specific field. For example, this won’t work either '0 44 14 ? * 2-6' (which would be MON-FRI). Basically we try to validate if the expression is a valid cron, and our validation isn’t currently correct. I’m looking into it now.

@matthewnohr thank you very much for getting back to me on this. I had tried converting the strings to integers (MON = 1 though) but with a different cron format that you presented here. I will give this a try.

On another note I found creating the “Days” function in the SmartApp to check if it was a valid day worked just as well.

Im not sure why you want to hard code the job timing in your app, but here is some code that can get the samething done w/o cron.
You can set any day or days of the week and time. Feel free to tweak.

I identified the problem and submitted a fix. It should be available/fixed next week.

Until then, you can do something like @sidjohn1 shared, which will work well. Or if you want the cron, you can use the numbers 1-7 (1 = Sunday) as the day-of-week part.

Thanks for pointing this out!

3 Likes

This should be fixed now.

2 Likes