now.isAfter rule

Hi,

what am I doing wrong? I am using latest docker 2.4 version.

rule "Rolladen etwas früher hoch"
when
    Channel "astro:sun:local:civilDawn#event" triggered START or
Time cron "0 26 7 1/1 * ? *"
then
   if (now.isAfter(Min_Rolladen_Open_Zeit)) {
    logInfo("sonne.rules", "Now is after Min_Rolladen_Open_Zeit")
    EG_Rolladen_Switch.sendCommand(OFF)

} else {
    logInfo("sonne.rules", "Now is before Min_Rolladen_Open_Zeit --> keine Rolladen öffnen")

}
end

I get the following error in the logs:

2020-03-19 07:26:00.734 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Rolladen etwas früher hoch': An error occurred during the script execution: Could not invoke method: org.joda.time.base.AbstractInstant.isAfter(org.joda.time.ReadableInstant) on instance: 2020-03-19T07:26:00.733+01:00

Min_Rolladen_Open_Zeit is defined as:

DateTime Min_Rolladen_Open_Zeit "Min Rolladen Öffnungszeit" <sunrise> (gSonne)  {channel="astro:sun:local:civilDawn#end"}

Thank you,

Daniel

Your rule has two issues:

1 Like

This is also a very good explaination: DateTime Conversion

A quick solution:
if (now.isAfter(new DateTime(Min_Rolladen_Open_Zeit.state.toString) )) {

Hi there,
can someone tell me the mistake im making?

If i execute

// if two days are gone
val last_clean = new DateTime(dVac1_last_clean.state.toString)
if (now.minusDays(2).isAfter(last_clean)){

MYSTUFF WHICH IS TEMPORARILY COMMENTED OUT

}
DateTime                    dVac1_last_clean                                (dVac1)

I get

2021-12-05 15:26:40.332 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘vacuum-3’ failed: An error occurred during the script execution: null in vacuum

OK with more trial and error i got it working.
The solution for me was

val LastCleaned = (dVac1_last_clean.state as DateTimeType).zonedDateTime
2 Likes

Hi, i have a similar problem since update to OH3…

My in OH2.5 working rule:

if (now.isAfter((Rollos_up_time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)) {

Now in OH3 i get this error:

Type mismatch: cannot convert from long to ChronoZonedDateTime<?>

My item:
DateTime	Rollos_up_time	{ channel="astro:sun:home-offset:rise#start" }

I tried several changes to my rule, but errors are getting more and more… My knowledge about time conversion is very poor…

UPDATE:
I removed .toInstand.toEpochMilli and now it seems to work. Is this right? Why was this needed in OH2 and is not needed anymore in OH3?