DateTimeType error

I’m trying to reuse the Design Pattern: Working with Groups in Rules Design Pattern.

I’m getting the following error:

2017-07-17 20:47:56.902 [INFO ] [clipse.smarthome.model.script.motion] - Motion: Sensor - LandingMotion Triggered
2017-07-17 20:47:56.911 [INFO ] [clipse.smarthome.model.script.Motion] - Timer: LandingMotionTimer
2017-07-17 20:47:56.923 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'A Motion Sensor Changed': org.eclipse.smarthome.core.library.types.DateTimeType


Group:Contact:OR(OPEN, CLOSED) gMotionSensors "The Motion Sensors are [%s]"
Group:DateTime:MAX gMotionLast "The last motion event was [%1$tm/%1$td %1$tH:%1$tM]" 
Group:Switch:OR(ON, OFF) gMotionTimers

Switch  HallwayMotionTimer  (gMotionTimers)    { expire="2m30s,command=OFF" }
Switch  LandingMotionTimer  (gMotionTimers)    { expire="2m30s,command=OFF" }

Contact  HallwayMotion "Hallway Motion [MAP(]" <contact> (gHall,gMotion,gMotionSensors) {mios="unit:house,device:22/service/SecuritySensor1/Tripped"}
DateTime HallwayMotion_LastUpdate "Hallway Motion [%1$tm/%1$td %1$tH:%1$tM]" (gMotionLast)
Contact LandingMotion	"Landing Motion [MAP(]" 	(gModbus, gMotion, gMotionSensors)   {modbus="slave1:0"}
DateTime LandingMotion_LastUpdate "Landing Motion [%1$tm/%1$td %1$tH:%1$tM]" (gMotionLast)


rule "A Motion Sensor Changed"
    Item LandingMotion changed or
    Item HallwayMotion changed
    Thread::sleep(100) // give persistence time to catch up

    val motion = gMotionSensors.members.filter[s|s.lastUpdate("mapdb") != null].sortBy[lastUpdate("mapdb")].last as ContactItem
    logInfo("motion", "Motion: Sensor - " + + " Triggered")

    val timer = gMotionTimers.members.filter[t | =="Timer"].head as SwitchItem
    logInfo("Motion", "Timer: " +
    if(motion.state == OPEN){
        val lastUpdate = gMotionLast.members.filter[dt | == + "_LastUpdate"].head as DateTimeType
        logInfo("Motion", "LastUpdate: " +
        lastUpdate.postUpdate(new DateTimeType)

        // Alert
        val StringBuilder msg = new StringBuilder
        msg.append(  // note a map and transform can convert from Item name to human friendly words
        msg.append(" was activated")

        if(AlarmSet.state == ON){
        if (FrontLux.state < LightLevelTrigger && Elevation.state < ElevationHeightTrigger){
		    msg.append(" DO stuff here!")
            logInfo("lightsLanding", msg.toString)
    //timer.postUpdate(OFF) // postUpdate(OFF) cancels the Timer without triggering the rule below


It would be helpful to see the log statements immediately before the error so we know where in the rule it failed.

Updated the original post with the previous log entries, it points to the issue being here:

val lastUpdate = gMotionLast.members.filter[dt | == + "_LastUpdate"].head as DateTimeType
        logInfo("Motion", "LastUpdate: " +


Should be

val lastUpdate = gMotionLast.members.filter[dt | == + "_LastUpdate"].head as DateTimeItem

Though the cast is probably not even needed and you can just use:

val lastUpdate = gMotionLast.members.filter[dt | == + "_LastUpdate"].head

Edit: I’ve gone and corrected the error in the original posting. Thanks for finding the error! Hope this fixes it.

Thanks @rlkoshak for the speedy response - RFXcom problem solved, OH2 migration complete it’s time to start re-writing rules that I’ve avoided till now!