[Solved] createTime does not work for openHAB3 without error log

Hi,

I have a problem with a rule which I have copied from my openhab 2 conf. The rules are working but not the created timers, but there are also no log entries. What happens? Or better, why does not happen anything related to the timers?

var Timer rasenTimer
var Timer beetTimer

rule "Teichpumpe_auto"
when
    Item MQTTHochbeet_Lufttemperatur changed
then
    if (AutomatikTeichpumpe.state == ON && MQTTHochbeet_Teichpumpe.state == OFF && 
    (MQTTHochbeet_Lufttemperatur.state as Number) > ((GrenzwertTempTeichpumpe.state as Number))) 
    {
	    MQTTHochbeet_Teichpumpe.sendCommand(ON)
    }
    if (AutomatikTeichpumpe.state == ON && MQTTHochbeet_Teichpumpe.state == ON && 
    (MQTTHochbeet_Lufttemperatur.state as Number) < ((GrenzwertTempTeichpumpe.state as Number))) 
    {
	    MQTTHochbeet_Teichpumpe.sendCommand(OFF)
    }
end

rule "Rasenbewaesserung_auto"
when
    Channel 'astro:sun:local:nauticDawn#event' triggered START
then
    if (AutomatikBeregnung.state == ON && (MQTTHochbeet_Rasenfeuchtigkeit.state as Number) < (GrenzwertFeuchteRasen.state as Number)) {
        MQTTHochbeet_Rasenbewasserung.sendCommand(ON)
        val telegramAction = getActions("telegram","telegram:telegramBot:myBot")
        telegramAction.sendTelegram(-XXXXXL,"Es ist zu trocken. Ich habe für Euch die Rasenbewässerung EINgeschaltet")
    }
end

rule "Rasenbewaesserung_aus"
when
    Item MQTTHochbeet_Rasenbewaesserung changed
then
    if (MQTTHochbeet_Rasenbewasserung.state == ON) {
        val myDauer = BeregnungsdauerRasen.state as Number
        val intDauer = myDauer.intValue
        rasenTimer = createTimer(now.plusMinutes(intDauer)) [
            MQTTHochbeet_Rasenbewasserung.sendCommand(OFF)
            val telegramAction = getActions("telegram","telegram:telegramBot:myBot")
            telegramAction.sendTelegram(-XXXXXXL,"Die Regenwürmer beschweren sich schon. Ich habe für sie die Rasenbewässerung AUSgeschaltet")
            if (AutomatikBeetbewaesserung.state == ON) {
                MQTTHochbeet_Beetbewasserung.sendCommand(ON)
                telegramAction.sendTelegram(-XXXXXXXL,"Nun wird das Beet bewässert.")
            }
        ]
    } else {
        if (rasenTimer!==null) {
            rasenTimer.cancel
            rasenTimer = null
        }
    }
end

rule "Beetbewaesserung_aus"
when
    Item MQTTHochbeet_Beetbewaesserung changed
then
    if (MQTTHochbeet_Beetbewasserung.state == ON) {
        val myDauer = BeregnungsdauerBeet.state as Number
        val intDauer = myDauer.intValue
        beetTimer = createTimer(now.plusMinutes(intDauer)) [
            MQTTHochbeet_Beetbewasserung.sendCommand(OFF)
            val telegramAction = getActions("telegram","telegram:telegramBot:myBot")
            telegramAction.sendTelegram(-XXXXXXXL,"Die Regenwürmer beschweren sich schon. Ich habe für sie die Beetbewässerung AUSgeschaltet")
        ]
    } else {
        if (beetTimer!==null) {
            beetTimer.cancel
            beetTimer = null
        }
    }
end

Do you use them in UI or in file based rules ?
Global variables like rasenTimer, beetTimer are not supported in UI rules.
See e.g.

How can you tell? The first thing I’d do is add some logInfo() to the rules, see what time value you are using when you create the timer. And another as first line of timer code, see when it runs.

Note that you’re not dealing with use of the timer-handle very neatly. You don’t check if it is null before creating a new timer, you don’t set it to null in the timer code after a run.

@rossko57: Thanks a lot.
I added some logInfo to the rules and also checked for null.
The rules do not even start. There was an error in the when condition…

1 Like

May we know what the error was? Might help someone else in future.