/**
* Candeo C-ZB-SEWA Zigbee Water Sensor
* Reports Water Events
* Reports Battery Events
* Has Setting For Battery Reporting
*/
metadata {
definition(name: 'Candeo C-ZB-SEWA Zigbee Water Sensor', namespace: 'Candeo', author: 'Candeo', importUrl: 'https://raw.githubusercontent.com/candeosmart/hubitat-zigbee/refs/heads/main/Candeo%20C-ZB-SEWA%20Zigbee%20Water%20Sensor.groovy', singleThreaded: true) {
capability 'WaterSensor'
capability 'Battery'
capability 'Sensor'
capability 'Configuration'
fingerprint profileId: '0104', endpointId: '01', inClusters: '0000,0003,0500,0001', outClusters: '000A', manufacturer: 'Candeo', model: 'C-ZB-SEWA', deviceJoinName: 'Candeo C-ZB-SEWA Zigbee Water Sensor'
}
preferences {
input name: 'deviceDriverOptions', type: 'hidden', title: 'Device Driver Options', description: 'The following options change the behaviour of the device driver, they take effect after hitting "Save Preferences below."'
input name: 'loggingOption', type: 'enum', title: 'Logging Option', description: 'Sets the logging level cumulatively, for example "Driver Trace Logging" will include all logging levels below it.
', options: PREFLOGGING, defaultValue: '5'
input name: 'deviceConfigurationOptions', type: 'hidden', title: 'Device Configuration Options', description: 'The following options change the behaviour of the device itself, they take effect after hitting "Save Preferences below", followed by "Configure" above.
For a battery powered device, you may also need to wake it up manually!'
input name: 'batteryPercentageReportTime', type: 'enum', title: 'Battery Percentage Time (hours)', description: 'Adjust the period that the battery percentage is reported to suit your requirements.
', options: PREFBATTERYREPORTTIME, defaultValue: '28800'
input name: 'platformOptions', type: 'hidden', title: 'Platform Options', description: 'The following options are relevant to the Hubitat platform and UI itself.'
}
}
import groovy.transform.Field
private @Field final String CANDEO = 'Candeo C-ZB-SEWA Device Driver'
private @Field final Boolean DEBUG = false
private @Field final Integer LOGSOFF = 1800
private @Field final Integer ZIGBEEDELAY = 1000
private @Field final Map PREFFALSE = [value: 'false', type: 'bool']
private @Field final Map PREFTRUE = [value: 'true', type: 'bool']
private @Field final Map PREFBATTERYREPORTTIME = ['3600': '1h', '5400': '1.5h', '7200': '2h', '10800': '3h', '21600': '6h', '28800': '8h', '43200': '12h', '64800': '18h']
private @Field final Map PREFLOGGING = ['0': 'Device Event Logging', '1': 'Driver Informational Logging', '2': 'Driver Warning Logging', '3': 'Driver Error Logging', '4': 'Driver Debug Logging', '5': 'Driver Trace Logging' ]
void installed() {
logsOn()
logTrace('installed called')
device.updateSetting('batteryPercentageReportTime', [value: '28800', type: 'enum'])
logInfo("batteryPercentageReportTime setting is: ${PREFBATTERYREPORTTIME[batteryPercentageReportTime]}")
logInfo('logging level is: Driver Trace Logging')
logInfo("logging level will reduce to Driver Error Logging after ${LOGSOFF} seconds")
}
void uninstalled() {
logTrace('uninstalled called')
clearAll()
}
void updated() {
logTrace('updated called')
logTrace("settings: ${settings}")
logInfo("batteryPercentageReportTime setting is: ${PREFBATTERYREPORTTIME[batteryPercentageReportTime ?: '28800']}", true)
logInfo("logging level is: ${PREFLOGGING[loggingOption]}", true)
clearAll()
if (logMatch('debug')) {
logInfo("logging level will reduce to Driver Error Logging after ${LOGSOFF} seconds", true)
runIn(LOGSOFF, logsOff)
}
logInfo('if you have changed any Device Configuration Options, make sure that you hit Configure above!', true)
}
void logsOff() {
logTrace('logsOff called')
if (DEBUG) {
logDebug('DEBUG field variable is set, not disabling logging automatically!', true)
}
else {
logInfo('automatically reducing logging level to Driver Error Logging', true)
device.updateSetting('loggingOption', [value: '3', type: 'enum'])
}
}
List configure() {
logTrace('configure called')
logDebug('battery powered device requires manual wakeup to accept configuration commands')
logDebug("battery percentage time is: ${batteryPercentageReportTime.toBigDecimal()}")
Integer batteryTime = batteryPercentageReportTime.toInteger()
List cmds = ["zdo bind 0x${device.deviceNetworkId} 0x${device.endpointId} 0x01 0x0001 {${device.zigbeeId}} {}", "delay ${ZIGBEEDELAY}",
"he cr 0x${device.deviceNetworkId} 0x${device.endpointId} 0x0001 0x0021 0x20 3600 ${batteryTime} {${intTo16bitUnsignedHex(2)}}", "delay ${ZIGBEEDELAY}",
"he raw 0x${device.deviceNetworkId} 0x01 0x${device.endpointId} 0x0001 {10 00 08 00 2100}", "delay ${ZIGBEEDELAY}",
"he rattr 0x${device.deviceNetworkId} 0x${device.endpointId} 0x0001 0x0021 {}"]
logDebug("sending ${cmds}")
return cmds
}
List