First off, before buying my ST hub I have never looked at code before. So everything is new and the language is foreign to me.
I have a thermostat (CT100) that I need battery updates on because it is not connected to a C wire and I have no means of doing so. Also, it’s in a second home where I can’t monitor the physical device all the time. So seeing battery remotely provides significant peace of mind.
When I first installed the thermostat last weekend I was getting updates with the following code (provided by @minollo ). Please note that getBattery() is included in the def poll() command.
def zwaveEvent(physicalgraph.zwave.commands.batteryv1.BatteryReport cmd) {
def nowTime = new Date().time
state.lastBatteryGet = nowTime
def map = [ name: “battery”, unit: “%” ]
if (cmd.batteryLevel == 0xFF || cmd.batteryLevel == 0) {
map.value = 1
map.descriptionText = “$device.displayName battery is low!”
} else {
map.value = cmd.batteryLevel
}
map
private getBattery() { //once every 10 hours
def nowTime = new Date().time
def ageInMinutes = state.lastBatteryGet ? (nowTime - state.lastBatteryGet)/60000 : 600
log.debug "Battery report age: ${ageInMinutes} minutes"
if (ageInMinutes >= 600) {
log.debug "Fetching fresh battery value"
zwave.batteryV1.batteryGet().format()
} else “delay 87”
}
I was getting updates every 10 hours then all of a sudden it stopped working. My last battery update was 4 days ago, so I’m not sure if anything changed on the ST end. I read in a thread that the cmd.batteryLevel should have “as Integer” attached to the end. And I read in another thread that a sendEvent should be used because the polling command is inconsistent for a custom device type. Luckily, @RBoy wrote the code with both of these attributes. His code changed the one above to the one below:
def zwaveEvent(physicalgraph.zwave.commands.batteryv1.BatteryReport cmd) {
def nowTime = new Date().time
state.lastBatteryGet = nowTime
def map = [ name: “battery”, unit: “%” ]
if (cmd.batteryLevel == 0xFF || cmd.batteryLevel == 0) {
map.value = 1
map.descriptionText = "battery is low!"
sendEvent(name: “BatteryLevel”, value: “battery is low!”)
} else {
map.value = cmd.batteryLevel as Integer
sendEvent(name: “BatteryLevel”, value: “battery is $cmd.batteryLevel%”)
}
map
}
private getBattery() { //once every 10 hours
def nowTime = new Date().time
def ageInMinutes = state.lastBatteryGet ? (nowTime - state.lastBatteryGet)/60000 : 600
log.debug "Battery report age: ${ageInMinutes} minutes"
if (ageInMinutes >= 600) {
log.debug "Fetching fresh battery value"
zwave.batteryV1.batteryGet().format()
} else “delay 87”
}
def refresh() {
// Force a refresh
log.info "Requested a refresh"
state.lastBatteryGet = (new Date().time) - (600 * 60000)
poll()
}
Hitting the refresh button/tile on my phone multiple times does nothing to update battery. Also, when I look at the list of events on IDE (using the “from device” link) I see nothing relating to battery - although I see the multiple refreshes. I’ve installed the Pollster by smartapp by @geko and am polling the thermostat every 6 minutes. I’ve deleted and re-installed the smart device several times. I’m out of ideas.
Any help you can provide would be really appreciated. Thanks so much.