Timer error after oh3 install

Got any old datetime related imports at the head of that file?
Log out sollminuten to see what you are doing.
Check you are looking at the correct rule - the second one in that file.

@rossko57 thank you for the reply.

I only define var’s at the head of the file.
sollMinuten is providing e.g. 1252 before creating the timer. I log it at three points, this is a correct value. Is it in a wrong format? Second rule is correct. puh :slight_smile:

No sign of that or the results in what you’ve shown us.
But don’t care really; what is its .intValue version just before you feed that to plusMinutes()?

@rossko57 right, I did hide those lines, sorry. Thought that wouldn’t be interesting. I log at three positions.

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.getMinute
                    logInfo("Test2", "T2")}
                logInfo("Test3", "T3 {}",sollMinuten)
                Lichtweckertimer = createTimer(now.plusMinutes(sollMinuten.intValue) [|

What do you mean with .intValue version? the first time I feed sollMinuten is

if(Lichtschlauch_Wecker_H.state instanceof Number)                                            // check if value valid
                sollMinuten = (Lichtschlauch_Wecker_H.state as Number).intValue * 60   

at the beginning of the rule. I take it from number and convert it to .intValue. Did you mean that? Log info output for SollMinuten just before the timer creation failed was based on input parameter 1252 in my last case.

That’s what I meant.

There are subtle differences in Java version, I think you’ve run into one of them.
Try
createTimer(now.plusMinutes(sollMinuten.longValue)

Hey @rossko57,

after changing the line to Lichtweckertimer = createTimer(now.plusMinutes(sollMinuten.longValue) [| I receive a different issue notification:

2021-05-17 21:42:39.144 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'zigbee-2' failed: An error occurred during the script execution: index=1, size=1 in zigbee

Do you have a further idea?

Nope. Change it back if you think that’s the problem.

@Udo_Hartmann do you have an idea? You helped me two years ago with the rule the first time to get it running.

Searching this forum for “script execution: index=1, size=1” leads to

2 Likes

Jepp, that’s the point.

Lichtweckertimer = createTimer(now.plusMinutes(sollMinuten) [| 
                                                          /\----- missing comma
1 Like

@rossko57 @Udo_Hartmann thank you both, that helped. Recently I adjusted the code and the issue message is gone.

I am facing now the problem, that the creation of the timer is not working:

e.g. I have created a message T3 that tells me the value of SollMinuten calculated for 2 Minutes. So the system should create the timer for 2 Minutes. SollMinuten was created as .intValue.

2021-06-20 14:41:57.438 [INFO ] [org.openhab.core.model.script.Test3 ] - T3 2
2021-06-20 14:41:57.457 [INFO ] [enhab.core.model.script.morningAlarm] - Wecker erstellt für 14:43 Uhr

But I receive the following break up:

2021-06-20 14:43:57.443 [WARN ] [ore.internal.scheduler.SchedulerImpl] - Scheduled job failed and stopped
java.lang.NumberFormatException: Character , is neither a decimal digit number, decimal point, nor "e" notation exponential mark.

This is the code at this position of code:

                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

Where is my mistake? Do I have to transform the “2” again?

thank you in advance :slight_smile:

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.