mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-31 14:13:11 +01:00
Merge pull request #443 from tpmanley/feature/sensor_updates
Feature/sensor updates
This commit is contained in:
@@ -88,32 +88,38 @@ private handleReportAttributeMessage(String description) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleBatteryEvent(rawValue) {
|
/**
|
||||||
def linkText = getLinkText(device)
|
* Create battery event from reported battery voltage.
|
||||||
|
*
|
||||||
def eventMap = [
|
* @param volts Battery voltage in .1V increments
|
||||||
name: 'battery',
|
*/
|
||||||
value: '--'
|
private handleBatteryEvent(volts) {
|
||||||
]
|
if (volts == 0 || volts == 255) {
|
||||||
|
log.debug "Ignoring invalid value for voltage (${volts/10}V)"
|
||||||
def volts = rawValue / 10
|
}
|
||||||
if (volts > 0){
|
else {
|
||||||
def minVolts = 2.0
|
def batteryMap = [28:100, 27:100, 26:100, 25:90, 24:90, 23:70,
|
||||||
def maxVolts = 2.8
|
22:70, 21:50, 20:50, 19:30, 18:30, 17:15, 16:1, 15:0]
|
||||||
|
def minVolts = 15
|
||||||
|
def maxVolts = 28
|
||||||
|
|
||||||
if (volts < minVolts)
|
if (volts < minVolts)
|
||||||
volts = minVolts
|
volts = minVolts
|
||||||
else if (volts > maxVolts)
|
else if (volts > maxVolts)
|
||||||
volts = maxVolts
|
volts = maxVolts
|
||||||
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
def pct = batteryMap[volts]
|
||||||
|
if (pct != null) {
|
||||||
eventMap.value = Math.round(pct * 100)
|
def linkText = getLinkText(device)
|
||||||
eventMap.descriptionText = "${linkText} battery was ${eventMap.value}%"
|
def eventMap = [
|
||||||
}
|
name: 'battery',
|
||||||
|
value: pct,
|
||||||
log.debug "Creating battery event: ${eventMap}"
|
descriptionText: "${linkText} battery was ${pct}%"
|
||||||
|
]
|
||||||
|
log.debug "Creating battery event for voltage=${volts/10}V: ${eventMap}"
|
||||||
sendEvent(eventMap)
|
sendEvent(eventMap)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private handlePresenceEvent(present) {
|
private handlePresenceEvent(present) {
|
||||||
def wasPresent = device.currentState("presence")?.value == "present"
|
def wasPresent = device.currentState("presence")?.value == "present"
|
||||||
|
|||||||
@@ -215,18 +215,39 @@ def getTemperature(value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Map getBatteryResult(rawValue) {
|
private Map getBatteryResult(rawValue) {
|
||||||
log.debug 'Battery'
|
log.debug "Battery rawValue = ${rawValue}"
|
||||||
def linkText = getLinkText(device)
|
def linkText = getLinkText(device)
|
||||||
|
|
||||||
def result = [
|
def result = [
|
||||||
name: 'battery'
|
name: 'battery',
|
||||||
|
value: '--'
|
||||||
]
|
]
|
||||||
|
|
||||||
def volts = rawValue / 10
|
def volts = rawValue / 10
|
||||||
def descriptionText
|
|
||||||
|
if (rawValue == 0 || rawValue == 255) {}
|
||||||
|
else {
|
||||||
if (volts > 3.5) {
|
if (volts > 3.5) {
|
||||||
result.descriptionText = "${linkText} battery has too much power (${volts} volts)."
|
result.descriptionText = "${linkText} battery has too much power (${volts} volts)."
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if (device.getDataValue("manufacturer") == "SmartThings") {
|
||||||
|
volts = rawValue // For the batteryMap to work the key needs to be an int
|
||||||
|
def batteryMap = [28:100, 27:100, 26:100, 25:90, 24:90, 23:70,
|
||||||
|
22:70, 21:50, 20:50, 19:30, 18:30, 17:15, 16:1, 15:0]
|
||||||
|
def minVolts = 15
|
||||||
|
def maxVolts = 28
|
||||||
|
|
||||||
|
if (volts < minVolts)
|
||||||
|
volts = minVolts
|
||||||
|
else if (volts > maxVolts)
|
||||||
|
volts = maxVolts
|
||||||
|
def pct = batteryMap[volts]
|
||||||
|
if (pct != null) {
|
||||||
|
result.value = pct
|
||||||
|
result.descriptionText = "${linkText} battery was ${result.value}%"
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
def minVolts = 2.1
|
def minVolts = 2.1
|
||||||
def maxVolts = 3.0
|
def maxVolts = 3.0
|
||||||
@@ -234,6 +255,8 @@ private Map getBatteryResult(rawValue) {
|
|||||||
result.value = Math.min(100, (int) pct * 100)
|
result.value = Math.min(100, (int) pct * 100)
|
||||||
result.descriptionText = "${linkText} battery was ${result.value}%"
|
result.descriptionText = "${linkText} battery was ${result.value}%"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -230,25 +230,40 @@ def getTemperature(value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Map getBatteryResult(rawValue) {
|
private Map getBatteryResult(rawValue) {
|
||||||
log.debug 'Battery'
|
log.debug "Battery rawValue = ${rawValue}"
|
||||||
def linkText = getLinkText(device)
|
def linkText = getLinkText(device)
|
||||||
|
|
||||||
log.debug rawValue
|
|
||||||
|
|
||||||
def result = [
|
def result = [
|
||||||
name: 'battery',
|
name: 'battery',
|
||||||
value: '--'
|
value: '--'
|
||||||
]
|
]
|
||||||
|
|
||||||
def volts = rawValue / 10
|
def volts = rawValue / 10
|
||||||
def descriptionText
|
|
||||||
|
|
||||||
if (rawValue == 0) {}
|
if (rawValue == 0 || rawValue == 255) {}
|
||||||
else {
|
else {
|
||||||
if (volts > 3.5) {
|
if (volts > 3.5) {
|
||||||
result.descriptionText = "${linkText} battery has too much power (${volts} volts)."
|
result.descriptionText = "${linkText} battery has too much power (${volts} volts)."
|
||||||
}
|
}
|
||||||
else if (volts > 0){
|
else {
|
||||||
|
if (device.getDataValue("manufacturer") == "SmartThings") {
|
||||||
|
volts = rawValue // For the batteryMap to work the key needs to be an int
|
||||||
|
def batteryMap = [28:100, 27:100, 26:100, 25:90, 24:90, 23:70,
|
||||||
|
22:70, 21:50, 20:50, 19:30, 18:30, 17:15, 16:1, 15:0]
|
||||||
|
def minVolts = 15
|
||||||
|
def maxVolts = 28
|
||||||
|
|
||||||
|
if (volts < minVolts)
|
||||||
|
volts = minVolts
|
||||||
|
else if (volts > maxVolts)
|
||||||
|
volts = maxVolts
|
||||||
|
def pct = batteryMap[volts]
|
||||||
|
if (pct != null) {
|
||||||
|
result.value = pct
|
||||||
|
result.descriptionText = "${linkText} battery was ${result.value}%"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
def minVolts = 2.1
|
def minVolts = 2.1
|
||||||
def maxVolts = 3.0
|
def maxVolts = 3.0
|
||||||
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
||||||
@@ -256,6 +271,7 @@ private Map getBatteryResult(rawValue) {
|
|||||||
result.descriptionText = "${linkText} battery was ${result.value}%"
|
result.descriptionText = "${linkText} battery was ${result.value}%"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -303,8 +303,7 @@ def getTemperature(value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Map getBatteryResult(rawValue) {
|
private Map getBatteryResult(rawValue) {
|
||||||
log.debug "Battery"
|
log.debug "Battery rawValue = ${rawValue}"
|
||||||
log.debug rawValue
|
|
||||||
def linkText = getLinkText(device)
|
def linkText = getLinkText(device)
|
||||||
|
|
||||||
def result = [
|
def result = [
|
||||||
@@ -313,21 +312,39 @@ def getTemperature(value) {
|
|||||||
]
|
]
|
||||||
|
|
||||||
def volts = rawValue / 10
|
def volts = rawValue / 10
|
||||||
def descriptionText
|
|
||||||
|
|
||||||
if (rawValue == 255) {}
|
if (rawValue == 0 || rawValue == 255) {}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
if (volts > 3.5) {
|
if (volts > 3.5) {
|
||||||
result.descriptionText = "${linkText} battery has too much power (${volts} volts)."
|
result.descriptionText = "${linkText} battery has too much power (${volts} volts)."
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if (device.getDataValue("manufacturer") == "SmartThings") {
|
||||||
|
volts = rawValue // For the batteryMap to work the key needs to be an int
|
||||||
|
def batteryMap = [28:100, 27:100, 26:100, 25:90, 24:90, 23:70,
|
||||||
|
22:70, 21:50, 20:50, 19:30, 18:30, 17:15, 16:1, 15:0]
|
||||||
|
def minVolts = 15
|
||||||
|
def maxVolts = 28
|
||||||
|
|
||||||
|
if (volts < minVolts)
|
||||||
|
volts = minVolts
|
||||||
|
else if (volts > maxVolts)
|
||||||
|
volts = maxVolts
|
||||||
|
def pct = batteryMap[volts]
|
||||||
|
if (pct != null) {
|
||||||
|
result.value = pct
|
||||||
|
result.descriptionText = "${linkText} battery was ${result.value}%"
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
def minVolts = 2.1
|
def minVolts = 2.1
|
||||||
def maxVolts = 3.0
|
def maxVolts = 3.0
|
||||||
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
||||||
result.value = Math.min(100, (int) pct * 100)
|
result.value = Math.min(100, (int) pct * 100)
|
||||||
result.descriptionText = "${linkText} battery was ${result.value}%"
|
result.descriptionText = "${linkText} battery was ${result.value}%"
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@@ -377,10 +394,8 @@ def getTemperature(value) {
|
|||||||
def refreshCmds = []
|
def refreshCmds = []
|
||||||
|
|
||||||
if (device.getDataValue("manufacturer") == "SmartThings") {
|
if (device.getDataValue("manufacturer") == "SmartThings") {
|
||||||
|
|
||||||
log.debug "Refreshing Values for manufacturer: SmartThings "
|
log.debug "Refreshing Values for manufacturer: SmartThings "
|
||||||
refreshCmds = refreshCmds + [
|
refreshCmds = refreshCmds + [
|
||||||
|
|
||||||
/* These values of Motion Threshold Multiplier(01) and Motion Threshold (7602)
|
/* These values of Motion Threshold Multiplier(01) and Motion Threshold (7602)
|
||||||
seem to be giving pretty accurate results for the XYZ co-ordinates for this manufacturer.
|
seem to be giving pretty accurate results for the XYZ co-ordinates for this manufacturer.
|
||||||
Separating these out in a separate if-else because I do not want to touch Centralite part
|
Separating these out in a separate if-else because I do not want to touch Centralite part
|
||||||
@@ -394,13 +409,9 @@ def getTemperature(value) {
|
|||||||
"zcl mfg-code ${manufacturerCode}", "delay 200",
|
"zcl mfg-code ${manufacturerCode}", "delay 200",
|
||||||
"zcl global write 0xFC02 2 0x21 {7602}", "delay 200",
|
"zcl global write 0xFC02 2 0x21 {7602}", "delay 200",
|
||||||
"send 0x${device.deviceNetworkId} 1 1", "delay 400",
|
"send 0x${device.deviceNetworkId} 1 1", "delay 400",
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
refreshCmds = refreshCmds + [
|
refreshCmds = refreshCmds + [
|
||||||
|
|
||||||
/* sensitivity - default value (8) */
|
/* sensitivity - default value (8) */
|
||||||
"zcl mfg-code ${manufacturerCode}", "delay 200",
|
"zcl mfg-code ${manufacturerCode}", "delay 200",
|
||||||
"zcl global write 0xFC02 0 0x20 {02}", "delay 200",
|
"zcl global write 0xFC02 0 0x20 {02}", "delay 200",
|
||||||
@@ -422,12 +433,10 @@ def getTemperature(value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def configure() {
|
def configure() {
|
||||||
|
|
||||||
String zigbeeEui = swapEndianHex(device.hub.zigbeeEui)
|
String zigbeeEui = swapEndianHex(device.hub.zigbeeEui)
|
||||||
log.debug "Configuring Reporting"
|
log.debug "Configuring Reporting"
|
||||||
|
|
||||||
def configCmds = [
|
def configCmds = [
|
||||||
|
|
||||||
"zcl global write 0x500 0x10 0xf0 {${zigbeeEui}}", "delay 200",
|
"zcl global write 0x500 0x10 0xf0 {${zigbeeEui}}", "delay 200",
|
||||||
"send 0x${device.deviceNetworkId} 1 ${endpointId}", "delay 500",
|
"send 0x${device.deviceNetworkId} 1 ${endpointId}", "delay 500",
|
||||||
|
|
||||||
@@ -455,7 +464,6 @@ def getTemperature(value) {
|
|||||||
"zcl mfg-code ${manufacturerCode}",
|
"zcl mfg-code ${manufacturerCode}",
|
||||||
"zcl global send-me-a-report 0xFC02 0x0014 0x29 1 3600 {01}",
|
"zcl global send-me-a-report 0xFC02 0x0014 0x29 1 3600 {01}",
|
||||||
"send 0x${device.deviceNetworkId} 1 ${endpointId}", "delay 500"
|
"send 0x${device.deviceNetworkId} 1 ${endpointId}", "delay 500"
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
return configCmds + refresh()
|
return configCmds + refresh()
|
||||||
@@ -582,5 +590,3 @@ private byte[] reverseArray(byte[] array) {
|
|||||||
}
|
}
|
||||||
return array
|
return array
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user