Adding timestamp in my label

Hi guys,

Thank you for sticking around. I understand .label is new and rather unknown.
Sorry I couldn’t test this sooner.

I tried this:

rule "Update label"

when
	Item gRamen2 received update
then
	Tex_Window_W10_GV_Bureau_Zijkant.label = "This should work"
		logInfo ("test", "A. " + Tex_Window_W10_GV_Bureau_Zijkant.label.toString)
	gRamen2.members.forEach[rm |
		Tex_Window_W10_GV_Bureau_Zijkant.label = "Might work, might not"  
		logInfo ("test", "B. " + Tex_Window_W10_GV_Bureau_Zijkant.label.toString)
		val indirect = Tex_Window_W10_GV_Bureau_Zijkant
		indirect.label = "Indirect Test Text"
		logInfo ("test", "C. " + indirect.label.toString)		
		rm.label = "This hasn't worked before"
		logInfo ("test", "D. " + rm.label.toString)					
	]
end

The output is this:

2017-06-01 12:34:11.822 [INFO ] [.eclipse.smarthome.model.script.test] - A. This should work
2017-06-01 12:34:11.826 [INFO ] [.eclipse.smarthome.model.script.test] - B. Might work, might not
2017-06-01 12:34:11.828 [INFO ] [.eclipse.smarthome.model.script.test] - C. Indirect Test Text
2017-06-01 12:34:11.829 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Update label': Couldn't invoke 'assignValueTo' for feature JvmVoid:  (eProxyURI: test.rules#|::0.2.2.2.0.2.7.0.1.0.5::0::/2)

So updating the label works fine in almost all cases, except on the for the “forEach[rm” part.

Any other creative ideas? :slight_smile:

I could always go back to old-school approach and mention every individual item separately in my rule:

	var label = Tex_Window_W10_GV_Bureau_Zijkant.label.toString.split("   ")
	Tex_Window_W10_GV_Bureau_Zijkant.label = label.get(0) + " " + " " + " (" + Tex_Window_W10_GV_Bureau_Zijkant.lastUpdate.toDateTime.toString("dd-MM-yy hh:mm") + ")"
	label = Tex_Window_W06_GV_Keuken_ZijkantRechts.label.toString.split("   ")
	Tex_Window_W06_GV_Keuken_ZijkantRechts.label = label.get(0) + " " + " " + " (" + Tex_Window_W06_GV_Keuken_ZijkantRechts.lastUpdate.toDateTime.toString("dd-MM-yy hh:mm") + ")"

BTW, I’ve also learned that adjusted labels are not persisted (the value of that same item is). Not an issue for me, but maybe interesting to know.