Variable Wakeup-Time Sequence

A more common way to solve this issue:

rule "wakeup"

when
	Item wakeup_Felix_hour changed or
	Item wakeup_Felix_minute changed 
then
	wakeupTimer?.cancel
    var Integer nHour = null
    var Integer nMinute = null
    if(wakeup_Felix_hour.state instanceof Number) nHour = wakeup_Felix_hour.state as Number
    if(wakeup_Felix_minute.state instanceof Number) nMinute = wakeup_Felix_minute.state as Number
    logInfo("wakeup", "Starting timer {}:{}",nHour,nMinute)
    if(nHour === null || nMinute === null) {
        logWarn("wakeup","Time not set!")
        return;
    }
    wakeupTimer = createTimer(now.plusDays(1).withTimeAtStartOfDay.plusMinutes(nHour*60 + nMinute), [|
		logInfo("wakeup", "Time is up")
		wakeupTimer = null
    ])
end

withTimeAtStartOfDay is Midnight, plusMinutes adds the given amount of Minutes.

Please always ensure that type of data is correct to avoid null-pointer-exceptions.

1 Like