mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-09 13:21:53 +00:00
Compare commits
14 Commits
MSA-1483-1
...
PROD_2016.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aae7f23a22 | ||
|
|
aab3b8d7f8 | ||
|
|
a0ccf35eaa | ||
|
|
02f30cf425 | ||
|
|
fea802ffce | ||
|
|
6400d26f4a | ||
|
|
5e3aaa3270 | ||
|
|
f5c3997679 | ||
|
|
30993aa218 | ||
|
|
2f8ed277ff | ||
|
|
8c4f7edc83 | ||
|
|
4f188581df | ||
|
|
0b7bb40474 | ||
|
|
e373b6f92e |
@@ -23,8 +23,10 @@ Works with:
|
||||
|
||||
## Device Health
|
||||
|
||||
A Category C6 Connected Cree LED Bulb with maxReportTime of 5 mins.
|
||||
Check-in interval = 12 mins
|
||||
A Category C6 Connected Cree LED Bulb with maxReportTime of 10 min.
|
||||
Check-in interval is double the value of maxReportTime for Zigbee device.
|
||||
This gives the device twice the amount of time to respond before it is marked as offline.
|
||||
Check-in interval = 2*10 = 20 min
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
|
||||
@@ -23,10 +23,10 @@ Works with:
|
||||
|
||||
## Device Health
|
||||
|
||||
A Category C1 smart power outlet with maxReportTime of 5 mins.
|
||||
Check-in interval is double the value of maxReportTime.
|
||||
A Category C1 smart power outlet with maxReportTime of 10 min.
|
||||
Check-in interval is double the value of maxReportTime for Zigbee device.
|
||||
This gives the device twice the amount of time to respond before it is marked as offline.
|
||||
Check-in interval = 12 mins
|
||||
Check-in interval = 2*10 = 20 min
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
|
||||
@@ -23,10 +23,10 @@ Works with:
|
||||
|
||||
## Device Health
|
||||
|
||||
A Category C2 moisture sensor with maxReportTime of 5 mins.
|
||||
Check-in interval is double the value of maxReportTime.
|
||||
A Category C2 moisture sensor with maxReportTime of 1 hr.
|
||||
Check-in interval is double the value of maxReportTime for Zigbee device.
|
||||
This gives the device twice the amount of time to respond before it is marked as offline.
|
||||
Check-in interval = 12 mins
|
||||
Check-in interval = 2*60 = 120 min
|
||||
|
||||
## Battery Specification
|
||||
|
||||
|
||||
@@ -180,9 +180,9 @@ private Map parseIasMessage(String description) {
|
||||
def getTemperature(value) {
|
||||
def celsius = Integer.parseInt(value, 16).shortValue() / 100
|
||||
if(getTemperatureScale() == "C"){
|
||||
return celsius
|
||||
return Math.round(celsius)
|
||||
} else {
|
||||
return celsiusToFahrenheit(celsius) as Integer
|
||||
return Math.round(celsiusToFahrenheit(celsius))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,10 +22,10 @@ Works with:
|
||||
|
||||
## Device Health
|
||||
|
||||
A Category C2 motion sensor with maxReportTime of 5 mins.
|
||||
Check-in interval is double the value of maxReportTime.
|
||||
A Category C2 motion sensor with maxReportTime of 1 hr.
|
||||
Check-in interval is double the value of maxReportTime for Zigbee device.
|
||||
This gives the device twice the amount of time to respond before it is marked as offline.
|
||||
Check-in interval = 12 mins
|
||||
Check-in interval = 2*60 = 120 min
|
||||
|
||||
## Battery Specification
|
||||
|
||||
|
||||
@@ -194,9 +194,9 @@ private Map parseIasMessage(String description) {
|
||||
def getTemperature(value) {
|
||||
def celsius = Integer.parseInt(value, 16).shortValue() / 100
|
||||
if(getTemperatureScale() == "C"){
|
||||
return celsius
|
||||
return Math.round(celsius)
|
||||
} else {
|
||||
return celsiusToFahrenheit(celsius) as Integer
|
||||
return Math.round(celsiusToFahrenheit(celsius))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,10 +26,10 @@ Works with:
|
||||
|
||||
## Device Health
|
||||
|
||||
A Category C2 multi sensor with maxReportTime of 5 mins.
|
||||
Check-in interval is double the value of maxReportTime.
|
||||
A Category C2 multi sensor with maxReportTime of 1 hr.
|
||||
Check-in interval is double the value of maxReportTime for Zigbee device.
|
||||
This gives the device twice the amount of time to respond before it is marked as offline.
|
||||
Check-in interval = 12 mins
|
||||
Check-in interval = 2*60 = 120 min
|
||||
|
||||
## Battery Specification
|
||||
|
||||
|
||||
@@ -261,9 +261,9 @@ def updated() {
|
||||
def getTemperature(value) {
|
||||
def celsius = Integer.parseInt(value, 16).shortValue() / 100
|
||||
if(getTemperatureScale() == "C"){
|
||||
return celsius
|
||||
return Math.round(celsius)
|
||||
} else {
|
||||
return celsiusToFahrenheit(celsius) as Integer
|
||||
return Math.round(celsiusToFahrenheit(celsius))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,10 +24,10 @@ Works with:
|
||||
|
||||
## Device Health
|
||||
|
||||
A Category C2 open/closed sensor with maxReportTime of 5 mins.
|
||||
Check-in interval is double the value of maxReportTime.
|
||||
A Category C2 open/closed sensor with maxReportTime of 1 hr.
|
||||
Check-in interval is double the value of maxReportTime for Zigbee device.
|
||||
This gives the device twice the amount of time to respond before it is marked as offline.
|
||||
Check-in interval = 12 mins
|
||||
Check-in interval = 2*60 = 120 min
|
||||
|
||||
## Battery Specification
|
||||
|
||||
|
||||
@@ -24,10 +24,10 @@ Works with:
|
||||
|
||||
## Device Health
|
||||
|
||||
A Category C2 SmartSense Temp/Humidity Sensor with maxReportTime of 5 mins.
|
||||
Check-in interval is double the value of maxReportTime.
|
||||
A Category C2 SmartSense Temp/Humidity Sensor with maxReportTime of 1 hr.
|
||||
Check-in interval is double the value of maxReportTime for Zigbee device.
|
||||
This gives the device twice the amount of time to respond before it is marked as offline.
|
||||
Check-in interval = 12 mins
|
||||
Check-in interval = 2*60 = 120 min
|
||||
|
||||
## Battery Specification
|
||||
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
.st-ignore
|
||||
README.md
|
||||
@@ -1,36 +0,0 @@
|
||||
# OSRAM Lightify LED On/Off/Dim
|
||||
|
||||
|
||||
|
||||
Works with:
|
||||
|
||||
* [OSRAM Lightify LED On/Off/Dim](https://shop.smartthings.com/#!/products/osram-led-smart-bulb-on-off-dim)
|
||||
|
||||
## Table of contents
|
||||
|
||||
* [Capabilities](#capabilities)
|
||||
* [Health](#device-health)
|
||||
* [Battery](#battery-specification)
|
||||
|
||||
## Capabilities
|
||||
|
||||
* **Actuator** - represents that a Device has commands
|
||||
* **Configuration** - _configure()_ command called when device is installed or device preferences updated
|
||||
* **Refresh** - _refresh()_ command for status updates
|
||||
* **Switch** - can detect state (possible values: on/off)
|
||||
* **Switch Level** - represents current light level, usually 0-100 in percent
|
||||
* **Health Check** - indicates ability to get device health notifications
|
||||
|
||||
## Device Health
|
||||
|
||||
A Category C1 Zigbee dimmer with maxReportTime of 5 mins.
|
||||
Check-in interval is double the value of maxReportTime.
|
||||
This gives the device twice the amount of time to respond before it is marked as offline.
|
||||
Check-in interval = 12 mins
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If the device doesn't pair when trying from the SmartThings mobile app, it is possible that the device is out of range.
|
||||
Pairing needs to be tried again by placing the device closer to the hub.
|
||||
Other troubleshooting tips are listed as follows:
|
||||
* [Troubleshooting:](https://support.smartthings.com/hc/en-us/articles/207191763-OSRAM-LIGHTIFY-LED-Smart-Connected-Light-A19-On-Off-Dim)
|
||||
@@ -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"
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
.st-ignore
|
||||
README.md
|
||||
@@ -1,42 +0,0 @@
|
||||
# OSRAM LIGHTIFY LED RGBW Bulb
|
||||
|
||||
|
||||
|
||||
Works with:
|
||||
|
||||
* [OSRAM LIGHTIFY LED RGBW Bulb](https://support.smartthings.com/hc/en-us/articles/207728173-OSRAM-LIGHTIFY-LED-Smart-Connected-Light-A19-RGBW)
|
||||
|
||||
## Table of contents
|
||||
|
||||
* [Capabilities](#capabilities)
|
||||
* [Health](#device-health)
|
||||
* [Battery](#battery-specification)
|
||||
|
||||
## Capabilities
|
||||
|
||||
* **Actuator** - It represents that a device has commands.
|
||||
* **Color Control** - It represents that the color attributes of a device can be controlled (hue, saturation, color value).
|
||||
* **Color Temperature** - It represents color temperature capability measured in degree Kelvin.
|
||||
* **Polling** - It represents that a device can be polled.
|
||||
* **Switch** - can detect state (possible values: on/off)
|
||||
* **Switch Level** - can detect current light level (0-100 in percent)
|
||||
* **Configuration** - _configure()_ command called when device is installed or device preferences updated
|
||||
* **Refresh** - _refresh()_ command for status updates
|
||||
* **Health Check** - indicates ability to get device health notifications
|
||||
|
||||
|
||||
## Device Health
|
||||
|
||||
A Category C6 OSRAM LIGHTIFY LED RGBW Bulb with maxReportTime of 5 mins.
|
||||
Check-in interval is double the value of maxReportTime.
|
||||
This gives the device twice the amount of time to respond before it is marked as offline.
|
||||
Check-in interval = 12 mins
|
||||
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If the device doesn't pair when trying from the SmartThings mobile app, it is possible that the device is out of range.
|
||||
Pairing needs to be tried again by placing the device closer to the hub.
|
||||
It may also happen that you need to reset the device.
|
||||
Instructions related to pairing, resetting and removing the device from SmartThings can be found in the following link:
|
||||
* [Troubleshooting Tips](https://support.smartthings.com/hc/en-us/articles/207728173-OSRAM-LIGHTIFY-LED-Smart-Connected-Light-A19-RGBW)
|
||||
@@ -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"
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
.st-ignore
|
||||
README.md
|
||||
@@ -1,37 +0,0 @@
|
||||
# OSRAM Lightify Tunable 60 White
|
||||
|
||||
|
||||
|
||||
Works with:
|
||||
|
||||
* [OSRAM Lightify Tunable 60 White](http://www.osram.com/osram_com/tools-and-services/tools/lightify---smart-connected-light/lightify-for-home---what-is-light-to-you/lightify-products/lightify-classic-a60-tunable-white/index.jsp)
|
||||
|
||||
## Table of contents
|
||||
|
||||
* [Capabilities](#capabilities)
|
||||
* [Health](#device-health)
|
||||
* [Battery](#battery-specification)
|
||||
|
||||
## Capabilities
|
||||
|
||||
* **Actuator** - represents that a Device has commands
|
||||
* **Color Temperature** - represents color temperature, measured in degrees Kelvin.
|
||||
* **Configuration** - _configure()_ command called when device is installed or device preferences updated.
|
||||
* **Refresh** - _refresh()_ command for status updates
|
||||
* **Switch** - can detect state (possible values: on/off)
|
||||
* **Switch Level** - represents current light level, usually 0-100 in percent
|
||||
* **Health Check** - indicates ability to get device health notifications
|
||||
|
||||
## Device Health
|
||||
|
||||
A Category C1 OSRAM Lightify Tunable 60 White with maxReportTime of 5 mins.
|
||||
Check-in interval is double the value of maxReportTime.
|
||||
This gives the device twice the amount of time to respond before it is marked as offline.
|
||||
Check-in interval = 12 mins
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If the device doesn't pair when trying from the SmartThings mobile app, it is possible that the device is out of range.
|
||||
Pairing needs to be tried again by placing the device closer to the hub.
|
||||
Other troubleshooting tips are listed as follows:
|
||||
* [Troubleshooting:](https://support.smartthings.com/hc/en-us/articles/204576454-OSRAM-LIGHTIFY-Tunable-White-60-Bulb)
|
||||
@@ -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"
|
||||
|
||||
@@ -1,683 +0,0 @@
|
||||
/**
|
||||
* Copyright 2015 SmartThings
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing permissions and limitations under the License.
|
||||
*
|
||||
*/
|
||||
metadata {
|
||||
definition (name: "Z-Wave Lock Reporting", namespace: "smartthings", author: "SmartThings") {
|
||||
capability "Actuator"
|
||||
capability "Lock"
|
||||
capability "Polling"
|
||||
capability "Refresh"
|
||||
capability "Sensor"
|
||||
capability "Lock Codes"
|
||||
capability "Battery"
|
||||
|
||||
command "unlockwtimeout"
|
||||
|
||||
fingerprint deviceId: "0x4003", inClusters: "0x98"
|
||||
fingerprint deviceId: "0x4004", inClusters: "0x98"
|
||||
}
|
||||
|
||||
simulator {
|
||||
status "locked": "command: 9881, payload: 00 62 03 FF 00 00 FE FE"
|
||||
status "unlocked": "command: 9881, payload: 00 62 03 00 00 00 FE FE"
|
||||
|
||||
reply "9881006201FF,delay 4200,9881006202": "command: 9881, payload: 00 62 03 FF 00 00 FE FE"
|
||||
reply "988100620100,delay 4200,9881006202": "command: 9881, payload: 00 62 03 00 00 00 FE FE"
|
||||
}
|
||||
|
||||
tiles(scale: 2) {
|
||||
multiAttributeTile(name:"toggle", type: "generic", width: 6, height: 4){
|
||||
tileAttribute ("device.lock", key: "PRIMARY_CONTROL") {
|
||||
attributeState "locked", label:'locked', action:"lock.unlock", icon:"st.locks.lock.locked", backgroundColor:"#79b821", nextState:"unlocking"
|
||||
attributeState "unlocked", label:'unlocked', action:"lock.lock", icon:"st.locks.lock.unlocked", backgroundColor:"#ffffff", nextState:"locking"
|
||||
attributeState "unknown", label:"unknown", action:"lock.lock", icon:"st.locks.lock.unknown", backgroundColor:"#ffffff", nextState:"locking"
|
||||
attributeState "locking", label:'locking', icon:"st.locks.lock.locked", backgroundColor:"#79b821"
|
||||
attributeState "unlocking", label:'unlocking', icon:"st.locks.lock.unlocked", backgroundColor:"#ffffff"
|
||||
}
|
||||
}
|
||||
standardTile("lock", "device.lock", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
|
||||
state "default", label:'lock', action:"lock.lock", icon:"st.locks.lock.locked", nextState:"locking"
|
||||
}
|
||||
standardTile("unlock", "device.lock", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
|
||||
state "default", label:'unlock', action:"lock.unlock", icon:"st.locks.lock.unlocked", nextState:"unlocking"
|
||||
}
|
||||
valueTile("battery", "device.battery", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
|
||||
state "battery", label:'${currentValue}% battery', unit:""
|
||||
}
|
||||
standardTile("refresh", "device.lock", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
|
||||
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
|
||||
}
|
||||
|
||||
main "toggle"
|
||||
details(["toggle", "lock", "unlock", "battery", "refresh"])
|
||||
}
|
||||
}
|
||||
|
||||
import physicalgraph.zwave.commands.doorlockv1.*
|
||||
import physicalgraph.zwave.commands.usercodev1.*
|
||||
|
||||
def updated() {
|
||||
try {
|
||||
if (!state.init) {
|
||||
state.init = true
|
||||
response(secureSequence([zwave.doorLockV1.doorLockOperationGet(), zwave.batteryV1.batteryGet()]))
|
||||
}
|
||||
} catch (e) {
|
||||
log.warn "updated() threw $e"
|
||||
}
|
||||
}
|
||||
|
||||
def parse(String description) {
|
||||
def result = null
|
||||
if (description.startsWith("Err 106")) {
|
||||
if (state.sec) {
|
||||
result = createEvent(descriptionText:description, displayed:false)
|
||||
} else {
|
||||
result = createEvent(
|
||||
descriptionText: "This lock failed to complete the network security key exchange. If you are unable to control it via SmartThings, you must remove it from your network and add it again.",
|
||||
eventType: "ALERT",
|
||||
name: "secureInclusion",
|
||||
value: "failed",
|
||||
displayed: true,
|
||||
)
|
||||
}
|
||||
} else if (description == "updated") {
|
||||
return null
|
||||
} else {
|
||||
def cmd = zwave.parse(description, [ 0x98: 1, 0x72: 2, 0x85: 2, 0x86: 1 ])
|
||||
if (cmd) {
|
||||
result = zwaveEvent(cmd)
|
||||
}
|
||||
}
|
||||
log.debug "\"$description\" parsed to ${result.inspect()}"
|
||||
result
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) {
|
||||
def encapsulatedCommand = cmd.encapsulatedCommand([0x62: 1, 0x71: 2, 0x80: 1, 0x85: 2, 0x63: 1, 0x98: 1, 0x86: 1])
|
||||
// log.debug "encapsulated: $encapsulatedCommand"
|
||||
if (encapsulatedCommand) {
|
||||
zwaveEvent(encapsulatedCommand)
|
||||
}
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.securityv1.NetworkKeyVerify cmd) {
|
||||
createEvent(name:"secureInclusion", value:"success", descriptionText:"Secure inclusion was successful")
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityCommandsSupportedReport cmd) {
|
||||
state.sec = cmd.commandClassSupport.collect { String.format("%02X ", it) }.join()
|
||||
if (cmd.commandClassControl) {
|
||||
state.secCon = cmd.commandClassControl.collect { String.format("%02X ", it) }.join()
|
||||
}
|
||||
log.debug "Security command classes: $state.sec"
|
||||
createEvent(name:"secureInclusion", value:"success", descriptionText:"Lock is securely included")
|
||||
}
|
||||
|
||||
def zwaveEvent(DoorLockOperationReport cmd) {
|
||||
def result = []
|
||||
def map = [ name: "lock" ]
|
||||
if (cmd.doorLockMode == 0xFF) {
|
||||
map.value = "locked"
|
||||
} else if (cmd.doorLockMode >= 0x40) {
|
||||
map.value = "unknown"
|
||||
} else if (cmd.doorLockMode & 1) {
|
||||
map.value = "unlocked with timeout"
|
||||
} else {
|
||||
map.value = "unlocked"
|
||||
if (state.assoc != zwaveHubNodeId) {
|
||||
log.debug "setting association"
|
||||
result << response(secure(zwave.associationV1.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId)))
|
||||
result << response(zwave.associationV1.associationSet(groupingIdentifier:2, nodeId:zwaveHubNodeId))
|
||||
result << response(secure(zwave.associationV1.associationGet(groupingIdentifier:1)))
|
||||
}
|
||||
}
|
||||
result ? [createEvent(map), *result] : createEvent(map)
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.alarmv2.AlarmReport cmd) {
|
||||
def result = []
|
||||
def map = null
|
||||
if (cmd.zwaveAlarmType == 6) {
|
||||
if (1 <= cmd.zwaveAlarmEvent && cmd.zwaveAlarmEvent < 10) {
|
||||
map = [ name: "lock", value: (cmd.zwaveAlarmEvent & 1) ? "locked" : "unlocked" ]
|
||||
}
|
||||
switch(cmd.zwaveAlarmEvent) {
|
||||
case 1:
|
||||
map.descriptionText = "$device.displayName was manually locked"
|
||||
break
|
||||
case 2:
|
||||
map.descriptionText = "$device.displayName was manually unlocked"
|
||||
break
|
||||
case 5:
|
||||
if (cmd.eventParameter) {
|
||||
map.descriptionText = "$device.displayName was locked with code ${cmd.eventParameter.first()}"
|
||||
map.data = [ usedCode: cmd.eventParameter[0] ]
|
||||
}
|
||||
break
|
||||
case 6:
|
||||
if (cmd.eventParameter) {
|
||||
map.descriptionText = "$device.displayName was unlocked with code ${cmd.eventParameter.first()}"
|
||||
map.data = [ usedCode: cmd.eventParameter[0] ]
|
||||
}
|
||||
break
|
||||
case 9:
|
||||
map.descriptionText = "$device.displayName was autolocked"
|
||||
break
|
||||
case 7:
|
||||
case 8:
|
||||
case 0xA:
|
||||
map = [ name: "lock", value: "unknown", descriptionText: "$device.displayName was not locked fully" ]
|
||||
break
|
||||
case 0xB:
|
||||
map = [ name: "lock", value: "unknown", descriptionText: "$device.displayName is jammed" ]
|
||||
break
|
||||
case 0xC:
|
||||
map = [ name: "codeChanged", value: "all", descriptionText: "$device.displayName: all user codes deleted", isStateChange: true ]
|
||||
allCodesDeleted()
|
||||
break
|
||||
case 0xD:
|
||||
if (cmd.eventParameter) {
|
||||
map = [ name: "codeReport", value: cmd.eventParameter[0], data: [ code: "" ], isStateChange: true ]
|
||||
map.descriptionText = "$device.displayName code ${map.value} was deleted"
|
||||
map.isStateChange = (state["code$map.value"] != "")
|
||||
state["code$map.value"] = ""
|
||||
} else {
|
||||
map = [ name: "codeChanged", descriptionText: "$device.displayName: user code deleted", isStateChange: true ]
|
||||
}
|
||||
break
|
||||
case 0xE:
|
||||
map = [ name: "codeChanged", value: cmd.alarmLevel, descriptionText: "$device.displayName: user code added", isStateChange: true ]
|
||||
if (cmd.eventParameter) {
|
||||
map.value = cmd.eventParameter[0]
|
||||
result << response(requestCode(cmd.eventParameter[0]))
|
||||
}
|
||||
break
|
||||
case 0xF:
|
||||
map = [ name: "codeChanged", descriptionText: "$device.displayName: user code not added, duplicate", isStateChange: true ]
|
||||
break
|
||||
case 0x10:
|
||||
map = [ name: "tamper", value: "detected", descriptionText: "$device.displayName: keypad temporarily disabled", displayed: true ]
|
||||
break
|
||||
case 0x11:
|
||||
map = [ descriptionText: "$device.displayName: keypad is busy" ]
|
||||
break
|
||||
case 0x12:
|
||||
map = [ name: "codeChanged", descriptionText: "$device.displayName: program code changed", isStateChange: true ]
|
||||
break
|
||||
case 0x13:
|
||||
map = [ name: "tamper", value: "detected", descriptionText: "$device.displayName: code entry attempt limit exceeded", displayed: true ]
|
||||
break
|
||||
default:
|
||||
map = map ?: [ descriptionText: "$device.displayName: alarm event $cmd.zwaveAlarmEvent", displayed: false ]
|
||||
break
|
||||
}
|
||||
} else if (cmd.zwaveAlarmType == 7) {
|
||||
map = [ name: "tamper", value: "detected", displayed: true ]
|
||||
switch (cmd.zwaveAlarmEvent) {
|
||||
case 0:
|
||||
map.value = "clear"
|
||||
map.descriptionText = "$device.displayName: tamper alert cleared"
|
||||
break
|
||||
case 1:
|
||||
case 2:
|
||||
map.descriptionText = "$device.displayName: intrusion attempt detected"
|
||||
break
|
||||
case 3:
|
||||
map.descriptionText = "$device.displayName: covering removed"
|
||||
break
|
||||
case 4:
|
||||
map.descriptionText = "$device.displayName: invalid code"
|
||||
break
|
||||
default:
|
||||
map.descriptionText = "$device.displayName: tamper alarm $cmd.zwaveAlarmEvent"
|
||||
break
|
||||
}
|
||||
} else switch(cmd.alarmType) {
|
||||
case 21: // Manually locked
|
||||
case 18: // Locked with keypad
|
||||
case 24: // Locked by command (Kwikset 914)
|
||||
case 27: // Autolocked
|
||||
map = [ name: "lock", value: "locked" ]
|
||||
break
|
||||
case 16: // Note: for levers this means it's unlocked, for non-motorized deadbolt, it's just unsecured and might not get unlocked
|
||||
case 19:
|
||||
map = [ name: "lock", value: "unlocked" ]
|
||||
if (cmd.alarmLevel) {
|
||||
map.descriptionText = "$device.displayName was unlocked with code $cmd.alarmLevel"
|
||||
map.data = [ usedCode: cmd.alarmLevel ]
|
||||
}
|
||||
break
|
||||
case 22:
|
||||
case 25: // Kwikset 914 unlocked by command
|
||||
map = [ name: "lock", value: "unlocked" ]
|
||||
break
|
||||
case 9:
|
||||
case 17:
|
||||
case 23:
|
||||
case 26:
|
||||
map = [ name: "lock", value: "unknown", descriptionText: "$device.displayName bolt is jammed" ]
|
||||
break
|
||||
case 13:
|
||||
map = [ name: "codeChanged", value: cmd.alarmLevel, descriptionText: "$device.displayName code $cmd.alarmLevel was added", isStateChange: true ]
|
||||
result << response(requestCode(cmd.alarmLevel))
|
||||
break
|
||||
case 32:
|
||||
map = [ name: "codeChanged", value: "all", descriptionText: "$device.displayName: all user codes deleted", isStateChange: true ]
|
||||
allCodesDeleted()
|
||||
break
|
||||
case 33:
|
||||
map = [ name: "codeReport", value: cmd.alarmLevel, data: [ code: "" ], isStateChange: true ]
|
||||
map.descriptionText = "$device.displayName code $cmd.alarmLevel was deleted"
|
||||
map.isStateChange = (state["code$cmd.alarmLevel"] != "")
|
||||
state["code$cmd.alarmLevel"] = ""
|
||||
break
|
||||
case 112:
|
||||
map = [ name: "codeChanged", value: cmd.alarmLevel, descriptionText: "$device.displayName code $cmd.alarmLevel changed", isStateChange: true ]
|
||||
result << response(requestCode(cmd.alarmLevel))
|
||||
break
|
||||
case 130: // Yale YRD batteries replaced
|
||||
map = [ descriptionText: "$device.displayName batteries replaced", isStateChange: true ]
|
||||
break
|
||||
case 131:
|
||||
map = [ /*name: "codeChanged", value: cmd.alarmLevel,*/ descriptionText: "$device.displayName code $cmd.alarmLevel is duplicate", isStateChange: false ]
|
||||
break
|
||||
case 161:
|
||||
if (cmd.alarmLevel == 2) {
|
||||
map = [ descriptionText: "$device.displayName front escutcheon removed", isStateChange: true ]
|
||||
} else {
|
||||
map = [ descriptionText: "$device.displayName detected failed user code attempt", isStateChange: true ]
|
||||
}
|
||||
break
|
||||
case 167:
|
||||
if (!state.lastbatt || now() - state.lastbatt > 12*60*60*1000) {
|
||||
map = [ descriptionText: "$device.displayName: battery low", isStateChange: true ]
|
||||
result << response(secure(zwave.batteryV1.batteryGet()))
|
||||
} else {
|
||||
map = [ name: "battery", value: device.currentValue("battery"), descriptionText: "$device.displayName: battery low", displayed: true ]
|
||||
}
|
||||
break
|
||||
case 168:
|
||||
map = [ name: "battery", value: 1, descriptionText: "$device.displayName: battery level critical", displayed: true ]
|
||||
break
|
||||
case 169:
|
||||
map = [ name: "battery", value: 0, descriptionText: "$device.displayName: battery too low to operate lock", isStateChange: true ]
|
||||
break
|
||||
default:
|
||||
map = [ displayed: false, descriptionText: "$device.displayName: alarm event $cmd.alarmType level $cmd.alarmLevel" ]
|
||||
break
|
||||
}
|
||||
result ? [createEvent(map), *result] : createEvent(map)
|
||||
}
|
||||
|
||||
def zwaveEvent(UserCodeReport cmd) {
|
||||
def result = []
|
||||
def name = "code$cmd.userIdentifier"
|
||||
def code = cmd.code
|
||||
def map = [:]
|
||||
if (cmd.userIdStatus == UserCodeReport.USER_ID_STATUS_OCCUPIED ||
|
||||
(cmd.userIdStatus == UserCodeReport.USER_ID_STATUS_STATUS_NOT_AVAILABLE && cmd.user && code != "**********"))
|
||||
{
|
||||
if (code == "**********") { // Schlage locks send us this instead of the real code
|
||||
state.blankcodes = true
|
||||
code = state["set$name"] ?: decrypt(state[name]) ?: code
|
||||
state.remove("set$name".toString())
|
||||
}
|
||||
if (!code && cmd.userIdStatus == 1) { // Schlage touchscreen sends blank code to notify of a changed code
|
||||
map = [ name: "codeChanged", value: cmd.userIdentifier, displayed: true, isStateChange: true ]
|
||||
map.descriptionText = "$device.displayName code $cmd.userIdentifier " + (state[name] ? "changed" : "was added")
|
||||
code = state["set$name"] ?: decrypt(state[name]) ?: "****"
|
||||
state.remove("set$name".toString())
|
||||
} else {
|
||||
map = [ name: "codeReport", value: cmd.userIdentifier, data: [ code: code ] ]
|
||||
map.descriptionText = "$device.displayName code $cmd.userIdentifier is set"
|
||||
map.displayed = (cmd.userIdentifier != state.requestCode && cmd.userIdentifier != state.pollCode)
|
||||
map.isStateChange = true
|
||||
}
|
||||
result << createEvent(map)
|
||||
} else {
|
||||
map = [ name: "codeReport", value: cmd.userIdentifier, data: [ code: "" ] ]
|
||||
if (state.blankcodes && state["reset$name"]) { // we deleted this code so we can tell that our new code gets set
|
||||
map.descriptionText = "$device.displayName code $cmd.userIdentifier was reset"
|
||||
map.displayed = map.isStateChange = true
|
||||
result << createEvent(map)
|
||||
state["set$name"] = state["reset$name"]
|
||||
result << response(setCode(cmd.userIdentifier, state["reset$name"]))
|
||||
state.remove("reset$name".toString())
|
||||
} else {
|
||||
if (state[name]) {
|
||||
map.descriptionText = "$device.displayName code $cmd.userIdentifier was deleted"
|
||||
} else {
|
||||
map.descriptionText = "$device.displayName code $cmd.userIdentifier is not set"
|
||||
}
|
||||
map.displayed = (cmd.userIdentifier != state.requestCode && cmd.userIdentifier != state.pollCode)
|
||||
map.isStateChange = true
|
||||
result << createEvent(map)
|
||||
}
|
||||
code = ""
|
||||
}
|
||||
state[name] = code ? encrypt(code) : code
|
||||
|
||||
if (cmd.userIdentifier == state.requestCode) { // reloadCodes() was called, keep requesting the codes in order
|
||||
if (state.requestCode + 1 > state.codes || state.requestCode >= 30) {
|
||||
state.remove("requestCode") // done
|
||||
} else {
|
||||
state.requestCode = state.requestCode + 1 // get next
|
||||
result << response(requestCode(state.requestCode))
|
||||
}
|
||||
}
|
||||
if (cmd.userIdentifier == state.pollCode) {
|
||||
if (state.pollCode + 1 > state.codes || state.pollCode >= 30) {
|
||||
state.remove("pollCode") // done
|
||||
} else {
|
||||
state.pollCode = state.pollCode + 1
|
||||
}
|
||||
}
|
||||
log.debug "code report parsed to ${result.inspect()}"
|
||||
result
|
||||
}
|
||||
|
||||
def zwaveEvent(UsersNumberReport cmd) {
|
||||
def result = []
|
||||
state.codes = cmd.supportedUsers
|
||||
if (state.requestCode && state.requestCode <= cmd.supportedUsers) {
|
||||
result << response(requestCode(state.requestCode))
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.associationv2.AssociationReport cmd) {
|
||||
def result = []
|
||||
if (cmd.nodeId.any { it == zwaveHubNodeId }) {
|
||||
state.remove("associationQuery")
|
||||
log.debug "$device.displayName is associated to $zwaveHubNodeId"
|
||||
result << createEvent(descriptionText: "$device.displayName is associated")
|
||||
state.assoc = zwaveHubNodeId
|
||||
if (cmd.groupingIdentifier == 2) {
|
||||
result << response(zwave.associationV1.associationRemove(groupingIdentifier:1, nodeId:zwaveHubNodeId))
|
||||
}
|
||||
} else if (cmd.groupingIdentifier == 1) {
|
||||
result << response(secure(zwave.associationV1.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId)))
|
||||
} else if (cmd.groupingIdentifier == 2) {
|
||||
result << response(zwave.associationV1.associationSet(groupingIdentifier:2, nodeId:zwaveHubNodeId))
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.timev1.TimeGet cmd) {
|
||||
def result = []
|
||||
def now = new Date().toCalendar()
|
||||
if(location.timeZone) now.timeZone = location.timeZone
|
||||
result << createEvent(descriptionText: "$device.displayName requested time update", displayed: false)
|
||||
result << response(secure(zwave.timeV1.timeReport(
|
||||
hourLocalTime: now.get(Calendar.HOUR_OF_DAY),
|
||||
minuteLocalTime: now.get(Calendar.MINUTE),
|
||||
secondLocalTime: now.get(Calendar.SECOND)))
|
||||
)
|
||||
result
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) {
|
||||
// The old Schlage locks use group 1 for basic control - we don't want that, so unsubscribe from group 1
|
||||
def result = [ createEvent(name: "lock", value: cmd.value ? "unlocked" : "locked") ]
|
||||
result << response(zwave.associationV1.associationRemove(groupingIdentifier:1, nodeId:zwaveHubNodeId))
|
||||
if (state.assoc != zwaveHubNodeId) {
|
||||
result << response(zwave.associationV1.associationGet(groupingIdentifier:2))
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.batteryv1.BatteryReport cmd) {
|
||||
def map = [ name: "battery", unit: "%" ]
|
||||
if (cmd.batteryLevel == 0xFF) {
|
||||
map.value = 1
|
||||
map.descriptionText = "$device.displayName has a low battery"
|
||||
} else {
|
||||
map.value = cmd.batteryLevel
|
||||
}
|
||||
state.lastbatt = now()
|
||||
createEvent(map)
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.manufacturerspecificv2.ManufacturerSpecificReport cmd) {
|
||||
def result = []
|
||||
|
||||
def msr = String.format("%04X-%04X-%04X", cmd.manufacturerId, cmd.productTypeId, cmd.productId)
|
||||
log.debug "msr: $msr"
|
||||
updateDataValue("MSR", msr)
|
||||
|
||||
result << createEvent(descriptionText: "$device.displayName MSR: $msr", isStateChange: false)
|
||||
result
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.versionv1.VersionReport cmd) {
|
||||
def fw = "${cmd.applicationVersion}.${cmd.applicationSubVersion}"
|
||||
updateDataValue("fw", fw)
|
||||
if (state.MSR == "003B-6341-5044") {
|
||||
updateDataValue("ver", "${cmd.applicationVersion >> 4}.${cmd.applicationVersion & 0xF}")
|
||||
}
|
||||
def text = "$device.displayName: firmware version: $fw, Z-Wave version: ${cmd.zWaveProtocolVersion}.${cmd.zWaveProtocolSubVersion}"
|
||||
createEvent(descriptionText: text, isStateChange: false)
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.applicationstatusv1.ApplicationBusy cmd) {
|
||||
def msg = cmd.status == 0 ? "try again later" :
|
||||
cmd.status == 1 ? "try again in $cmd.waitTime seconds" :
|
||||
cmd.status == 2 ? "request queued" : "sorry"
|
||||
createEvent(displayed: true, descriptionText: "$device.displayName is busy, $msg")
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.applicationstatusv1.ApplicationRejectedRequest cmd) {
|
||||
createEvent(displayed: true, descriptionText: "$device.displayName rejected the last request")
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.Command cmd) {
|
||||
createEvent(displayed: false, descriptionText: "$device.displayName: $cmd")
|
||||
}
|
||||
|
||||
def lockAndCheck(doorLockMode) {
|
||||
secureSequence([
|
||||
zwave.doorLockV1.doorLockOperationSet(doorLockMode: doorLockMode),
|
||||
zwave.doorLockV1.doorLockOperationGet()
|
||||
], 4200)
|
||||
}
|
||||
|
||||
def lock() {
|
||||
lockAndCheck(DoorLockOperationSet.DOOR_LOCK_MODE_DOOR_SECURED)
|
||||
}
|
||||
|
||||
def unlock() {
|
||||
lockAndCheck(DoorLockOperationSet.DOOR_LOCK_MODE_DOOR_UNSECURED)
|
||||
}
|
||||
|
||||
def unlockwtimeout() {
|
||||
lockAndCheck(DoorLockOperationSet.DOOR_LOCK_MODE_DOOR_UNSECURED_WITH_TIMEOUT)
|
||||
}
|
||||
|
||||
def refresh() {
|
||||
def cmds = [secure(zwave.doorLockV1.doorLockOperationGet())]
|
||||
if (state.assoc == zwaveHubNodeId) {
|
||||
log.debug "$device.displayName is associated to ${state.assoc}"
|
||||
} else if (!state.associationQuery) {
|
||||
log.debug "checking association"
|
||||
cmds << "delay 4200"
|
||||
cmds << zwave.associationV1.associationGet(groupingIdentifier:2).format() // old Schlage locks use group 2 and don't secure the Association CC
|
||||
cmds << secure(zwave.associationV1.associationGet(groupingIdentifier:1))
|
||||
state.associationQuery = now()
|
||||
} else if (secondsPast(state.associationQuery, 9)) {
|
||||
cmds << "delay 6000"
|
||||
cmds << zwave.associationV1.associationSet(groupingIdentifier:2, nodeId:zwaveHubNodeId).format()
|
||||
cmds << secure(zwave.associationV1.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId))
|
||||
cmds << zwave.associationV1.associationGet(groupingIdentifier:2).format()
|
||||
cmds << secure(zwave.associationV1.associationGet(groupingIdentifier:1))
|
||||
state.associationQuery = now()
|
||||
}
|
||||
log.debug "refresh sending ${cmds.inspect()}"
|
||||
cmds
|
||||
}
|
||||
|
||||
def poll() {
|
||||
def cmds = []
|
||||
// Only check lock state if it changed recently or we haven't had an update in an hour
|
||||
def latest = device.currentState("lock")?.date?.time
|
||||
if (!latest || !secondsPast(latest, 6 * 60) || secondsPast(state.lastPoll, 55 * 60)) {
|
||||
cmds << secure(zwave.doorLockV1.doorLockOperationGet())
|
||||
state.lastPoll = now()
|
||||
} else if (!state.lastbatt || now() - state.lastbatt > 53*60*60*1000) {
|
||||
cmds << secure(zwave.batteryV1.batteryGet())
|
||||
state.lastbatt = now() //inside-214
|
||||
}
|
||||
if (cmds) {
|
||||
log.debug "poll is sending ${cmds.inspect()}"
|
||||
cmds
|
||||
} else {
|
||||
// workaround to keep polling from stopping due to lack of activity
|
||||
sendEvent(descriptionText: "skipping poll", isStateChange: true, displayed: false)
|
||||
null
|
||||
}
|
||||
|
||||
reportAllCodes(state)
|
||||
}
|
||||
|
||||
def requestCode(codeNumber) {
|
||||
secure(zwave.userCodeV1.userCodeGet(userIdentifier: codeNumber))
|
||||
}
|
||||
|
||||
def reloadAllCodes() {
|
||||
def cmds = []
|
||||
if (!state.codes) {
|
||||
state.requestCode = 1
|
||||
cmds << secure(zwave.userCodeV1.usersNumberGet())
|
||||
} else {
|
||||
if(!state.requestCode) state.requestCode = 1
|
||||
cmds << requestCode(codeNumber)
|
||||
}
|
||||
cmds
|
||||
}
|
||||
|
||||
def setCode(codeNumber, code) {
|
||||
def strcode = code
|
||||
log.debug "setting code $codeNumber to $code"
|
||||
if (code instanceof String) {
|
||||
code = code.toList().findResults { if(it > ' ' && it != ',' && it != '-') it.toCharacter() as Short }
|
||||
} else {
|
||||
strcode = code.collect{ it as Character }.join()
|
||||
}
|
||||
if (state.blankcodes) {
|
||||
// Can't just set, we won't be able to tell if it was successful
|
||||
if (state["code$codeNumber"] != "") {
|
||||
if (state["setcode$codeNumber"] != strcode) {
|
||||
state["resetcode$codeNumber"] = strcode
|
||||
return deleteCode(codeNumber)
|
||||
}
|
||||
} else {
|
||||
state["setcode$codeNumber"] = strcode
|
||||
}
|
||||
}
|
||||
secureSequence([
|
||||
zwave.userCodeV1.userCodeSet(userIdentifier:codeNumber, userIdStatus:1, user:code),
|
||||
zwave.userCodeV1.userCodeGet(userIdentifier:codeNumber)
|
||||
], 7000)
|
||||
}
|
||||
|
||||
def deleteCode(codeNumber) {
|
||||
log.debug "deleting code $codeNumber"
|
||||
secureSequence([
|
||||
zwave.userCodeV1.userCodeSet(userIdentifier:codeNumber, userIdStatus:0),
|
||||
zwave.userCodeV1.userCodeGet(userIdentifier:codeNumber)
|
||||
], 7000)
|
||||
}
|
||||
|
||||
def updateCodes(codeSettings) {
|
||||
if(codeSettings instanceof String) codeSettings = util.parseJson(codeSettings)
|
||||
def set_cmds = []
|
||||
def get_cmds = []
|
||||
codeSettings.each { name, updated ->
|
||||
def current = decrypt(state[name])
|
||||
if (name.startsWith("code")) {
|
||||
def n = name[4..-1].toInteger()
|
||||
log.debug "$name was $current, set to $updated"
|
||||
if (updated?.size() >= 4 && updated != current) {
|
||||
def cmds = setCode(n, updated)
|
||||
set_cmds << cmds.first()
|
||||
get_cmds << cmds.last()
|
||||
} else if ((current && updated == "") || updated == "0") {
|
||||
def cmds = deleteCode(n)
|
||||
set_cmds << cmds.first()
|
||||
get_cmds << cmds.last()
|
||||
} else if (updated && updated.size() < 4) {
|
||||
// Entered code was too short
|
||||
codeSettings["code$n"] = current
|
||||
}
|
||||
} else log.warn("unexpected entry $name: $updated")
|
||||
}
|
||||
if (set_cmds) {
|
||||
return response(delayBetween(set_cmds, 2200) + ["delay 2200"] + delayBetween(get_cmds, 4200))
|
||||
}
|
||||
}
|
||||
|
||||
def getCode(codeNumber) {
|
||||
decrypt(state["code$codeNumber"])
|
||||
}
|
||||
|
||||
def getAllCodes() {
|
||||
state.findAll { it.key.startsWith 'code' }.collectEntries {
|
||||
[it.key, (it.value instanceof String && it.value.startsWith("~")) ? decrypt(it.value) : it.value]
|
||||
}
|
||||
}
|
||||
|
||||
private secure(physicalgraph.zwave.Command cmd) {
|
||||
zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format()
|
||||
}
|
||||
|
||||
private secureSequence(commands, delay=4200) {
|
||||
delayBetween(commands.collect{ secure(it) }, delay)
|
||||
}
|
||||
|
||||
private Boolean secondsPast(timestamp, seconds) {
|
||||
if (!(timestamp instanceof Number)) {
|
||||
if (timestamp instanceof Date) {
|
||||
timestamp = timestamp.time
|
||||
} else if ((timestamp instanceof String) && timestamp.isNumber()) {
|
||||
timestamp = timestamp.toLong()
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return (now() - timestamp) > (seconds * 1000)
|
||||
}
|
||||
|
||||
private allCodesDeleted() {
|
||||
if (state.codes instanceof Integer) {
|
||||
(1..state.codes).each { n ->
|
||||
if (state["code$n"]) {
|
||||
result << createEvent(name: "codeReport", value: n, data: [ code: "" ], descriptionText: "code $n was deleted",
|
||||
displayed: false, isStateChange: true)
|
||||
}
|
||||
state["code$n"] = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def reportAllCodes(state) {
|
||||
def map = [ name: "reportAllCodes", data: [:], displayed: false, isStateChange: false, type: "physical" ]
|
||||
state.each { entry ->
|
||||
//iterate through all the state entries and add them to the event data to be handled by application event handlers
|
||||
if ( entry.key ==~ /^code\d{1,}/ && entry.value.startsWith("~") ) {
|
||||
map.data.put(entry.key, decrypt(entry.value))
|
||||
} else {
|
||||
map.data.put(entry.key, entry.value)
|
||||
}
|
||||
}
|
||||
sendEvent(map)
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -83,7 +83,7 @@ def bridgeDiscovery(params=[:])
|
||||
|
||||
return dynamicPage(name:"bridgeDiscovery", title:"Discovery Started!", nextPage:"bridgeBtnPush", refreshInterval:refreshInterval, uninstall: true) {
|
||||
section("Please wait while we discover your Hue Bridge. Discovery can take five minutes or more, so sit back and relax! Select your device below once discovered.") {
|
||||
input "selectedHue", "enum", required:false, title:"Select Hue Bridge (${numFound} found)", multiple:false, options:options
|
||||
input "selectedHue", "enum", required:false, title:"Select Hue Bridge (${numFound} found)", multiple:false, options:options, submitOnChange: true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -333,9 +333,9 @@ def bulbListHandler(hub, data = "") {
|
||||
def bridge = null
|
||||
if (selectedHue) {
|
||||
bridge = getChildDevice(selectedHue)
|
||||
bridge?.sendEvent(name: "bulbList", value: hub, data: bulbs, isStateChange: true, displayed: false)
|
||||
}
|
||||
bridge.sendEvent(name: "bulbList", value: hub, data: bulbs, isStateChange: true, displayed: false)
|
||||
msg = "${bulbs.size()} bulbs found. ${bulbs}"
|
||||
msg = "${bulbs.size()} bulbs found. ${bulbs}"
|
||||
return msg
|
||||
}
|
||||
|
||||
@@ -490,24 +490,25 @@ def ssdpBridgeHandler(evt) {
|
||||
def host = ip + ":" + port
|
||||
log.debug "Device ($parsedEvent.mac) was already found in state with ip = $host."
|
||||
def dstate = bridges."${parsedEvent.ssdpUSN.toString()}"
|
||||
def dni = "${parsedEvent.mac}"
|
||||
def d = getChildDevice(dni)
|
||||
def dniReceived = "${parsedEvent.mac}"
|
||||
def currentDni = dstate.mac
|
||||
def d = getChildDevice(dniReceived)
|
||||
def networkAddress = null
|
||||
if (!d) {
|
||||
childDevices.each {
|
||||
if (it.getDeviceDataByName("mac")) {
|
||||
def newDNI = "${it.getDeviceDataByName("mac")}"
|
||||
d = it
|
||||
if (newDNI != it.deviceNetworkId) {
|
||||
def oldDNI = it.deviceNetworkId
|
||||
log.debug "updating dni for device ${it} with $newDNI - previous DNI = ${it.deviceNetworkId}"
|
||||
it.setDeviceNetworkId("${newDNI}")
|
||||
if (oldDNI == selectedHue) {
|
||||
app.updateSetting("selectedHue", newDNI)
|
||||
}
|
||||
doDeviceSync()
|
||||
}
|
||||
// There might be a mismatch between bridge DNI and the actual bridge mac address, correct that
|
||||
log.debug "Bridge with $dniReceived not found"
|
||||
def bridge = childDevices.find { it.deviceNetworkId == currentDni }
|
||||
if (bridge != null) {
|
||||
log.warn "Bridge is set to ${bridge.deviceNetworkId}, updating to $dniReceived"
|
||||
bridge.setDeviceNetworkId("${dniReceived}")
|
||||
dstate.mac = dniReceived
|
||||
// Check to see if selectedHue is a valid bridge, otherwise update it
|
||||
def isSelectedValid = bridges?.find {it.value?.mac == selectedHue}
|
||||
if (isSelectedValid == null) {
|
||||
log.warn "Correcting selectedHue in state"
|
||||
app.updateSetting("selectedHue", dniReceived)
|
||||
}
|
||||
doDeviceSync()
|
||||
}
|
||||
} else {
|
||||
updateBridgeStatus(d)
|
||||
@@ -525,6 +526,18 @@ def ssdpBridgeHandler(evt) {
|
||||
d.sendEvent(name:"networkAddress", value: host)
|
||||
d.updateDataValue("networkAddress", host)
|
||||
}
|
||||
if (dstate.mac != dniReceived) {
|
||||
log.warn "Correcting bridge mac address in state"
|
||||
dstate.mac = dniReceived
|
||||
}
|
||||
if (selectedHue != dniReceived) {
|
||||
// Check to see if selectedHue is a valid bridge, otherwise update it
|
||||
def isSelectedValid = bridges?.find {it.value?.mac == selectedHue}
|
||||
if (isSelectedValid == null) {
|
||||
log.warn "Correcting selectedHue in state"
|
||||
app.updateSetting("selectedHue", dniReceived)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -950,6 +963,14 @@ private handleCommandResponse(body) {
|
||||
* @return empty array
|
||||
*/
|
||||
private handlePoll(body) {
|
||||
// Used to track "unreachable" time
|
||||
// Device is considered "offline" if it has been in the "unreachable" state for
|
||||
// 11 minutes (e.g. two poll intervals)
|
||||
// Note, Hue Bridge marks devices as "unreachable" often even when they accept commands
|
||||
Calendar time11 = Calendar.getInstance()
|
||||
time11.add(Calendar.MINUTE, -11)
|
||||
Calendar currentTime = Calendar.getInstance()
|
||||
|
||||
def bulbs = getChildDevices()
|
||||
for (bulb in body) {
|
||||
def device = bulbs.find{it.deviceNetworkId == "${app.id}/${bulb.key}"}
|
||||
@@ -959,7 +980,10 @@ private handlePoll(body) {
|
||||
// light just came back online, notify device watch
|
||||
def lastActivity = now()
|
||||
device.sendEvent(name: "deviceWatch-status", value: "ONLINE", description: "Last Activity is on ${new Date((long) lastActivity)}", displayed: false, isStateChange: true)
|
||||
log.debug "$device is Online"
|
||||
}
|
||||
// Mark light as "online"
|
||||
state.bulbs[bulb.key]?.unreachableSince = null
|
||||
state.bulbs[bulb.key]?.online = true
|
||||
|
||||
// If user just executed commands, then do not send events to avoid confusing the turning on/off state
|
||||
@@ -969,9 +993,18 @@ private handlePoll(body) {
|
||||
sendColorEvents(device, bulb.value?.state?.xy, bulb.value?.state?.hue, bulb.value?.state?.sat, bulb.value?.state?.ct, bulb.value?.state?.colormode)
|
||||
}
|
||||
} else {
|
||||
state.bulbs[bulb.key]?.online = false
|
||||
log.warn "$device is not reachable by Hue bridge"
|
||||
device.sendEvent(name: "DeviceWatch-DeviceOffline", value: "offline", displayed: false, isStateChange: true)
|
||||
if (state.bulbs[bulb.key]?.unreachableSince == null) {
|
||||
// Store the first time where device was reported as "unreachable"
|
||||
state.bulbs[bulb.key]?.unreachableSince = currentTime.getTimeInMillis()
|
||||
} else if (state.bulbs[bulb.key]?.online) {
|
||||
// Check if device was "unreachable" for more than 11 minutes and mark "offline" if necessary
|
||||
if (state.bulbs[bulb.key]?.unreachableSince < time11.getTimeInMillis()) {
|
||||
log.warn "$device went Offline"
|
||||
state.bulbs[bulb.key]?.online = false
|
||||
device.sendEvent(name: "DeviceWatch-DeviceOffline", value: "offline", displayed: false, isStateChange: true)
|
||||
}
|
||||
}
|
||||
log.warn "$device may not reachable by Hue bridge"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1006,9 +1039,6 @@ def hubVerification(bodytext) {
|
||||
def on(childDevice) {
|
||||
log.debug "Executing 'on'"
|
||||
def id = getId(childDevice)
|
||||
if (!isOnline(id)) {
|
||||
return "Bulb is unreachable"
|
||||
}
|
||||
updateInProgress()
|
||||
createSwitchEvent(childDevice, "on")
|
||||
put("lights/$id/state", [on: true])
|
||||
@@ -1018,9 +1048,6 @@ def on(childDevice) {
|
||||
def off(childDevice) {
|
||||
log.debug "Executing 'off'"
|
||||
def id = getId(childDevice)
|
||||
if (!isOnline(id)) {
|
||||
return "Bulb is unreachable"
|
||||
}
|
||||
updateInProgress()
|
||||
createSwitchEvent(childDevice, "off")
|
||||
put("lights/$id/state", [on: false])
|
||||
@@ -1030,9 +1057,6 @@ def off(childDevice) {
|
||||
def setLevel(childDevice, percent) {
|
||||
log.debug "Executing 'setLevel'"
|
||||
def id = getId(childDevice)
|
||||
if (!isOnline(id)) {
|
||||
return "Bulb is unreachable"
|
||||
}
|
||||
updateInProgress()
|
||||
// 1 - 254
|
||||
def level
|
||||
@@ -1057,10 +1081,6 @@ def setLevel(childDevice, percent) {
|
||||
def setSaturation(childDevice, percent) {
|
||||
log.debug "Executing 'setSaturation($percent)'"
|
||||
def id = getId(childDevice)
|
||||
if (!isOnline(id)) {
|
||||
return "Bulb is unreachable"
|
||||
}
|
||||
|
||||
updateInProgress()
|
||||
// 0 - 254
|
||||
def level = Math.min(Math.round(percent * 254 / 100), 254)
|
||||
@@ -1073,9 +1093,6 @@ def setSaturation(childDevice, percent) {
|
||||
def setHue(childDevice, percent) {
|
||||
log.debug "Executing 'setHue($percent)'"
|
||||
def id = getId(childDevice)
|
||||
if (!isOnline(id)) {
|
||||
return "Bulb is unreachable"
|
||||
}
|
||||
updateInProgress()
|
||||
// 0 - 65535
|
||||
def level = Math.min(Math.round(percent * 65535 / 100), 65535)
|
||||
@@ -1088,9 +1105,6 @@ def setHue(childDevice, percent) {
|
||||
def setColorTemperature(childDevice, huesettings) {
|
||||
log.debug "Executing 'setColorTemperature($huesettings)'"
|
||||
def id = getId(childDevice)
|
||||
if (!isOnline(id)) {
|
||||
return "Bulb is unreachable"
|
||||
}
|
||||
updateInProgress()
|
||||
// 153 (6500K) to 500 (2000K)
|
||||
def ct = hueSettings == 6500 ? 153 : Math.round(1000000/huesettings)
|
||||
@@ -1102,9 +1116,6 @@ def setColorTemperature(childDevice, huesettings) {
|
||||
def setColor(childDevice, huesettings) {
|
||||
log.debug "Executing 'setColor($huesettings)'"
|
||||
def id = getId(childDevice)
|
||||
if (!isOnline(id)) {
|
||||
return "Bulb is unreachable"
|
||||
}
|
||||
updateInProgress()
|
||||
|
||||
def value = [:]
|
||||
@@ -1120,7 +1131,7 @@ def setColor(childDevice, huesettings) {
|
||||
value.hue = Math.min(Math.round(huesettings.hue * 65535 / 100), 65535)
|
||||
if (huesettings.saturation != null)
|
||||
value.sat = Math.min(Math.round(huesettings.saturation * 254 / 100), 254)
|
||||
} else if (huesettings.hex != null && false) {
|
||||
} else if (huesettings.hex != null) {
|
||||
// For now ignore model to get a consistent color if same color is set across multiple devices
|
||||
// def model = state.bulbs[getId(childDevice)]?.modelid
|
||||
// value.xy = calculateXY(huesettings.hex, model)
|
||||
@@ -1224,7 +1235,7 @@ private getBridgeIP() {
|
||||
if (d) {
|
||||
if (d.getDeviceDataByName("networkAddress"))
|
||||
host = d.getDeviceDataByName("networkAddress")
|
||||
else
|
||||
else
|
||||
host = d.latestState('networkAddress').stringValue
|
||||
}
|
||||
if (host == null || host == "") {
|
||||
@@ -1663,7 +1674,7 @@ private boolean checkPointInLampsReach(p, colorPoints) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an RGB color in hex to HSV.
|
||||
* Converts an RGB color in hex to HSV/HSB.
|
||||
* Algorithm based on http://en.wikipedia.org/wiki/HSV_color_space.
|
||||
*
|
||||
* @param colorStr color value in hex (#ff03d3)
|
||||
@@ -1673,32 +1684,32 @@ private boolean checkPointInLampsReach(p, colorPoints) {
|
||||
def hexToHsv(colorStr){
|
||||
def r = Integer.valueOf( colorStr.substring( 1, 3 ), 16 ) / 255
|
||||
def g = Integer.valueOf( colorStr.substring( 3, 5 ), 16 ) / 255
|
||||
def b = Integer.valueOf( colorStr.substring( 5, 7 ), 16 ) / 255;
|
||||
def b = Integer.valueOf( colorStr.substring( 5, 7 ), 16 ) / 255
|
||||
|
||||
def max = Math.max(Math.max(r, g), b)
|
||||
def min = Math.min(Math.min(r, g), b)
|
||||
|
||||
def h, s, v = max;
|
||||
def h, s, v = max
|
||||
|
||||
def d = max - min;
|
||||
s = max == 0 ? 0 : d / max;
|
||||
def d = max - min
|
||||
s = max == 0 ? 0 : d / max
|
||||
|
||||
if(max == min){
|
||||
h = 0;
|
||||
h = 0
|
||||
}else{
|
||||
switch(max){
|
||||
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
|
||||
case g: h = (b - r) / d + 2; break;
|
||||
case b: h = (r - g) / d + 4; break;
|
||||
case r: h = (g - b) / d + (g < b ? 6 : 0); break
|
||||
case g: h = (b - r) / d + 2; break
|
||||
case b: h = (r - g) / d + 4; break
|
||||
}
|
||||
h /= 6;
|
||||
}
|
||||
|
||||
return [(h * 100).round(), (s * 100).round(), (v * 100).round()];
|
||||
return [Math.round(h * 100), Math.round(s * 100), Math.round(v * 100)]
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts HSV color to RGB in hex.
|
||||
* Converts HSV/HSB color to RGB in hex.
|
||||
* Algorithm based on http://en.wikipedia.org/wiki/HSV_color_space.
|
||||
*
|
||||
* @param hue hue 0-100
|
||||
@@ -1713,11 +1724,11 @@ def hsvToHex(hue, sat, value = 100){
|
||||
def s = sat / 100
|
||||
def v = value / 100
|
||||
|
||||
def i = Math.floor(h * 6);
|
||||
def f = h * 6 - i;
|
||||
def p = v * (1 - s);
|
||||
def q = v * (1 - f * s);
|
||||
def t = v * (1 - (1 - f) * s);
|
||||
def i = Math.floor(h * 6)
|
||||
def f = h * 6 - i
|
||||
def p = v * (1 - s)
|
||||
def q = v * (1 - f * s)
|
||||
def t = v * (1 - (1 - f) * s)
|
||||
|
||||
switch (i % 6) {
|
||||
case 0:
|
||||
@@ -1753,9 +1764,9 @@ def hsvToHex(hue, sat, value = 100){
|
||||
}
|
||||
|
||||
// Converting float components to int components.
|
||||
def r1 = String.format("%02X", (int) (r * 255.0f));
|
||||
def g1 = String.format("%02X", (int) (g * 255.0f));
|
||||
def b1 = String.format("%02X", (int) (b * 255.0f));
|
||||
def r1 = String.format("%02X", (int) (r * 255.0f))
|
||||
def g1 = String.format("%02X", (int) (g * 255.0f))
|
||||
def b1 = String.format("%02X", (int) (b * 255.0f))
|
||||
|
||||
return "#$r1$g1$b1"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user