Rules with Timer OH3 after Update from OH2

Hello Folks,
i want to update to OH3 but i have many timers an such sort of things. After the update all of this stop working.
What type of changes do i need?
My working OH2 Script looks is this

var Timer rueckfallzeitduschbad = null
var Timer duschbadlichttimer = null

//Bewegungsmelder

//Licht Duschbad
    rule "Licht Duschbad Rückfallzeit"
        when
            Item Duschbad_licht changed
        then
            if( Duschbad_licht.state != 0 ) {
                if (rueckfallzeitduschbad !== null){
                    rueckfallzeitduschbad.cancel()
                    rueckfallzeitduschbad = null
                    }   
                    else 
                    //logInfo("Duschbadlicht", "Rückfallzeit gestartet")
                    rueckfallzeitduschbad = createTimer(now.plusMinutes(60)) [| Duschbad_licht.sendCommand(0) rueckfallzeitduschbad = null]
        }
    else {
        //logInfo("Duschbadlicht", "Rückfallzeit zurückgesetzt")
        rueckfallzeitduschbad.cancel()
        rueckfallzeitduschbad = null
    }
    end

    rule "Licht Duschbad einschalten Präsenzsmelder"
        when
            Item Duschbadpraesenz_Status changed
        then
            if (Duschbadpraesenz_Status.state == 1){
                if(duschbadlichttimer !== null  ) {
                    //logInfo("Duschbadlicht", "Auscchalten Timer gestoppt") 
                    duschbadlichttimer.cancel()
                    duschbadlichttimer = null
                    }

                else
                    if(Tag_Nacht_Lichter.state== ON){
                        if((Helligkeit_Duschbad.state<60)&&(Duschbad_licht.state == 0)) {
                            //logInfo("Duschbadlicht", "Licht Tag an") 
                            Duschbad_licht.sendCommand(100)
                            }
                        }
                        else {
                            if((Helligkeit_Duschbad.state<60)&&(Duschbad_licht.state == 0)){
                                //logInfo("Duschbadlicht", "Licht Tag Nacht") 
                                Duschbad_licht.sendCommand(5)
                            }
                    }
            }
            else
            {
                if( duschbadlichttimer === null ) {
                    //logInfo("Duschbadlicht", "Ausschalten gestartet") 
                    duschbadlichttimer = createTimer(now.plusMinutes(5)) [| Duschbad_licht.sendCommand(0) duschbadlichttimer = null]
                }
            }
    end

The Item “Tag_Nacht_Lichter” is an switch that updated with this rule

rule "Lichter in Tag oder Nachtmodus schalten"
        when
            Item KNX_Zeit changed //NTP-Server Item
        then
if( (isWeekend == true) || (isBankHoliday == true) ) {
            if( (now.getHourOfDay == (Tag_Nacht_morgens_Stunde_Lichter_Wochenende.state as DecimalType).intValue)&&(now.getMinuteOfHour == (Tag_Nacht_morgens_Minute_Lichter_Wochenende.state as DecimalType).intValue)) {
                if (Tag_Nacht_Lichter.state != ON){
                    Tag_Nacht_Lichter.sendCommand(ON)
                    }
                
                }
                else
                if((now.getHourOfDay == (Tag_Nacht_abend_Stunde_Lichter_Wochenende.state as DecimalType).intValue)&&(now.getMinuteOfHour == (Tag_Nacht_abend_Minute_Lichter_Wochenende.state as DecimalType).intValue)  ) {
                    if (Tag_Nacht_Lichter.state != OFF){
                    Tag_Nacht_Lichter.sendCommand(OFF)
                    }
                }
            
            } 
        else {
            if( (now.getHourOfDay == (Tag_Nacht_morgens_Stunde_Lichter.state as DecimalType).intValue)&&(now.getMinuteOfHour == (Tag_Nacht_morgens_Minute_Lichter.state as DecimalType).intValue)) {
                if (Tag_Nacht_Lichter.state != ON){
                    Tag_Nacht_Lichter.sendCommand(ON)
                    }
                
             }
                else
                    if((now.getHourOfDay == (Tag_Nacht_abend_Stunde_Lichter.state as DecimalType).intValue)&&(now.getMinuteOfHour == (Tag_Nacht_abend_Minute_Lichter.state as DecimalType).intValue)  ) {
                        if (Tag_Nacht_Lichter.state != OFF){
                        Tag_Nacht_Lichter.sendCommand(OFF)
                        }
                    }

        }
        
        end

All other configuration works pretty fine on OH3 except my issue.

I hope anyone can help me.

Best regards

The underlying problem might be that joda time was changed to java time. As a result time conversion works differently. See DateTime Conversion (openHAB 3.x)

Without knowing what the error is, it is hard to tell.

The main thing is, to change now to ZonedDateTime.now, getHourOfMinute to getHour and getMinuteOdDay to getMinute. So

now.getHourOfDay

becomes

ZonedDateTime.now.getHour

Another thing is, I may be wrong, but I think your rules are more complex that necessary.

Last rule:

rule "Lichter in Tag oder Nachtmodus schalten"
when
    Time cron "0 * * * * ?"  // every Minute
then
    val nHour     = ZonedDateTime.now.getHour
    val nMinute   = ZonedDateTime.now.getMinute
    var nMHour   = Tag_Nacht_morgens_Stunde_Lichter.state as Number).intValue
    var nMMinute = Tag_Nacht_morgens_Minute_Lichter.state as Number).intValue
    var nEHour   = Tag_Nacht_abend_Stunde_Lichter.state as Number).intValue
    var nEMinute = Tag_Nacht_abend_Minute_Lichter.state as Number).intValue
    var Soll = Tag_Nacht_Lichter.state

    if(isWeekend || isBankHoliday) {
        nMHour   = Tag_Nacht_morgens_Stunde_Lichter_Wochenende.state as Number).intValue
        nMMinute = Tag_Nacht_morgens_Minute_Lichter_Wochenende.state as Number).intValue
        nEHour   = Tag_Nacht_abend_Stunde_Lichter_Wochenende.state as Number).intValue
        nEMinute = Tag_Nacht_abend_Minute_Lichter_Wochenende.state as Number).intValue
    }

    if(nHour == nMHour && nMinute == nMMinute)
        Soll = ON
    else if(nHour == nEHour && nMinute == nEMinute) 
        Soll = OFF

    if (Tag_Nacht_Lichter.state != Soll)
        Tag_Nacht_Lichter.sendCommand(Soll)
end

So, instead of using Items and States over and over again, use local vars to reduce complexity. define vars for hour and minute (for morning and evening) and set to weekday values. Now, only if weekend or holiday, change the values to those of weekend.
Please be aware that you don’t need to test for == true, as if() needs Boolean anyway.
Additional, use a var for the set value, initialize with actual state. Only if time is “correct”, set either to ON or OFF.
Now only send command if actual value differs from target value.

This is much less complex and more readable.

In question of the first and second rule, I’m pretty sure these two rules will suffice:

var Timer rueckfallzeitduschbad = null
var Timer duschbadlichttimer = null

//Bewegungsmelder

//Licht Duschbad
rule "Licht Duschbad Rückfallzeit"
when
    Item Duschbad_licht changed
then
    rueckfallzeitduschbad?.cancel()
    if(Duschbad_licht.state != 0 )
        rueckfallzeitduschbad = createTimer(ZonedDateTime.now.plusMinutes(60), [|
            Duschbad_licht.sendCommand(0)
        ])
end

rule "Licht Duschbad einschalten Präsenzsmelder"
when
    Item Duschbadpraesenz_Status changed
then
    duschbadlichttimer?.cancel()
    if(Duschbadpraesenz_Status.state == 1){
        if(Helligkeit_Duschbad.state < 60 && Duschbad_licht.state == 0) {
            if(Tag_Nacht_Lichter.state== ON){
                //logInfo("Duschbadlicht", "Licht Tag an") 
                Duschbad_licht.sendCommand(100)
            } else {
                //logInfo("Duschbadlicht", "Licht Tag Nacht") 
                Duschbad_licht.sendCommand(5)
            }
        }
    } else {
        //logInfo("Duschbadlicht", "Ausschalten gestartet") 
        duschbadlichttimer = createTimer(ZonedDateTime.now.plusMinutes(5), [| 
            Duschbad_licht.sendCommand(0) 
        )]
    }
end

i didn’t get it to work.
if i change the rules files OH3 doesnt recognize it and removed all rules in these files.

Is it possible to configure a rule over the new Rule UI that does the same things?

Ye-es, but why would you expect that to be any easier? Better to understand what is going on with your existing rule I’d have thought.

Why, what does it say?

Hi. trying to use the : val nHour = ZonedDateTime.now.getHour
val nMinute = ZonedDateTime.now.getMinute
in UI scripting (ecmascript) - but fail every try…

that’s DSL code, not ECMA