Did I do this correctly? Non-developer needing help…

Is this the right way to ensure the driver I modified for my Ecolink Z-Wave contact sensor starts to get battery reports every 12 hours?

Some background: I recently switch driver for Ecolink contact sensors (was using the generic Z-Wave contact sensors before) to a community one (I wanted to add an option to set to open/close manually, and also report closed when open and vice-versa).

The new driver won’t report battery every 12 hours like the generic one use to, so I checked with ChatGPT to determine how to fix.

I implemented its recommendation, but am wondering if it really is the right way to do this…

The updated code:
Under “def updated()”, add: “schedule("0 0 */12 * * ?", "batteryCheck")” (Line 119)

Then add (line 135):
def batteryCheck() {
if (logEnable) log.debug "Checking battery level..."
zwave.batteryV1.batteryGet()
}

Code is here:

Is this the right way to do this, or is there a better way?

And in case you’re wondering why I need this… I use Device Activity Check to tell me if a device is still working… since I updated to the new driver, it keeps reporting it as failed since with this driver, it doesn’t get updated battery reports every 12 hours, as it use to before…

Screenshot

No do not do that. The device is probably reporting it, the driver is just not posting the event.

You need to include isStateChange = true to force it to post. I see in the code it is being included only if the batter level is low. I always include that for battery events so they post.

1 Like

Okay, thanks! Is there somewhere specific where I need to add “isStateChange = true”?

This should do the trick
EDIT: Fixed a typo copy paste error

def zwaveEvent(hubitat.zwave.commands.batteryv1.BatteryReport cmd) {
	def map = [ name: "battery", unit: "%", isStateChange: true ]
	if (cmd.batteryLevel == 0xFF) {
		map.value = 1
		map.descriptionText = "${device.displayName} has a low battery"
	} else {
		map.value = cmd.batteryLevel
	}
	state.lastbat = now()
	[createEvent(map), response(zwave.wakeUpV1.wakeUpNoMoreInformation())]
}

This is one of the reasons I force post the battery events, so I know the device is still alive using DAC.

2 Likes

Thanks Jeff!

Change made. I’ve also unschedule the check that I added with the previous code now by temporarily changing the driver to “Device” and clicking on the “Delete All Scheduled Jobs” button. Not 100% sure it was needed, but didn’t think it would hurt… :blush:

:+1:
If you need any other examples I have two contact drivers.

This one was a custom request and has a lot of my typical extra fluff stripped out, so it is a little more simplistic: Hubitat Generic Z-Wave Tilt/Contact Sensor · GitHub

Here is the Zooz driver: https://github.com/jtp10181/Hubitat/blob/main/Drivers/zooz/zooz-zse41-open-close.groovy

1 Like

Thanks! I’m very much a beginner when it comes to coding and especially with Groovy. I did a bit of Visual Basic maybe 25 years ago, so I can understand a good part of the code, but when it comes to writing new stuff, it is a challenge.