Rule error for minusMinutes()

rules
datetime
Tags: #<Tag:0x00007fd3224b59e0> #<Tag:0x00007fd3224b5878>

(Maximilian) #1

I always get an error when I try to call the minusMinutes function in a rule.
My roller shutter should go up in the morning hours, when there is enough light.
What could be the problem?

Rule:

rule "Open RollerShutters on sunrise and enough luminance"
when
    Item MultiOutLight_luminance received update
then
  if (Activate_Rule.state == ON) {
    if (Sunrise_Time.minusMinutes(60).isBefore(now) && Sunrise_Time.plusMinutes(60).isAfter(now) && MultiOutLight_luminance.state >= 25) {
      logInfo("sunrise.rules","Rollladen hochfahren")
      sendCommand(EG_Alle, UP)
    }
  }
end

Error log:

2018-02-23 22:05:57.108 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Open RollerShutters on sunrise and enough luminance': 'minusMinutes' is not a member of 'org.eclipse.smarthome.core.library.items.DateTimeItem'; line 8, column 9, length 29

(Robert) #2

Try

Sunrise_Time.state.minusMinutes(60).isBefore(now)

Insert state for both dates.


(Maximilian) #3

Doesn’t make a difference, I get the same error.


(Robert) #4

Perhaps this is of help


(Maximilian) #5

Now I have tried

if ((Sunrise_Time.state as DateTimeType).minusMinutes(60).isBefore(now) && (Sunrise_Time.state as DateTimeType).plusMinutes(60).isAfter(now) && MultiOutLight_luminance.state >= 25)

and

if (now.isBefore((Sunrise_Time.state as DateTimeType).minusMinutes(60)) && now.isAfter((Sunrise_Time.state as DateTimeType).plusMinutes(60)) && MultiOutLight_luminance.state >= 25)

but I always get the same error.
What am I doing wrong?


(Robert) #6

You should convert to epoc times and then compare. The article I referred to says

// See if DateTimeType is before Joda DateTime
if(now.isBefore((MyDateTimeItem.state as DateTimeType).calendar.timeInMillis)) ...

So in your case something like

val check = (Sunrise_Time.state as DateTimeType).calendar.timeInMillis + (60*60*1000)
if(now.isBefore(check)...

(Maximilian) #7

So that works:

rule "Open RollerShutters on sunrise and enough luminance"
when
    Item MultiOutLight_luminance received update
then
  val minus60 = new DateTime((Sunrise_Time.state as DateTimeType).calendar.timeInMillis - (60*60*1000))
  val plus60  = new DateTime((Sunrise_Time.state as DateTimeType).calendar.timeInMillis + (60*60*1000))
  if (Activate_Rule.state == ON) {
    logInfo("sunrise.rules","received update")
    if (minus60.isBefore(now) && plus60.isAfter(now) && MultiOutLight_luminance.state >= 20) {
      logInfo("sunrise.rules","Rollladen hochfahren")
      sendCommand(EG_Alle, UP)
    }
  }
end

but I get this validation error:

2018-02-24 10:47:21.701 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'sunrise-new.rules', using it anyway:
The method getCalendar() from the type DateTimeType is deprecated
The method getCalendar() from the type DateTimeType is deprecated

(Maximilian) #8

A replace of

.calendar.timeInMillis

to

.zonedDateTime.toInstant().toEpochMilli

fixed it.