getLastActivity()?

I am looking at Simple Device Viewer in ST.
It makes a call for device.getLastActivity() which is expecting a timestamp.

device.getLastActivity() returns the following error for each device iterated:
java.lang.IllegalArgumentException: Command 'getLastActivity' is not supported by device.

In Hubitat, I know "Last Activity" is visible on the Hubitat device page but is there another way to get this information programatically?

I've added a ticket to add that method. In the mean time you can implement it like this:

device.events([max: 1])?.date
3 Likes

Is it a Timestamp or a Date or a String? ST docs aren't clear on that.

I'm thinking it's data type is Date perhaps..
Below is a snip of code from the app I am working with, perhaps it will help:

def checkHistoryCutoff = (new Date().time - (safeToInteger(settings?.checkHistoryThreshold, 12) * 60 * 60 * 1000))
...
def lastActivityDate = device.getLastActivity()
if (lastActivityDate && (lastActivityDate.time >= checkHistoryCutoff)) {
	lastActivity = [
					name: "unknown",
					value: "",
					time: lastActivityDate.time,
					type: activityType
				]
			}

@chuck.schwer I found a post in the ST forum from erocm1231 regarding his app "Device Monitor" that states:

device.status will return ONLINE, OFFLINE, ACTIVE, INACTIVE. ONLINE and OFFLINE are returned if the device is using Health Check.

device.getLastActivity() will return the last activity as a date object.

1 Like

Are you trying to port over the Simple Device Viewer SmartApp?

Have you looked at @ericm's port of Device Monitor for Hubitat?

Yea. I wanted something that I could quickly see battery levels with. It loaded fine as-is but then had the errors due to the missing getLastActivity() function.

I did see that one as well. It too makes the same getLastActivity() call which sounds like Hubitat will include in a future release.

1 Like

It looks like getLastActivity() is not returning Last Activity At value:

image

It returns the same value as just checking the last event:

Is there anyway to get the date value for the "Last Activity At" for the device?

Have you tried
device.events([max: 1])?.date

Never mind. On second read it looks like you have probably tried this. Your wanting a return of the last activity and not the last event time.

Yeah, I did try that.

Exactly, I'm trying to get the last active time and not the last event time. Both:

device.events([max: 1])?.date

and

device.getLastActivity()

Are returning the date/time of the last event.

What is setting for existing devices "active", inactive, etc? ie what operation is being monitored, and is inactive a timeout? I asking about the HE devices display off the portal.

I believe that the device is sending a report to the Hubitat device, but the report is not generating an event. For example, the device in my screenshot it is sending battery reports every few hours. Since the reports are all 100% a new event isn't created. The Last Active time is the last time the device reported to the hub.

I don't know a way to get the last active time though. I thought getLastActivity would do it, but it doesn't seem to.

I'm not sure how long the timeout is for it to be marked INACTIVE.

what you want is device.lastActivity

devices are marked inactive after 24 hours

1 Like

thx, so what "makes them active"? Execution? sending Events?, calls to parse?

Yes, events comitted to the db, currently the event must involve a state change, or an app has subscribed to the attribute in question with filterEvents:false

Maybe I am missing something obvious. So I am trying:

log.debug device.lastActivity
log.debug device.displayName

Which is logging:

app:9912018-11-26 05:30:26.151 pm debug Master Bedroom Glass Break Detector
app:9912018-11-26 05:30:26.150 pm debug 2018-11-20 08:14:23.095
app:9912018-11-26 05:30:26.139 pm debug Basement West Glass Break Detector
app:9912018-11-26 05:30:26.138 pm debug 2018-11-26 16:31:36.918
app:9912018-11-26 05:30:26.109 pm debug Basement North Glass Break Detector
app:9912018-11-26 05:30:26.108 pm debug 2018-11-26 17:17:25.246
app:9912018-11-26 05:30:26.061 pm debug Basement East Glass Break Detector
app:9912018-11-26 05:30:26.060 pm debug 2018-10-17 13:31:16.157

Which doesn't match up with the Last Activity displayed in the web ui.

Time zone...

don't even line up if you try to convert TZ...

1 Like