From 60a98e307401771087fc7e27d4e863dd93ce149d Mon Sep 17 00:00:00 2001 From: jackchi Date: Tue, 20 Sep 2016 11:10:31 -0700 Subject: [PATCH 1/5] [CHF-374] Better healthPoll scheduling for Cree Bulb --- devicetypes/smartthings/cree-bulb.src/cree-bulb.groovy | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/devicetypes/smartthings/cree-bulb.src/cree-bulb.groovy b/devicetypes/smartthings/cree-bulb.src/cree-bulb.groovy index 979b51c..bb67c35 100644 --- a/devicetypes/smartthings/cree-bulb.src/cree-bulb.groovy +++ b/devicetypes/smartthings/cree-bulb.src/cree-bulb.groovy @@ -97,13 +97,14 @@ def refresh() { } def healthPoll() { + log.debug "healthPoll()" def cmds = zigbee.onOffRefresh() + zigbee.levelRefresh() cmds.each{ sendHubCommand(new physicalgraph.device.HubAction(it))} } def configure() { unschedule() - schedule("0 0/5 * * * ? *", "healthPoll") + runEvery5Minutes("healthPoll") log.debug "Configuring Reporting and Bindings." // Device-Watch allows 3 check-in misses from device. 300 seconds x 3 = 15min sendEvent(name: "checkInterval", value: 900, displayed: false, data: [protocol: "zigbee"]) From c17830ab56b15157d47eaf5d0d09904418860f9a Mon Sep 17 00:00:00 2001 From: Parijat Das Date: Tue, 4 Oct 2016 18:19:41 +0530 Subject: [PATCH 2/5] Removed categorization in DTHs for the following devices: 1. SmartSense Moisture Sensor 2. SmartSense Temp/Humidity Sensor 3. SmartSense Multi Sensor 4. SmartSense Open/closed Sensor 5. SmartPower Outlet 6. SmartSense Motion Sensor 7. OSRAM Lightify LED On/Off/Dim 8. OSRAM Lightify LED RGBW 9. OSRAM Lightify Tunable 60 White 10. Tyco Door/Window Sensor --- .../smartthings/smartpower-outlet.src/smartpower-outlet.groovy | 2 +- .../smartsense-moisture-sensor.groovy | 2 +- .../smartsense-motion-sensor.groovy | 2 +- .../smartsense-multi-sensor.src/smartsense-multi-sensor.groovy | 2 +- .../smartsense-open-closed-sensor.groovy | 2 +- .../smartsense-temp-humidity-sensor.groovy | 2 +- .../tyco-door-window-sensor.src/tyco-door-window-sensor.groovy | 2 +- devicetypes/smartthings/zigbee-dimmer.src/zigbee-dimmer.groovy | 2 +- .../smartthings/zigbee-rgbw-bulb.src/zigbee-rgbw-bulb.groovy | 2 +- .../zigbee-white-color-temperature-bulb.groovy | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/devicetypes/smartthings/smartpower-outlet.src/smartpower-outlet.groovy b/devicetypes/smartthings/smartpower-outlet.src/smartpower-outlet.groovy index c27f2a6..358576c 100644 --- a/devicetypes/smartthings/smartpower-outlet.src/smartpower-outlet.groovy +++ b/devicetypes/smartthings/smartpower-outlet.src/smartpower-outlet.groovy @@ -16,7 +16,7 @@ metadata { // Automatically generated. Make future change here. - definition (name: "SmartPower Outlet", namespace: "smartthings", author: "SmartThings", category: "C1") { + definition (name: "SmartPower Outlet", namespace: "smartthings", author: "SmartThings") { capability "Actuator" capability "Switch" capability "Power Meter" diff --git a/devicetypes/smartthings/smartsense-moisture-sensor.src/smartsense-moisture-sensor.groovy b/devicetypes/smartthings/smartsense-moisture-sensor.src/smartsense-moisture-sensor.groovy index 21d791f..8b51662 100644 --- a/devicetypes/smartthings/smartsense-moisture-sensor.src/smartsense-moisture-sensor.groovy +++ b/devicetypes/smartthings/smartsense-moisture-sensor.src/smartsense-moisture-sensor.groovy @@ -17,7 +17,7 @@ import physicalgraph.zigbee.clusters.iaszone.ZoneStatus metadata { - definition (name: "SmartSense Moisture Sensor",namespace: "smartthings", author: "SmartThings", category: "C2") { + definition (name: "SmartSense Moisture Sensor",namespace: "smartthings", author: "SmartThings") { capability "Configuration" capability "Battery" capability "Refresh" diff --git a/devicetypes/smartthings/smartsense-motion-sensor.src/smartsense-motion-sensor.groovy b/devicetypes/smartthings/smartsense-motion-sensor.src/smartsense-motion-sensor.groovy index 5d30bf2..4293bfa 100644 --- a/devicetypes/smartthings/smartsense-motion-sensor.src/smartsense-motion-sensor.groovy +++ b/devicetypes/smartthings/smartsense-motion-sensor.src/smartsense-motion-sensor.groovy @@ -17,7 +17,7 @@ import physicalgraph.zigbee.clusters.iaszone.ZoneStatus metadata { - definition (name: "SmartSense Motion Sensor", namespace: "smartthings", author: "SmartThings", category: "C2") { + definition (name: "SmartSense Motion Sensor", namespace: "smartthings", author: "SmartThings") { capability "Motion Sensor" capability "Configuration" capability "Battery" diff --git a/devicetypes/smartthings/smartsense-multi-sensor.src/smartsense-multi-sensor.groovy b/devicetypes/smartthings/smartsense-multi-sensor.src/smartsense-multi-sensor.groovy index bc6ab6f..606cb01 100644 --- a/devicetypes/smartthings/smartsense-multi-sensor.src/smartsense-multi-sensor.groovy +++ b/devicetypes/smartthings/smartsense-multi-sensor.src/smartsense-multi-sensor.groovy @@ -16,7 +16,7 @@ import physicalgraph.zigbee.clusters.iaszone.ZoneStatus metadata { - definition (name: "SmartSense Multi Sensor", namespace: "smartthings", author: "SmartThings", category: "C2") { + definition (name: "SmartSense Multi Sensor", namespace: "smartthings", author: "SmartThings") { capability "Three Axis" capability "Battery" diff --git a/devicetypes/smartthings/smartsense-open-closed-sensor.src/smartsense-open-closed-sensor.groovy b/devicetypes/smartthings/smartsense-open-closed-sensor.src/smartsense-open-closed-sensor.groovy index ebe83ce..d588dac 100644 --- a/devicetypes/smartthings/smartsense-open-closed-sensor.src/smartsense-open-closed-sensor.groovy +++ b/devicetypes/smartthings/smartsense-open-closed-sensor.src/smartsense-open-closed-sensor.groovy @@ -16,7 +16,7 @@ import physicalgraph.zigbee.clusters.iaszone.ZoneStatus metadata { - definition (name: "SmartSense Open/Closed Sensor", namespace: "smartthings", author: "SmartThings", category: "C2") { + definition (name: "SmartSense Open/Closed Sensor", namespace: "smartthings", author: "SmartThings") { capability "Battery" capability "Configuration" capability "Contact Sensor" diff --git a/devicetypes/smartthings/smartsense-temp-humidity-sensor.src/smartsense-temp-humidity-sensor.groovy b/devicetypes/smartthings/smartsense-temp-humidity-sensor.src/smartsense-temp-humidity-sensor.groovy index 0ce8edc..c83d433 100644 --- a/devicetypes/smartthings/smartsense-temp-humidity-sensor.src/smartsense-temp-humidity-sensor.groovy +++ b/devicetypes/smartthings/smartsense-temp-humidity-sensor.src/smartsense-temp-humidity-sensor.groovy @@ -14,7 +14,7 @@ * */ metadata { - definition (name: "SmartSense Temp/Humidity Sensor",namespace: "smartthings", author: "SmartThings", category: "C2") { + definition (name: "SmartSense Temp/Humidity Sensor",namespace: "smartthings", author: "SmartThings") { capability "Configuration" capability "Battery" capability "Refresh" diff --git a/devicetypes/smartthings/tyco-door-window-sensor.src/tyco-door-window-sensor.groovy b/devicetypes/smartthings/tyco-door-window-sensor.src/tyco-door-window-sensor.groovy index a90ce2e..98f75a0 100644 --- a/devicetypes/smartthings/tyco-door-window-sensor.src/tyco-door-window-sensor.groovy +++ b/devicetypes/smartthings/tyco-door-window-sensor.src/tyco-door-window-sensor.groovy @@ -16,7 +16,7 @@ import physicalgraph.zigbee.clusters.iaszone.ZoneStatus metadata { - definition (name: "Tyco Door/Window Sensor", namespace: "smartthings", author: "SmartThings", category: "C2") { + definition (name: "Tyco Door/Window Sensor", namespace: "smartthings", author: "SmartThings") { capability "Battery" capability "Configuration" capability "Contact Sensor" diff --git a/devicetypes/smartthings/zigbee-dimmer.src/zigbee-dimmer.groovy b/devicetypes/smartthings/zigbee-dimmer.src/zigbee-dimmer.groovy index d1a0b80..e966b79 100644 --- a/devicetypes/smartthings/zigbee-dimmer.src/zigbee-dimmer.groovy +++ b/devicetypes/smartthings/zigbee-dimmer.src/zigbee-dimmer.groovy @@ -13,7 +13,7 @@ */ metadata { - definition (name: "ZigBee Dimmer", namespace: "smartthings", author: "SmartThings", category: "C1") { + definition (name: "ZigBee Dimmer", namespace: "smartthings", author: "SmartThings") { capability "Actuator" capability "Configuration" capability "Refresh" diff --git a/devicetypes/smartthings/zigbee-rgbw-bulb.src/zigbee-rgbw-bulb.groovy b/devicetypes/smartthings/zigbee-rgbw-bulb.src/zigbee-rgbw-bulb.groovy index eb39489..f9a29b5 100644 --- a/devicetypes/smartthings/zigbee-rgbw-bulb.src/zigbee-rgbw-bulb.groovy +++ b/devicetypes/smartthings/zigbee-rgbw-bulb.src/zigbee-rgbw-bulb.groovy @@ -17,7 +17,7 @@ */ metadata { - definition (name: "ZigBee RGBW Bulb", namespace: "smartthings", author: "SmartThings", category: "C6") { + definition (name: "ZigBee RGBW Bulb", namespace: "smartthings", author: "SmartThings") { capability "Actuator" capability "Color Control" diff --git a/devicetypes/smartthings/zigbee-white-color-temperature-bulb.src/zigbee-white-color-temperature-bulb.groovy b/devicetypes/smartthings/zigbee-white-color-temperature-bulb.src/zigbee-white-color-temperature-bulb.groovy index 41d3135..16cd044 100644 --- a/devicetypes/smartthings/zigbee-white-color-temperature-bulb.src/zigbee-white-color-temperature-bulb.groovy +++ b/devicetypes/smartthings/zigbee-white-color-temperature-bulb.src/zigbee-white-color-temperature-bulb.groovy @@ -17,7 +17,7 @@ */ metadata { - definition (name: "ZigBee White Color Temperature Bulb", namespace: "smartthings", author: "SmartThings", category: "C1") { + definition (name: "ZigBee White Color Temperature Bulb", namespace: "smartthings", author: "SmartThings") { capability "Actuator" capability "Color Temperature" From 823efed5625e6edcddf61be456f621975d8a2942 Mon Sep 17 00:00:00 2001 From: Parijat Das Date: Tue, 23 Aug 2016 16:58:14 +0530 Subject: [PATCH 3/5] Added health checks for NYCE open/closed sensor checkInterval value determined and added Implemented ping functionality Fixed indentation in the metadata section --- .../nyce-open-closed-sensor.src/.st-ignore | 2 + .../nyce-open-closed-sensor.src/README.md | 37 ++++++++++++++ .../nyce-open-closed-sensor.groovy | 51 +++++++++++-------- 3 files changed, 68 insertions(+), 22 deletions(-) create mode 100644 devicetypes/smartthings/nyce-open-closed-sensor.src/.st-ignore create mode 100644 devicetypes/smartthings/nyce-open-closed-sensor.src/README.md diff --git a/devicetypes/smartthings/nyce-open-closed-sensor.src/.st-ignore b/devicetypes/smartthings/nyce-open-closed-sensor.src/.st-ignore new file mode 100644 index 0000000..f78b46e --- /dev/null +++ b/devicetypes/smartthings/nyce-open-closed-sensor.src/.st-ignore @@ -0,0 +1,2 @@ +.st-ignore +README.md diff --git a/devicetypes/smartthings/nyce-open-closed-sensor.src/README.md b/devicetypes/smartthings/nyce-open-closed-sensor.src/README.md new file mode 100644 index 0000000..64624e3 --- /dev/null +++ b/devicetypes/smartthings/nyce-open-closed-sensor.src/README.md @@ -0,0 +1,37 @@ +# Nyce Door/Window Sensor (Open/Close Sensor) + + + +Works with: + +* [NYCE Door/Window Sensor NCZ-3011](https://support.smartthings.com/hc/en-us/articles/204576764-NYCE-Door-Window-Sensor) + +## Table of contents + +* [Capabilities](#capabilities) +* [Health](#device-health) +* [Battery](#battery-specification) +* [Troubleshooting](#troubleshooting) + +## Capabilities + +* **Configuration** - _configure()_ command called when device is installed or device preferences updated +* **Contact Sensor** - can detect contact (with possible values - open/closed) +* **Battery** - defines device uses a battery +* **Refresh** - _refresh()_ command for status updates +* **Health Check** - indicates ability to get device health notifications + +## Device Health + +A Category C2 Nyce Door/Window sensor that has 12min check-in interval + +## Battery Specification + +One 3V CR2032 battery required. + +## Troubleshooting + +If the device doesn't pair when trying from the SmartThings mobile app, it is possible that the sensor is out of range. +Pairing needs to be tried again by placing the sensor closer to the hub. +Instructions related to pairing, resetting and removing the sensor from SmartThings can be found in the following link: +* [Nyce Door/Window Sensor](https://support.smartthings.com/hc/en-us/articles/204576764-NYCE-Door-Window-Sensor) diff --git a/devicetypes/smartthings/nyce-open-closed-sensor.src/nyce-open-closed-sensor.groovy b/devicetypes/smartthings/nyce-open-closed-sensor.src/nyce-open-closed-sensor.groovy index 506ca89..7f75068 100644 --- a/devicetypes/smartthings/nyce-open-closed-sensor.src/nyce-open-closed-sensor.groovy +++ b/devicetypes/smartthings/nyce-open-closed-sensor.src/nyce-open-closed-sensor.groovy @@ -19,25 +19,26 @@ import physicalgraph.zigbee.clusters.iaszone.ZoneStatus metadata { definition (name: "NYCE Open/Closed Sensor", namespace: "smartthings", author: "NYCE") { - capability "Battery" + capability "Battery" capability "Configuration" - capability "Contact Sensor" + capability "Contact Sensor" capability "Refresh" - - command "enrollResponse" - - - fingerprint inClusters: "0000,0001,0003,0500,0020", manufacturer: "NYCE", model: "3010", deviceJoinName: "NYCE Door Hinge Sensor" + capability "Health Check" + + command "enrollResponse" + + + fingerprint inClusters: "0000,0001,0003,0500,0020", manufacturer: "NYCE", model: "3010", deviceJoinName: "NYCE Door Hinge Sensor" fingerprint inClusters: "0000,0001,0003,0406,0500,0020", manufacturer: "NYCE", model: "3011", deviceJoinName: "NYCE Door/Window Sensor" - fingerprint inClusters: "0000,0001,0003,0500,0020", manufacturer: "NYCE", model: "3011", deviceJoinName: "NYCE Door/Window Sensor" - fingerprint inClusters: "0000,0001,0003,0406,0500,0020", manufacturer: "NYCE", model: "3014", deviceJoinName: "NYCE Tilt Sensor" - fingerprint inClusters: "0000,0001,0003,0500,0020", manufacturer: "NYCE", model: "3014", deviceJoinName: "NYCE Tilt Sensor" + fingerprint inClusters: "0000,0001,0003,0500,0020", manufacturer: "NYCE", model: "3011", deviceJoinName: "NYCE Door/Window Sensor" + fingerprint inClusters: "0000,0001,0003,0406,0500,0020", manufacturer: "NYCE", model: "3014", deviceJoinName: "NYCE Tilt Sensor" + fingerprint inClusters: "0000,0001,0003,0500,0020", manufacturer: "NYCE", model: "3014", deviceJoinName: "NYCE Tilt Sensor" } - + simulator { - + } - + tiles { standardTile("contact", "device.contact", width: 2, height: 2) { state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e") @@ -273,23 +274,28 @@ private List parseIasMessage(String description) { return resultListMap } +/** + * PING is used by Device-Watch in attempt to reach the Device + * */ +def ping() { + return zigbee.readAttribute(0x001, 0x0020) // Read the Battery Level +} + def configure() { + // Device-Watch allows 2 check-in misses from device + sendEvent(name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID]) + String zigbeeEui = swapEndianHex(device.hub.zigbeeEui) - def configCmds = [ - //battery reporting and heartbeat - "zdo bind 0x${device.deviceNetworkId} 1 ${endpointId} 1 {${device.zigbeeId}} {}", "delay 200", - "zcl global send-me-a-report 1 0x20 0x20 600 3600 {01}", "delay 200", - "send 0x${device.deviceNetworkId} 1 ${endpointId}", "delay 1500", - - + def enrollCmds = [ // Writes CIE attribute on end device to direct reports to the hub's EUID "zcl global write 0x500 0x10 0xf0 {${zigbeeEui}}", "delay 200", "send 0x${device.deviceNetworkId} 1 1", "delay 500", ] log.debug "configure: Write IAS CIE" - return configCmds + // battery minReportTime 30 seconds, maxReportTime 5 min. Reporting interval if no activity + return enrollCmds + zigbee.batteryConfig(30, 300) + refresh() // send refresh cmds as part of config } def enrollResponse() { @@ -334,7 +340,8 @@ Integer convertHexToInt(hex) { def refresh() { log.debug "Refreshing Battery" - [ + def refreshCmds = [ "st rattr 0x${device.deviceNetworkId} ${endpointId} 1 0x20", "delay 200" ] + return refreshCmds + enrollResponse() } From 427fa88ed855d368663cc8b9dd4fcb0b92ac76b6 Mon Sep 17 00:00:00 2001 From: Juan Pablo Risso Date: Wed, 5 Oct 2016 14:33:38 -0400 Subject: [PATCH 4/5] Harmony - Fix Exceptions (#1321) response.status --- .../logitech-harmony-connect.groovy | 83 +++---------------- 1 file changed, 12 insertions(+), 71 deletions(-) diff --git a/smartapps/smartthings/logitech-harmony-connect.src/logitech-harmony-connect.groovy b/smartapps/smartthings/logitech-harmony-connect.src/logitech-harmony-connect.groovy index 2597e2b..0da1df6 100644 --- a/smartapps/smartthings/logitech-harmony-connect.src/logitech-harmony-connect.groovy +++ b/smartapps/smartthings/logitech-harmony-connect.src/logitech-harmony-connect.groovy @@ -362,7 +362,7 @@ Map discoverDevices() { def hubname = getHubName(it.key) def hubvalue = "${hubname}" hubs["harmony-${hubkey}"] = hubvalue - it.value.response.data.activities.each { + it.value.response.data.activities.each { def value = "${it.value.name}" def key = "harmony-${hubkey}-${it.key}" activities["${key}"] = value @@ -461,22 +461,11 @@ def activityResponse(response, data) { log.warn "Logitech Harmony - Access token has expired" } } else { - def ResponseValues - try { - // json response already parsed into JSONElement object - ResponseValues = response.json - } catch (e) { - log.error "Logitech Harmony - error parsing json from response: $e" - } - if (ResponseValues) { - if (ResponseValues.code == 200) { - log.trace "Command sent succesfully" - poll() - } else { - log.trace "Command failed. Error: $response.data.code" - } + if (response.status == 200) { + log.trace "Command sent succesfully" + poll() } else { - log.debug "Logitech Harmony - did not get json results from response body: $response.data" + log.trace "Command failed. Error: $response.status" } } } @@ -484,7 +473,6 @@ def activityResponse(response, data) { def poll() { // GET THE LIST OF ACTIVITIES if (state.HarmonyAccessToken) { - getActivityList() def tokenParam = [auth: state.HarmonyAccessToken] def params = [ uri: "https://home.myharmony.com/cloudapi/state?${toQueryString(tokenParam)}", @@ -493,7 +481,7 @@ def poll() { ] asynchttp_v1.get('pollResponse', params) } else { - log.warn "Logitech Harmony - Access token has expired" + log.warn "Logitech Harmony - Access token has expired" } } @@ -522,7 +510,12 @@ def pollResponse(response, data) { if (it.value.response.data.currentAvActivity == "-1") { hub.sendEvent(name: "currentActivity", value: "--", descriptionText: "There isn't any activity running", display: false) } else { - def currentActivity = getChildDevice("harmony-${it.key}-${it.value.response.data.currentAvActivity}").device.displayName + def currentActivity + def activityDTH = getChildDevice("harmony-${it.key}-${it.value.response.data.currentAvActivity}") + if (activityDTH) + currentActivity = activityDTH.device.displayName + else + currentActivity = getActivityName(it.value.response.data.currentAvActivity,it.key) hub.sendEvent(name: "currentActivity", value: currentActivity, descriptionText: "Current activity is ${currentActivity}", display: false) } } @@ -557,58 +550,6 @@ def pollResponse(response, data) { } } -def getActivityList() { - if (state.HarmonyAccessToken) { - def tokenParam = [auth: state.HarmonyAccessToken] - def params = [ - uri: "https://home.myharmony.com/cloudapi/activity/all?${toQueryString(tokenParam)}", - headers: ["Accept": "application/json"], - contentType: 'application/json' - ] - asynchttp_v1.get('activityListResponse', params) - } else { - log.warn "Logitech Harmony - Access token has expired" - } -} - -def activityListResponse(response, data) { - if (response.hasError()) { - log.error "Logitech Harmony - response has error: $response.errorMessage" - if (response.status == 401) { // token is expired - state.remove("HarmonyAccessToken") - log.warn "Logitech Harmony - Access token has expired" - } - } else { - def ResponseValues - try { - // json response already parsed into JSONElement object - ResponseValues = response.json - } catch (e) { - log.error "Logitech Harmony - error parsing json from response: $e" - } - if (ResponseValues) { - ResponseValues.hubs.each { - def hub = getChildDevice("harmony-${it.key}") - if (hub) { - def hubname = getHubName("${it.key}") - def activities = [] - def aux = it.value.response?.data.activities.size() - if (aux >= 1) { - activities = it.value.response.data.activities.collect { - [id: it.key, name: it.value['name'], type: it.value['type']] - } - activities += [id: "off", name: "Activity OFF", type: "0"] - log.trace activities - } - hub.sendEvent(name: "activities", value: new groovy.json.JsonBuilder(activities).toString(), descriptionText: "Activities are ${activities.collect { it.name }?.join(', ')}", display: false) - } - } - } else { - log.debug "Logitech Harmony - did not get json results from response body: $response.data" - } - } -} - def getActivityName(activity,hubId) { // GET ACTIVITY'S NAME def actname = activity From 12b09acfa8409468fb1350fd07a657bb021de0d6 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 6 Oct 2016 15:44:16 -0700 Subject: [PATCH 5/5] alterSetpoint - check for auto or off mode changed debug message --- .../ecobee-thermostat.groovy | 91 ++++++++++--------- 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/devicetypes/smartthings/ecobee-thermostat.src/ecobee-thermostat.groovy b/devicetypes/smartthings/ecobee-thermostat.src/ecobee-thermostat.groovy index 1b8d775..37cbb85 100644 --- a/devicetypes/smartthings/ecobee-thermostat.src/ecobee-thermostat.groovy +++ b/devicetypes/smartthings/ecobee-thermostat.src/ecobee-thermostat.groovy @@ -655,55 +655,60 @@ void lowerSetpoint() { void alterSetpoint(temp) { def mode = device.currentValue("thermostatMode") - def heatingSetpoint = device.currentValue("heatingSetpoint") - def coolingSetpoint = device.currentValue("coolingSetpoint") - def deviceId = device.deviceNetworkId.split(/\./).last() - def targetHeatingSetpoint - def targetCoolingSetpoint - - //step1: check thermostatMode, enforce limits before sending request to cloud - if (mode == "heat" || mode == "auxHeatOnly"){ - if (temp.value > coolingSetpoint){ - targetHeatingSetpoint = temp.value - targetCoolingSetpoint = temp.value - } else { - targetHeatingSetpoint = temp.value - targetCoolingSetpoint = coolingSetpoint - } - } else if (mode == "cool") { - //enforce limits before sending request to cloud - if (temp.value < heatingSetpoint){ - targetHeatingSetpoint = temp.value - targetCoolingSetpoint = temp.value - } else { - targetHeatingSetpoint = heatingSetpoint - targetCoolingSetpoint = temp.value - } - } - - log.debug "alterSetpoint >> in mode ${mode} trying to change heatingSetpoint to $targetHeatingSetpoint " + - "coolingSetpoint to $targetCoolingSetpoint with holdType : ${holdType}" - - def sendHoldType = holdType ? (holdType=="Temporary")? "nextTransition" : (holdType=="Permanent")? "indefinite" : "indefinite" : "indefinite" - - def coolingValue = location.temperatureScale == "C"? convertCtoF(targetCoolingSetpoint) : targetCoolingSetpoint - def heatingValue = location.temperatureScale == "C"? convertCtoF(targetHeatingSetpoint) : targetHeatingSetpoint - - if (parent.setHold(heatingValue, coolingValue, deviceId, sendHoldType)) { - sendEvent("name": "thermostatSetpoint", "value": temp.value, displayed: false) - sendEvent("name": "heatingSetpoint", "value": targetHeatingSetpoint, "unit": location.temperatureScale) - sendEvent("name": "coolingSetpoint", "value": targetCoolingSetpoint, "unit": location.temperatureScale) - log.debug "alterSetpoint in mode $mode succeed change setpoint to= ${temp.value}" + if (mode == "off" || mode == "auto") { + log.warn "this mode: $mode does not allow alterSetpoint" } else { - log.error "Error alterSetpoint()" + def heatingSetpoint = device.currentValue("heatingSetpoint") + def coolingSetpoint = device.currentValue("coolingSetpoint") + def deviceId = device.deviceNetworkId.split(/\./).last() + + def targetHeatingSetpoint + def targetCoolingSetpoint + + //step1: check thermostatMode, enforce limits before sending request to cloud if (mode == "heat" || mode == "auxHeatOnly"){ - sendEvent("name": "thermostatSetpoint", "value": heatingSetpoint.toString(), displayed: false) + if (temp.value > coolingSetpoint){ + targetHeatingSetpoint = temp.value + targetCoolingSetpoint = temp.value + } else { + targetHeatingSetpoint = temp.value + targetCoolingSetpoint = coolingSetpoint + } } else if (mode == "cool") { - sendEvent("name": "thermostatSetpoint", "value": coolingSetpoint.toString(), displayed: false) + //enforce limits before sending request to cloud + if (temp.value < heatingSetpoint){ + targetHeatingSetpoint = temp.value + targetCoolingSetpoint = temp.value + } else { + targetHeatingSetpoint = heatingSetpoint + targetCoolingSetpoint = temp.value + } } + + log.debug "alterSetpoint >> in mode ${mode} trying to change heatingSetpoint to $targetHeatingSetpoint " + + "coolingSetpoint to $targetCoolingSetpoint with holdType : ${holdType}" + + def sendHoldType = holdType ? (holdType=="Temporary")? "nextTransition" : (holdType=="Permanent")? "indefinite" : "indefinite" : "indefinite" + + def coolingValue = location.temperatureScale == "C"? convertCtoF(targetCoolingSetpoint) : targetCoolingSetpoint + def heatingValue = location.temperatureScale == "C"? convertCtoF(targetHeatingSetpoint) : targetHeatingSetpoint + + if (parent.setHold(heatingValue, coolingValue, deviceId, sendHoldType)) { + sendEvent("name": "thermostatSetpoint", "value": temp.value, displayed: false) + sendEvent("name": "heatingSetpoint", "value": targetHeatingSetpoint, "unit": location.temperatureScale) + sendEvent("name": "coolingSetpoint", "value": targetCoolingSetpoint, "unit": location.temperatureScale) + log.debug "alterSetpoint in mode $mode succeed change setpoint to= ${temp.value}" + } else { + log.error "Error alterSetpoint()" + if (mode == "heat" || mode == "auxHeatOnly"){ + sendEvent("name": "thermostatSetpoint", "value": heatingSetpoint.toString(), displayed: false) + } else if (mode == "cool") { + sendEvent("name": "thermostatSetpoint", "value": coolingSetpoint.toString(), displayed: false) + } + } + generateStatusEvent() } - generateStatusEvent() } def generateStatusEvent() {