Timer error after oh3 install

Dunno. What makes you think the error is that piece of code? The code shown is incomplete, missing } and ] and ).

@rossko57 sorry I already posted the code in my first post. The brackets are all there, There is no general issue message that sth. in the code is wrong thatswhy I assume that it is related to the number format.

here the code:

var Timer Lichtweckertimer      = null

rule "Schlafzimmer morning alarm Radio"
    when
        Item Lichtwecker_Osram changed
    then
        if(Lichtwecker_Osram.state == ON) {
            var Number sollMinuten                                                                        // define var
            if(Lichtschlauch_Wecker_H.state instanceof Number)                                            // check if value valid
                sollMinuten = (Lichtschlauch_Wecker_H.state as Number).intValue * 60                      // set var
            else 
                sollMinuten = -61                                                                         // mark as invalid
            if(Lichtschlauch_Wecker_M.state instanceof Number)                                            // check if value valid
                sollMinuten = sollMinuten + (Lichtschlauch_Wecker_M.state as Number).intValue             // set var
            else 
                sollMinuten = -1                                                                          // mark as invalid
            if (sollMinuten >= 0 ) {                                                                      // check if time valid
                Lichtweckertimer?.cancel    
                logInfo("Test0", "T0 {}",sollMinuten)                                                              // cancel existing timer
                if (sollMinuten <= (now.getHour * 60 + now.getMinute)){
                    logInfo("Test1", "T1 {}:{}",sollMinuten, (now.getHour * 60 + now.getMinute))        
                    sollMinuten = 1440 - (now.getHour * 60 + now.getMinute ) + sollMinuten }
                else {
                    sollMinuten = sollMinuten - ( now.getHour * 60 + now.getMinute )
                    logInfo("Test2", "T2")}
                logInfo("Test3", "T3 {}",sollMinuten)
                Lichtweckertimer = createTimer(now.plusMinutes(sollMinuten.longValue) , [|
                    if((ZigLightstrip_2.state as Number) < 91 && (ZigLight1_Dimmer.state as Number) < 91) {                                      // check Level
                        ZigLightstrip_2.sendCommand((ZigLightstrip_2.state as Number) + 10) 
                        ZigLight1_Dimmer.sendCommand((ZigLight1_Dimmer.state as Number) + 10)       // Increase Level by 10 fĂŒr deckenfluter und bettlicht
                        Lichtweckertimer.reschedule(now.plusMinutes(1))                                // Reschedule Timer
                    } else {                                                                              // or
                        Lichtwecker_Osram.sendCommand(OFF)                                                // switch Wecker off
                        logInfo("morningAlarm", "Wakeup finished")
                        if (Sonos_Radio_Wecken.state == ON) {
                                timer_Sonos_WakeUp?.cancel
                                timer_Sonos_WakeUp = createTimer(now.plusSeconds(5),[|
                                    Sonos_ONE1_Volume.sendCommand(10)
                                    Sonos_ONE1_TuneInID.sendCommand("24878")
                                ]) 
                        }
                    }
                ])
                logInfo("morningAlarm", "Wecker erstellt fĂŒr {}:{} Uhr",Lichtschlauch_Wecker_H.state,Lichtschlauch_Wecker_M.state)              
            } else {
                logWarn("morningAlarm", "Stunde oder Minute haben keinen gĂŒltigen Wert!")
            }
        } else {
            Lichtweckertimer?.cancel
            logInfo("morningAlarm", "Wecker ausgeschaltet")
        }
end

Ignore the LogInfo “Tests” they are just for me understanding what value “SollMinuten” is at a specific stage.

Sorry again that I did not send the code completely.

Kindly,

Woogi

Yes, but you’ve changed it since then.

Not at all - that’s what they’re for, following the path and showing the values.

Errors in Timer code are often unhelpful, this one very much in that category.
We can make some deductions though

From the log timestamp 14:41:57.457
to the WARN timestamp 14:43:57.443
is two minutes, so it looks like your Timer was set up okay and executed when expected. The problem lies within the code being executed.

This looks suspiciously like something is trying to parse a number from text, but doesn’t understand a German language decimal “,”

You could add some more logInfo() to see where it gets to before the error. My guess is one or both of those sendCommand().
DSL can be picky about sending objects, even numbers, as commands. Safe way is to send the string version.

ZigLightstrip_2.sendCommand(((ZigLightstrip_2.state as Number) + 10).toString)

Maybe ZigLightstrip_2 isn’t a Dimmer Item at all but of type Color? Color would have a , in the status


1 Like

I’m having a similar issue as the OP, so rather than creating a new topic I thought I’d add to this one.

This is the error I get, which is the same as the OP received. Having looked at all of the replies I don’t see a valid solution to the issue.

An error occurred during the script exe
cution: Could not invoke method: java.time.ZonedDateTime.plusMinutes(long) on instance

This is part of the rule I have in place that is causing the above error.

    createTimer(now.plusMinutes(Random_FifteenMinutes.state as Number).intValue) [|
        Announcement_Type.postUpdate(1)
    ]

For completeness here is how I have the item defined.

Number Random_FifteenMinutes "[%d Minutes]" <time>

I have tried all the different combinations mentioned in the topic and still haven’t managed to get this rule working as it should. My assumption is that the Number stored in the item is a Decimal and I need it to be an Integer for the rule to work as it should, but clearly haven’t found the right syntax to us and need some help.

Thanks,

Garry

Careful with the brackets - that is trying to get the intValue of plusMinutes

OK, thanks for that information. So how do I resolve my issue as clearly I have the wrong syntax and not getting any closer to finding the answer.

Break it down.

(now.plusMinutes
    (Random_FifteenMinutes.state as Number)
.intValue)

If we simplify this as written by hard coding the value from the Item to 5 it would be:

now.plusMinutes(5).intValue

That doesn’t make sense, a ZonedDateTime doesn’t have an intValue. You want to pass the intValue to plusMinutes.

You want

(now.plusMinutes
    (
        (Random_FifteenMinutes.state as Number).intValue)
    )
)

or

(now.plusMinutes((Random_FifteenMinutes.state as Number).intValue))

Or another way to break it down:

val randState = Random_FifteenMinutes.state
val randNum = randState as Number
val randInt = randNum.intValue
now.plusMinutes(randInt)

Or a little less broken down

val rand = (Random_FifteenMinutes.state as Number).intValue
nhow.plusMinutes(rand)

Thanks @rlkoshak as all ways a very detailed explanation. I’ve gone with the below syntax and it’s working just as I hoped.