[SOLVED] Datetime item optimisation issue within rule using groups

Hi all,
I am on the latest GA stable release OH 2.3
I suspect I am doing something dumb but for the life of me cannot figure out what, I have done similar rules in the past and have them all working but this one has escaped me and I resorted to a simple set of if statements to workaround while I request the communities assistance.

I am trying to use the technique where I create an items name to update using triggered items names and a suffix.

here is my configuration

.items

Group gContact // presense contacts last changes
Switch cPaul_Phone 		"Paul (Phone)"		(chartpersist, statepersist, gPresent, gContact) 	
Switch cHolly_Phone		"Holly (Phone)"		(chartpersist, statepersist, gPresent, gContact) 	
DateTime 	cPaul_Phone_Last "[%1$tY-%1$tm-%1$td  %1$tH:%1$tM]" 	
DateTime 	cHolly_Phone_Last "[%1$tY-%1$tm-%1$td  %1$tH:%1$tM]" 	

This is the workaround rule which functions but not happy with it
.rules

rule "Contact update Last Change"
when
	Member of gContact received update or
	Member of gContact changed	
then
	logInfo("phone.rules", triggeringItem.name + " Phone received a change")
    val pContact = triggeringItem.name.split("_").get(0)

	//val _Last = gContact.members.findFirst[ contact | contact.name == triggeringItem.name+"_Last" ]

	if (pContact == "cPaul") {postUpdate(cPaul_Phone_Last,new DateTimeType())}
	if (pContact == "cHolly") {postUpdate(cHolly_Phone_Last,new DateTimeType())}

	logInfo("phone.rules", "Changed - "+triggeringItem.name)
end

Instead of the two if statements in my example I would prefer to uncomment the _Last definition and use something like this one liner to replace the if statements with a single line (in reality I have many if statements).

postUpdate(_Last,new DateTimeType())

But it just does not update the item with the current date time-stamp :frowning:

Can someone point out what I am doing wrong? It is possible I have hit a bug but kind of thinking its me at this stage.

Many thanks

Paul

Your DateTime Items are not members of any group. So naturally, searching any group will not find them.

Personally I put such things in a group gTimestamps and use that.

If there is a chance that a group search will come up blank, you can test to see if the result (_Last in this case) is null. Then you can avoid trying to do things with it (like postUpdate) and if you wish, ring bells instead to say you have a setup problem.

That was it, so obvious once it was pointed out.
@rossko57 Thank you!

And for the record here is the corrected details.

.items

Group gContact // presense contacts last changes
Group gTimestamp


Switch cPaul_Phone 		"Paul (Phone)"		(chartpersist, statepersist, gPresent, gContact) 	
Switch cHolly_Phone		"Holly (Phone)"		(chartpersist, statepersist, gPresent, gContact) 	

DateTime cPaul_Phone_Last "[%1$tY-%1$tm-%1$td  %1$tH:%1$tM]" (gTimestamp)

DateTime cHolly_Phone_Last "[%1$tY-%1$tm-%1$td  %1$tH:%1$tM]" (gTimestamp)

.rules

rule "Contact update Last Change"
when
	Member of gContact received update or
	Member of gContact changed	
then
	logInfo("phone.rules", triggeringItem.name + " Phone received a change")
	val _Last = gTimestamp.members.findFirst[ contact | contact.name == triggeringItem.name+"_Last" ]
	postUpdate(_Last,new DateTimeType())
end

Thanks

Paul