1

In order to set an alarm from the GUI I would like to pass a variable as the argument to cron.

This works:

rule "Wake up"
when
  Time cron "00 00 06 * * ?"
then
  // ...
end

This does not work:

var morning = "00 00 06 * * ?"

rule "Wake up"
when
  Time cron morning
then
  // ...
end

Should this be possible to do?

Markus
  • 809
  • 5
  • 10

1 Answers1

0

The Cron string cannot be changed, but I use this code to get around it:

import org.joda.time.Duration
import org.quartz.CronExpression

var Timer wateringtimer = null

// Start watering at 03:00 AM, all days except Saturday (5)                               
val wateringCronString = "0 0 3 ? * 1,2,3,4,5,6"
...
rule "Set Cron" 
...
var cronExpression = new CronExpression(wateringCronString)
var triggerTime = cronExpression.getNextValidTimeAfter(now.plusMinutes(1).toDate)
Seconds::secondsBetween(now,new DateTime(triggerTime)).getSeconds()
if (watertimer !== null) 
  watertimer.cancel()

wateringtimer = createTimer(now.plusSeconds(diff),
    [
        ...Do something... 
    ])
Tom
  • 1