Generic Zigbee Contact Sensor - battery change date

So - I assume that this is supposed to give an idea of when the battery was changed last - have no idea how to interpret it. Would be nice if it gave an actual date! (And I double-checked - it’s not a custom driver).

Thanks!

1 Like

Screenshot 2024-03-07 at 6.15.06 PM

2 Likes

Its just the timestamp of when the last battery report came in, mostly useless.

2 Likes

Thanks, both of you. Question: given that it’s the default - any reason the Groovy driver couldn’t just convert it into human-readable and actually say: “Last battery report”? I assume there’s a formula for that. [Edit: never mind - I just looked into algorithms - not that easy!]

Its not hard, I have it in my driver to do it for the last check in and show as a normal date.
You can also just look at the "Last Activity" down lower on the device page, that is the last time the device state changed and battery reports usually always cause a state change.

1 Like

@jtp10181 - will track down and try your driver (and look at the algorithm) - thanks! It’s more about basic not having to look at an impossible-to-humanly parse number.

1 Like

Sorry I do not have Zigbee drivers.

Here is my function that I use in my Z-wave drivers though

String convertToLocalTimeString(dt) {
	def timeZoneId = location?.timeZone?.ID
	if (timeZoneId) {
		return dt.format("MM/dd/yyyy hh:mm:ss a", TimeZone.getTimeZone(timeZoneId))
	} else {
		return "$dt"
	}
}

Here is how you could call it:

void updateLastCheckIn() {
	def nowDate = new Date()
	state.lastCheckInDate = convertToLocalTimeString(nowDate)
}

Is there a reason you care specifically about this value? In general, data under "State" is for internal use by the driver (unlike "Current States" that could be usable for automation or just nice to know as a user). Not all devices will do the same thing here.

If you're looking to see if the battery/device died, a better value most of the time is the "Last Activity At" data towards the bottom of the page. This normally updates for not just battery reports but any event -- and it's in human-friendly format.

@bertabcd1234 Also has an app to keep track of the Last Activity on all devices. I consider this a MUST HAVE app for anyone with battery devices. Set it and forget it, it will notify you if a device stops checking in with updates.

2 Likes