I have the same problem, just waiting for a new stable version which will (hopefully) fix this.
I use this lambda for timestamps:
val Functions$Function2<GenericItem, String, String> getTimestamp = [ //function (lambda) to get a timestamp. Returns formatted string and optionally updates an item
item,
date_format |
var date_time_format = date_format
if(date_format == "" || date_format === null) date_time_format = "%1$ta %1$tT" //default format Day Hour:Minute:Seconds
var String Timestamp = String::format( date_time_format, new Date() )
if(item != NULL && item !== null) {
var t = new DateTimeType()
if(item instanceof DateTimeItem) {
postUpdate(item, t)
logInfo("Last Update", item.name + " DateTimeItem updated at: " + Timestamp )
}
else if(item instanceof StringItem) {
postUpdate(item, Timestamp)
logInfo("Last Update", item.name + " StringItem updated at: " + Timestamp )
}
else
logWarn("Last Update", item.name + " is not DateTime or String - not updating")
}
Timestamp
]
You call it in a rule like this:
rule "HEM Last Updated"
when
Item HEM_C1 received update or
Item HEM_C2 received update
then
getTimestamp.apply(HEMLastUpdated, "")
end
or:
rule "Aeon Labs Multisensor LA Last Updated"
when
Item AeonMS61LA changed or
Item AeonMS62LA changed or
Item AeonMS63LA changed or
Item AeonMS64LA changed
then
getTimestamp.apply(AeonMS6LastUpdatedLA, "%1$ta %1$tR")
end
or:
rule "Autolock Front Door"
when
Item virtualfrontDoorDoorContact changed to CLOSED
then
// Front Door Closed
if(DoorTimer !== null) DoorTimer.cancel
DoorTimer = null
logInfo("FRONT_DOOR", "Front Door CLOSED - Master Sensor: " + FrontDoorSensorSelected.state )
postUpdate(hallway_HSM200_setcolour, 3) //RED (closed, unlocked)
var String Timestamp = getTimestamp.apply(virtualfrontDoorLastUpdate, "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS")
AutoRelock.apply(" by: Door Close Auto Lock", Timestamp, LockTimers, "FrontDoor", DoorRelockTime)
end
This way, it doesn’t matter if the item is a DateTime type, or a String, you can optionally specify the format of the string, and you can get the Timestamp value returned as a String to use in notifications, or logs etc.