Solved: Openhab3 problem with hashmap containing datetime: validation issue

Hi people,

I am facing a problem when migrating from openhab 2.5.11 to 3.0.0. I have a rules file with a hashmap with a Sting linked to a DateTime like so:

import java.util.Map
val Map<String, DateTime> timersend = newHashMap

This worked perfectly in openhab 2.5. Now I am getting:

2020-12-29 19:11:08.656 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'rooms_occupied.rules', using it anyway:
The field Tmp_rooms_occupiedRules.timersend refers to the missing type Object
The field Tmp_rooms_occupiedRules.timersend refers to the missing type Object
The field Tmp_rooms_occupiedRules.timersend refers to the missing type Object
The field Tmp_rooms_occupiedRules.timersend refers to the missing type Object
The field Tmp_rooms_occupiedRules.timersend refers to the missing type Object
The field Tmp_rooms_occupiedRules.timersend refers to the missing type Object
The field Tmp_rooms_occupiedRules.timersend refers to the missing type Object
The field Tmp_rooms_occupiedRules.timersend refers to the missing type Object
The field Tmp_rooms_occupiedRules.timersend refers to the missing type Object
The field Tmp_rooms_occupiedRules.timersend refers to the missing type Object
The field Tmp_rooms_occupiedRules.timersend refers to the missing type Object
The field Tmp_rooms_occupiedRules.timersend refers to the missing type Object
The field Tmp_rooms_occupiedRules.timersend refers to the missing type Object

The number of messages corresponds to the times the hashmap variable is used. If I remove one, the number of messages decreases accordingly.

An example of the ways I am using the variable is:

	if(timersend.get(triggername) === null){
		//var DateTime timerend = new DateTime(now.plusMinutes(length.intValue))
		timerend = new DateTime(now.plusMinutes(length.intValue))
		timersend.put(triggername, timerend)
	}

As a result of this issue this rule produces errors. In this case:

2020-12-29 19:22:28.806 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'rooms_occupied-2' failed: Unknown variable or command '==='; line 40, column 5, length 35 in rooms_occupied

Please note that I am also using other hashmaps in the same rule file without issue:

val Map<String, Timer> timers = newHashMap
val Map<String, Number> timerslength = newHashMap

I note that this behaviour was already reported earlier here:

The behaviour is exacly the same, in both cases only the hashmap with a DateTime is failing. Has anyone else seen this behaviour and is there a way to fix it?

  • Platform information:
    • Hardware: Raspberry Pi 4_
    • OS: Raspian
    • Openhab running on docker
    • openHAB version: 3.0.0

Did you update to the new dateTime library syntax as listed in the Release notes?

Hi, I saw the following in the release notes:

Rules now use Java Time API instead of Jodatime so some expressions need to be adapted:

  • getHourOfDay → getHour, getMinuteOfHour → getMinute, getMonthOfYear → getMonthValue
  • Some simple >and < comparisons may no longer work and you may need to use isAfter()/isBefore() instead.
  • See also this thread for more information.

I changed the obvious stuff like the getHour stuff. I also studied the thread mentioned, but I can’t find information about the hashmap issue. It seems likely that there is a link. Maybe I am missing an import statement or something like that.

I think you need to use ZonedDateTime…

OH2

val Map<String, DateTime> timersend = newHashMap

OH3

val Map<String, ZonedDateTime> timersend = newHashMap
1 Like

That did it thanks! :grinning: