Show datetime for receiving last event on a tile?

Hi all, I have slightly modified the Smartsense Temperature + Humidity Sensor device handler so it displays celcius temperature with a decimal. (Thanks to another thread in here).

I would also like to display when the temperature was last reported/changed from the device in a tile.

How can I accomplish that?

Best regards

First create an attribute

attribute "lastActivity", "string"

then a tileAttribute

tileAttribute ("device.lastActivity", key: "SECONDARY_CONTROL") {
				attributeState "default", label:'Last activity: ${currentValue}', action: "refresh.refresh"
			}

when you get a temperature update also do this…

def finalString = lastActivity?.format('MM/d/yyyy hh:mm a',location.timeZone)    
	sendEvent(name: "lastActivity", value: finalString, display: false , displayed: false)

See my leakSmart sensor code for example.

2 Likes