'time' is not a member of 'java.time.ZonedDateTime'

Hi all, did not maintain my openhab installation for some time, as it was running fine for years . After finally updating from 2.x. to 4.3.7 it seems that my wallbox script for PV charging does not run properly. The log is getting filled with:

2025-10-04 06:06:53.997 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID ‘goe-1’ failed: ‘time’ is not a member of ‘java.time.ZonedDateTime’; line 33, column 27, length 52 in goe

The corresponding line in the rule is

    lastBelow6A = SE25K_Live_Export.previousState(true).timestamp.time

I read that the format of representing time changed in 3.x, but I did not find out how to convert the above line to work with the new format …

Can someone help?

What rule type are you using?

In jsscripting (which is generated by blockly) you can just do

var mytime = items.getItem(‘garten_temperature’).persistence.previousState(true)?.state;

What exactly do you want to do with the time?

if (newPower < 4140) { // 6A - 3 phase
        if (GoEChargerAllowCharging.state === OFF) { // WB is already switched off, nothing todo
            return
        }

        newPower = 4140 // set current to 6A 3 Phase which is lowest charging speed available
		        
        if (lastBelow6A == 0) {
            // store time when below 6A for 1st time
            lastBelow6A = SE25K_Live_Export.previousState(true).timestamp.time
        }

        val secondsBelow6A = (now.millis - lastBelow6A)/1000
		logInfo("Wallbox", "secondsBelow6A = " + secondsBelow6A)

        if (secondsBelow6A > switchOffTimeout) {
            logInfo("Wallbox", "Below 6A for " + secondsBelow6A + "s, switching off.")
            GoEChargerAllowCharging.sendCommand(OFF)
            return
        }
    } else {
        lastBelow6A = 0
        if (GoEChargerAllowCharging.state === OFF && availablePower > 5000) {
            GoEChargerAllowCharging.sendCommand(ON)
        }
    }

This is the whole part where the timestamp is used. The aim is to stop charging if the available power from PV is below 4kw for a specific time …

Did you try what I posted above?

Try this:

        
        if (lastBelow6A == 0) {
            // store time when below 6A for 1st time
            lastBelow6A = SE25K_Live_Export.previousState(true).timestamp.toEpochSecond
        }

        val secondsBelow6A = now.toEpochSecond - lastBelow6A

See ZonedDateTime (Java SE 21 & JDK 21)

This works fine, thanks for your support!