Blocky Rules with Datetime creating exeption

On startup, I want to set my alarm clock to 7:00:00 on that day. Sure, I could use persistence. But I decided on OH3 for this code. On OH4 I seem to get a exception:

2023-09-02 21:27:02.291 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'cc36c55e08' failed: org.graalvm.polyglot.PolyglotException: SyntaxError: <eval>:51:43 Expected an operand but found .
  neu = time.ZonedDateTime.now().withYear((.year())).withMonth((.monthValue())).withDayOfMonth((.dayOfMonth())).withHour((.hour())).withMinute((.minute())).withSecond(0).withNano(0);
                                           ^
<eval>:62:0 Expected eof but found }
}
^

This is the blocky generated code:

var default_alarm_clock;

default_alarm_clock = time.ZonedDateTime.now().withYear(((time.ZonedDateTime.now()).year())).withMonth(((time.ZonedDateTime.now()).monthValue())).withDayOfMonth(((time.ZonedDateTime.now()).dayOfMonth())).withHour(7).withMinute(0).withSecond(0).withNano(0);
items.getItem('alarmClock').sendCommand((default_alarm_clock.format(time.DateTimeFormatter.ofPattern('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'))));

  • Platform information:
    • Hardware: RPI4
    • OS: Linux
    • Java Runtime Environment: openJDK-17
    • openHAB version: 4.0.2

Did you create the original with the earlier DateTime marketplace library blocks, as opposed to the new Date Time blocks in the base UI? I had some rules that had problems like you are describing and when I replaced the old blocks with the new ones, everything worked.

Try like this without the variable

1 Like

And here’s how you use this block type that @Rolli has mentioned:

Thanks! I changed to the new code, all fine now.