OH2.4 #1428 Java 8 DateTime API

I am using the following rules and they produce the error. Please help

An error occurred during the script execution: index=1, size=1

rule "Calculate time of day state"
when
  Time cron "	0 0/3 * 1/1 * ? *"
then
  Thread::sleep(1000) // make sure we are a tad past midnight to give Astro a chance to recalculate DateTimes for today

  val long day_start = (Sunrise_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli
  val long night_start = (Sunset_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli

  var curr = "UNKNOWN"

  switch now {
        case now.isAfter(day_start) && now.isBefore(night_start):                  curr = "Daytime"
        case (now.isAfter(night_start) && now.isBefore(now.withTimeAtStartOfDay.plusHours(24))) ||
             (now.isAfter(now.withTimeAtStartOfDay) && now.isBefore(day_start)):   curr = "Night time"
  }

  if(TimeOfDay.state.toString != curr) {
    logInfo("TimeofDay", "Current time of day is now " + curr)
    TimeOfDay.sendCommand(curr)
  }
	if(Day.state == OFF && TimeOfDay.state.toString == "Daytime"){Day.sendCommand(ON)}
	if(Day.state == ON && TimeOfDay.state.toString == "Night time"){Day.sendCommand(OFF)}

end

and

rule "Rec Room Lights On"
when   
	Item rrtrigger changed to ON
then
	var LocalTime LocTime = new LocalTime(now)
	if((LocTime.getLocalMillis()) >= (new LocalTime(7, 0, 0, 0).getLocalMillis()) &&
		(LocTime.getLocalMillis()) <= (new LocalTime(7, 59, 59, 0).getLocalMillis())){
			if(HueBulb14.state.toString != "41,38,50"){sendCommand(HueBulb14, new HSBType(new DecimalType(41),new PercentType(38),new PercentType(50)))}
			if(HueBulb15.state.toString != "41,38,50" && MBRAuto.state == ON){sendCommand(HueBulb15, new HSBType(new DecimalType(41),new PercentType(38),new PercentType(50)))}
			if(Light_scene_RR.state != 7){Light_scene_RR.sendCommand(7)}
			sendCommand(Wifi5Ledrgbw, new HSBType(new DecimalType(200),new PercentType(20),new PercentType(2)))
	}
	else if((LocTime.getLocalMillis()) >= (new LocalTime(8, 0, 0, 0).getLocalMillis()) &&
		(LocTime.getLocalMillis()) <= (new LocalTime(19, 29, 59, 0).getLocalMillis())){
			if(HueBulb14.state.toString != "41,38,50"){sendCommand(HueBulb14, new HSBType(new DecimalType(41),new PercentType(38),new PercentType(50)))}
			if(HueBulb15.state.toString != "41,38,50" && MBRAuto.state == ON){sendCommand(HueBulb15, new HSBType(new DecimalType(41),new PercentType(38),new PercentType(50)))}
			if(Light_scene_RR.state != 7){Light_scene_RR.sendCommand(7)}
			sendCommand(Wifi5Ledrgbw, new HSBType(new DecimalType(200),new PercentType(20),new PercentType(10)))
	}
	else if((LocTime.getLocalMillis()) >= (new LocalTime(19, 30, 0, 0).getLocalMillis()) &&
		(LocTime.getLocalMillis()) <= (new LocalTime(20, 59, 59, 0).getLocalMillis())){
			if(HueBulb14.state.toString != "41,38,25"){sendCommand(HueBulb14, new HSBType(new DecimalType(41),new PercentType(38),new PercentType(25)))}
			if(HueBulb15.state.toString != "41,38,0"){sendCommand(HueBulb15, new HSBType(new DecimalType(41),new PercentType(38),new PercentType(0)))}
			if(Light_scene_RR.state != 7){Light_scene_RR.sendCommand(7)}
			sendCommand(Wifi5Ledrgbw, new HSBType(new DecimalType(200),new PercentType(20),new PercentType(2)))
	}
	else if((LocTime.getLocalMillis()) >= (new LocalTime(21, 0, 0, 0).getLocalMillis()) &&
		(LocTime.getLocalMillis()) <= (new LocalTime(23, 59, 59, 0).getLocalMillis())){
			if(Light_scene_RR.state != 1){Light_scene_RR.sendCommand(1)}
			sendCommand(Wifi5Ledrgbw, new HSBType(new DecimalType(0),new PercentType(100),new PercentType(2)))
	}
	else if((LocTime.getLocalMillis()) >= (new LocalTime(0, 0, 0, 0).getLocalMillis()) &&
		(LocTime.getLocalMillis()) <= (new LocalTime(6, 59, 59, 0).getLocalMillis())){
			if(Light_scene_RR.state != 1){Light_scene_RR.sendCommand(1)}
			sendCommand(Wifi5Ledrgbw, new HSBType(new DecimalType(0),new PercentType(100),new PercentType(2)))
	}
	if(WindowSwitch_Status21.state == CLOSED && HueBulb24.state.toString != "41,38,0"){sendCommand(HueBulb24, new HSBType(new DecimalType(41),new PercentType(38),new PercentType(0)))}

end

For the first rule, check out this tutorial https://community.openhab.org/t/datetime-conversion/54266?u=h102 maybe some tweaking needed for time on the latest snapshot?

This is the only thing you see in the logs?

Yes the rule doesn’t execute.

I can confirm this! Got errors for:

now.plusMillis(150)
now.getHourOfDay

Did not change anything in my rules-file and went back to a previous snapshot

sudo apt-get install openhab2=2.4.0~20181115123158-1

Guessing that this change broke things.

now.plusMillis(150)
now.getHourOfDay
now.withTimeAtStartOfDay

@Kai I realize this is a breaking change. However, the above methods, which are commonly used in rules, no longer exist.

as far as I understood, you will have to update the rules to use the new methogs.

  • now.plusMillis(150) -> maybe (can’t test it myself yet) plus(150,MILLIS) would work
  • now.getHourOfDay -> now.getHour should work
  • now.withTimeAtStartOfDay -> now.truncatedTo(DAYS)

I’m pretty sure VSCode should give hints.

unfortunatly this change broke a lot of rules in my setup… i changed today to the latest 2.4.0 snapshot
on my production 2.3.0 stable system (yes i know) and i had to revert back to 2.3.0 stable because i wasn’t
able to fix it…
e.g. (now.isAfter((SunriseTimeEnd.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
doesnt work anymore…

@rlkoshak @vzorglub heads-up on this one !

Say goodbye to org.joda.time, Say hello to java.time :slight_smile:

The hope was that it does not break a lot, but with methods missing now, it seems it does. Imho we should bring them back, see my comment Add ability to find out when a timer will fire by evansj · Pull Request #6492 · eclipse-archived/smarthome · GitHub. Feel free to add comments about further methods that might be needed.

1 Like

I added a comment to the issue with some observations from me and @Udo_Hartmann.

Thank you all. As discussed on the issue, we have reverted this change for now.
I have built a new ESH stable, so the next openHAB distro #1430 should behave as before again.

2 Likes