mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-09 05:11:52 +00:00
Compare commits
30 Commits
MSA-1474-1
...
MSA-1493-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8011f4bc3 | ||
|
|
81cf1179ef | ||
|
|
79d20b0edb | ||
|
|
b6d862fdd4 | ||
|
|
d58084c438 | ||
|
|
dbfaef3e69 | ||
|
|
40ed88e7fd | ||
|
|
1d6e22dc16 | ||
|
|
1d180ac487 | ||
|
|
71880e2644 | ||
|
|
8d920ea072 | ||
|
|
43a1ae6371 | ||
|
|
a441b94a33 | ||
|
|
ced03d746d | ||
|
|
5341d0d06f | ||
|
|
2a58d7ff62 | ||
|
|
260917d515 | ||
|
|
c1478d3e96 | ||
|
|
8b9bff15dc | ||
|
|
75c1ede16c | ||
|
|
a7acc384a2 | ||
|
|
c6998e5f1d | ||
|
|
f95e906d6e | ||
|
|
4891e3b947 | ||
|
|
ae91f9bff5 | ||
|
|
bb87ad2cf0 | ||
|
|
5dff03fb69 | ||
|
|
dd7c6b90d5 | ||
|
|
fe2fbc3b97 | ||
|
|
4ad0a6fd9d |
@@ -23,10 +23,8 @@ Works with:
|
||||
|
||||
## Device Health
|
||||
|
||||
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
|
||||
A Category C6 Connected Cree LED Bulb with maxReportTime of 5 mins.
|
||||
Check-in interval = 12 mins
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ metadata {
|
||||
|
||||
capability "Actuator"
|
||||
capability "Configuration"
|
||||
capability "Polling"
|
||||
capability "Refresh"
|
||||
capability "Switch"
|
||||
capability "Switch Level"
|
||||
@@ -97,14 +96,17 @@ def refresh() {
|
||||
zigbee.onOffRefresh() + zigbee.levelRefresh() + zigbee.onOffConfig() + zigbee.levelConfig()
|
||||
}
|
||||
|
||||
def poll() {
|
||||
zigbee.onOffRefresh() + zigbee.levelRefresh()
|
||||
def healthPoll() {
|
||||
def cmds = zigbee.onOffRefresh() + zigbee.levelRefresh()
|
||||
cmds.each{ sendHubCommand(new physicalgraph.device.HubAction(it))}
|
||||
}
|
||||
|
||||
def configure() {
|
||||
unschedule()
|
||||
schedule("0 0/5 * * * ? *", "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"])
|
||||
// Device-Watch allows 2 check-in misses from device
|
||||
sendEvent(name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee"])
|
||||
// minReportTime 0 seconds, maxReportTime 5 min. Reporting interval if no activity
|
||||
zigbee.onOffConfig(0, 300) + zigbee.levelConfig() + zigbee.onOffRefresh() + zigbee.levelRefresh()
|
||||
}
|
||||
|
||||
@@ -67,6 +67,6 @@ def refresh() {
|
||||
|
||||
void poll() {
|
||||
log.debug "Executing 'poll' using parent SmartApp"
|
||||
parent.poll()
|
||||
parent.pollChild()
|
||||
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ def refresh() {
|
||||
|
||||
void poll() {
|
||||
log.debug "Executing 'poll' using parent SmartApp"
|
||||
parent.poll()
|
||||
parent.pollChild()
|
||||
}
|
||||
|
||||
def generateEvent(Map results) {
|
||||
|
||||
@@ -57,7 +57,7 @@ metadata {
|
||||
}
|
||||
|
||||
void installed() {
|
||||
sendEvent(name: "checkInterval", value: 60 * 15, data: [protocol: "lan"], displayed: false)
|
||||
sendEvent(name: "checkInterval", value: 60 * 12, data: [protocol: "lan"], displayed: false)
|
||||
}
|
||||
|
||||
// parse events into attributes
|
||||
|
||||
@@ -66,7 +66,7 @@ metadata {
|
||||
}
|
||||
|
||||
void installed() {
|
||||
sendEvent(name: "checkInterval", value: 60 * 15, data: [protocol: "lan"], displayed: false)
|
||||
sendEvent(name: "checkInterval", value: 60 * 12, data: [protocol: "lan"], displayed: false)
|
||||
}
|
||||
|
||||
// parse events into attributes
|
||||
|
||||
@@ -50,7 +50,7 @@ metadata {
|
||||
}
|
||||
|
||||
void installed() {
|
||||
sendEvent(name: "checkInterval", value: 60 * 15, data: [protocol: "lan"], displayed: false)
|
||||
sendEvent(name: "checkInterval", value: 60 * 12, data: [protocol: "lan"], displayed: false)
|
||||
}
|
||||
|
||||
// parse events into attributes
|
||||
|
||||
@@ -55,7 +55,7 @@ metadata {
|
||||
}
|
||||
|
||||
void installed() {
|
||||
sendEvent(name: "checkInterval", value: 60 * 15, data: [protocol: "lan"], displayed: false)
|
||||
sendEvent(name: "checkInterval", value: 60 * 12, data: [protocol: "lan"], displayed: false)
|
||||
}
|
||||
|
||||
// parse events into attributes
|
||||
|
||||
@@ -23,10 +23,10 @@ Works with:
|
||||
|
||||
## Device Health
|
||||
|
||||
A Category C1 smart power outlet with maxReportTime of 10 min.
|
||||
Check-in interval is double the value of maxReportTime for Zigbee device.
|
||||
A Category C1 smart power outlet 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 = 2*10 = 20 min
|
||||
Check-in interval = 12 mins
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
|
||||
@@ -128,8 +128,8 @@ def refresh() {
|
||||
}
|
||||
|
||||
def configure() {
|
||||
// Device-Watch allows 3 check-in misses from device. 300 seconds x 3 = 15min
|
||||
sendEvent(name: "checkInterval", value: 900, displayed: false, data: [protocol: "zigbee"])
|
||||
// Device-Watch allows 2 check-in misses from device
|
||||
sendEvent(name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee"])
|
||||
// OnOff minReportTime 0 seconds, maxReportTime 5 min. Reporting interval if no activity
|
||||
zigbee.onOffConfig(0, 300) + powerConfig() + refresh()
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@ Works with:
|
||||
|
||||
## Device Health
|
||||
|
||||
A Category C2 moisture sensor with maxReportTime of 1 hr.
|
||||
Check-in interval is double the value of maxReportTime for Zigbee device.
|
||||
A Category C2 moisture sensor 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 = 2*60 = 120 min
|
||||
Check-in interval = 12 mins
|
||||
|
||||
## Battery Specification
|
||||
|
||||
|
||||
@@ -292,8 +292,8 @@ def refresh() {
|
||||
}
|
||||
|
||||
def configure() {
|
||||
// Device-Watch allows 3 check-in misses from device. 300 seconds x 3 = 15min
|
||||
sendEvent(name: "checkInterval", value: 900, displayed: false, data: [protocol: "zigbee"])
|
||||
// Device-Watch allows 2 check-in misses from device
|
||||
sendEvent(name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee"])
|
||||
|
||||
String zigbeeEui = swapEndianHex(device.hub.zigbeeEui)
|
||||
log.debug "Configuring Reporting, IAS CIE, and Bindings."
|
||||
|
||||
@@ -22,10 +22,10 @@ Works with:
|
||||
|
||||
## Device Health
|
||||
|
||||
A Category C2 motion sensor with maxReportTime of 1 hr.
|
||||
Check-in interval is double the value of maxReportTime for Zigbee device.
|
||||
A Category C2 motion sensor 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 = 2*60 = 120 min
|
||||
Check-in interval = 12 mins
|
||||
|
||||
## Battery Specification
|
||||
|
||||
|
||||
@@ -303,8 +303,8 @@ def refresh() {
|
||||
}
|
||||
|
||||
def configure() {
|
||||
// Device-Watch allows 3 check-in misses from device. 300 seconds x 3 = 15min
|
||||
sendEvent(name: "checkInterval", value: 900, displayed: false, data: [protocol: "zigbee"])
|
||||
// Device-Watch allows 2 check-in misses from device
|
||||
sendEvent(name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee"])
|
||||
|
||||
String zigbeeEui = swapEndianHex(device.hub.zigbeeEui)
|
||||
log.debug "Configuring Reporting, IAS CIE, and Bindings."
|
||||
|
||||
@@ -26,10 +26,10 @@ Works with:
|
||||
|
||||
## Device Health
|
||||
|
||||
A Category C2 multi sensor with maxReportTime of 1 hr.
|
||||
Check-in interval is double the value of maxReportTime for Zigbee device.
|
||||
A Category C2 multi sensor 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 = 2*60 = 120 min
|
||||
Check-in interval = 12 mins
|
||||
|
||||
## Battery Specification
|
||||
|
||||
|
||||
@@ -401,8 +401,8 @@ def refresh() {
|
||||
}
|
||||
|
||||
def configure() {
|
||||
// Device-Watch allows 3 check-in misses from device. 300 seconds x 3 = 15min
|
||||
sendEvent(name: "checkInterval", value: 900, displayed: false, data: [protocol: "zigbee"])
|
||||
// Device-Watch allows 2 check-in misses from device
|
||||
sendEvent(name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee"])
|
||||
|
||||
log.debug "Configuring Reporting"
|
||||
|
||||
|
||||
@@ -24,10 +24,10 @@ Works with:
|
||||
|
||||
## Device Health
|
||||
|
||||
A Category C2 open/closed sensor with maxReportTime of 1 hr.
|
||||
Check-in interval is double the value of maxReportTime for Zigbee device.
|
||||
A Category C2 open/closed sensor 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 = 2*60 = 120 min
|
||||
Check-in interval = 12 mins
|
||||
|
||||
## Battery Specification
|
||||
|
||||
|
||||
@@ -255,8 +255,8 @@ def refresh() {
|
||||
}
|
||||
|
||||
def configure() {
|
||||
// Device-Watch allows 3 check-in misses from device. 300 seconds x 3 = 15min
|
||||
sendEvent(name: "checkInterval", value: 900, displayed: false, data: [protocol: "zigbee"])
|
||||
// Device-Watch allows 2 check-in misses from device
|
||||
sendEvent(name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee"])
|
||||
|
||||
String zigbeeEui = swapEndianHex(device.hub.zigbeeEui)
|
||||
log.debug "Configuring Reporting, IAS CIE, and Bindings."
|
||||
|
||||
@@ -24,10 +24,10 @@ Works with:
|
||||
|
||||
## Device Health
|
||||
|
||||
A Category C2 SmartSense Temp/Humidity Sensor with maxReportTime of 1 hr.
|
||||
Check-in interval is double the value of maxReportTime for Zigbee device.
|
||||
A Category C2 SmartSense Temp/Humidity Sensor 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 = 2*60 = 120 min
|
||||
Check-in interval = 12 mins
|
||||
|
||||
## Battery Specification
|
||||
|
||||
|
||||
@@ -264,8 +264,8 @@ def refresh()
|
||||
}
|
||||
|
||||
def configure() {
|
||||
// Device-Watch allows 3 check-in misses from device. 300 seconds x 3 = 15min
|
||||
sendEvent(name: "checkInterval", value: 900, displayed: false, data: [protocol: "zigbee"])
|
||||
// Device-Watch allows 2 check-in misses from device
|
||||
sendEvent(name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee"])
|
||||
|
||||
log.debug "Configuring Reporting and Bindings."
|
||||
def humidityConfigCmds = [
|
||||
|
||||
2
devicetypes/smartthings/zigbee-dimmer.src/.st-ignore
Normal file
2
devicetypes/smartthings/zigbee-dimmer.src/.st-ignore
Normal file
@@ -0,0 +1,2 @@
|
||||
.st-ignore
|
||||
README.md
|
||||
36
devicetypes/smartthings/zigbee-dimmer.src/README.md
Normal file
36
devicetypes/smartthings/zigbee-dimmer.src/README.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# 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") {
|
||||
definition (name: "ZigBee Dimmer", namespace: "smartthings", author: "SmartThings", category: "C1") {
|
||||
capability "Actuator"
|
||||
capability "Configuration"
|
||||
capability "Refresh"
|
||||
@@ -89,8 +89,8 @@ def refresh() {
|
||||
|
||||
def configure() {
|
||||
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"])
|
||||
// Device-Watch allows 2 check-in misses from device
|
||||
sendEvent(name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee"])
|
||||
// OnOff minReportTime 0 seconds, maxReportTime 5 min. Reporting interval if no activity
|
||||
zigbee.onOffConfig(0, 300) + zigbee.levelConfig() + zigbee.onOffRefresh() + zigbee.levelRefresh()
|
||||
}
|
||||
|
||||
@@ -31,7 +31,8 @@
|
||||
fingerprint profileId: "0104", inClusters: "0000,0001,0003,0009,000A,0101,0020", outClusters: "000A,0019", manufacturer: "Yale", model: "YRD210 PB DB", deviceJoinName: "Yale Push Button Deadbolt Lock"
|
||||
fingerprint profileId: "0104", inClusters: "0000,0001,0003,0009,000A,0101,0020", outClusters: "000A,0019", manufacturer: "Yale", model: "YRD220/240 TSDB", deviceJoinName: "Yale Touch Screen Deadbolt Lock"
|
||||
fingerprint profileId: "0104", inClusters: "0000,0001,0003,0009,000A,0101,0020", outClusters: "000A,0019", manufacturer: "Yale", model: "YRL210 PB LL", deviceJoinName: "Yale Push Button Lever Lock"
|
||||
}
|
||||
fingerprint profileId: "0104", inClusters: "0000,0001,0003,0009,000A,0101,0020", outClusters: "000A,0019", manufacturer: "Yale", model: "YRD226/246 TSDB", deviceJoinName: "Yale Touch Screen Deadbolt Lock"
|
||||
}
|
||||
|
||||
tiles(scale: 2) {
|
||||
multiAttributeTile(name:"toggle", type:"generic", width:6, height:4){
|
||||
|
||||
2
devicetypes/smartthings/zigbee-rgbw-bulb.src/.st-ignore
Normal file
2
devicetypes/smartthings/zigbee-rgbw-bulb.src/.st-ignore
Normal file
@@ -0,0 +1,2 @@
|
||||
.st-ignore
|
||||
README.md
|
||||
42
devicetypes/smartthings/zigbee-rgbw-bulb.src/README.md
Normal file
42
devicetypes/smartthings/zigbee-rgbw-bulb.src/README.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# 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") {
|
||||
definition (name: "ZigBee RGBW Bulb", namespace: "smartthings", author: "SmartThings", category: "C6") {
|
||||
|
||||
capability "Actuator"
|
||||
capability "Color Control"
|
||||
@@ -133,8 +133,8 @@ def refresh() {
|
||||
|
||||
def configure() {
|
||||
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"])
|
||||
// Device-Watch allows 2 check-in misses from device
|
||||
sendEvent(name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee"])
|
||||
// OnOff minReportTime 0 seconds, maxReportTime 5 min. Reporting interval if no activity
|
||||
zigbee.onOffConfig(0, 300) + zigbee.levelConfig() + zigbee.colorTemperatureConfig() + zigbee.configureReporting(COLOR_CONTROL_CLUSTER, ATTRIBUTE_HUE, 0x20, 1, 3600, 0x01) + zigbee.configureReporting(COLOR_CONTROL_CLUSTER, ATTRIBUTE_SATURATION, 0x20, 1, 3600, 0x01) + zigbee.readAttribute(0x0006, 0x00) + zigbee.readAttribute(0x0008, 0x00) + zigbee.readAttribute(COLOR_CONTROL_CLUSTER, 0x00) + zigbee.readAttribute(COLOR_CONTROL_CLUSTER, ATTRIBUTE_COLOR_TEMPERATURE) + zigbee.readAttribute(COLOR_CONTROL_CLUSTER, ATTRIBUTE_HUE) + zigbee.readAttribute(COLOR_CONTROL_CLUSTER, ATTRIBUTE_SATURATION)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
.st-ignore
|
||||
README.md
|
||||
@@ -0,0 +1,37 @@
|
||||
# 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") {
|
||||
definition (name: "ZigBee White Color Temperature Bulb", namespace: "smartthings", author: "SmartThings", category: "C1") {
|
||||
|
||||
capability "Actuator"
|
||||
capability "Color Temperature"
|
||||
@@ -113,8 +113,8 @@ def refresh() {
|
||||
|
||||
def configure() {
|
||||
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"])
|
||||
// Device-Watch allows 2 check-in misses from device
|
||||
sendEvent(name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee"])
|
||||
// OnOff minReportTime 0 seconds, maxReportTime 5 min. Reporting interval if no activity
|
||||
zigbee.onOffConfig(0, 300) + zigbee.levelConfig() + zigbee.colorTemperatureConfig() + zigbee.onOffRefresh() + zigbee.levelRefresh() + zigbee.colorTemperatureRefresh()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Smart Windows
|
||||
* Compares two temperatures – indoor vs outdoor, for example – then sends an alert if windows are open (or closed!).
|
||||
*
|
||||
*
|
||||
* Copyright 2014 Eric Gideon
|
||||
*
|
||||
* Based in part on the "When it's going to rain" SmartApp by the SmartThings team,
|
||||
@@ -21,13 +21,18 @@ definition(
|
||||
name: "Smart Windows",
|
||||
namespace: "egid",
|
||||
author: "Eric Gideon",
|
||||
description: "Compares two temperatures – indoor vs outdoor, for example – then sends an alert if windows are open (or closed!). If you don't use an external temperature device, your zipcode will be used instead.",
|
||||
description: "Compares two temperatures – indoor vs outdoor, for example – then sends an alert if windows are open (or closed!). If you don't use an external temperature device, your location will be used instead.",
|
||||
iconUrl: "https://s3.amazonaws.com/smartthings-device-icons/Home/home9-icn.png",
|
||||
iconX2Url: "https://s3.amazonaws.com/smartthings-device-icons/Home/home9-icn@2x.png"
|
||||
)
|
||||
|
||||
|
||||
preferences {
|
||||
|
||||
if (!(location.zipCode || ( location.latitude && location.longitude )) && location.channelName == 'samsungtv') {
|
||||
section { paragraph title: "Note:", "Location is required for this SmartApp. Go to 'Location Name' settings to setup your correct location." }
|
||||
}
|
||||
|
||||
section( "Set the temperature range for your comfort zone..." ) {
|
||||
input "minTemp", "number", title: "Minimum temperature"
|
||||
input "maxTemp", "number", title: "Maximum temperature"
|
||||
@@ -39,9 +44,11 @@ preferences {
|
||||
input "inTemp", "capability.temperatureMeasurement", title: "Indoor"
|
||||
input "outTemp", "capability.temperatureMeasurement", title: "Outdoor (optional)", required: false
|
||||
}
|
||||
section( "Set your location" ) {
|
||||
input "zipCode", "text", title: "Zip code"
|
||||
}
|
||||
|
||||
if (location.channelName != 'samsungtv') {
|
||||
section( "Set your location" ) { input "zipCode", "text", title: "Zip code" }
|
||||
}
|
||||
|
||||
section( "Notifications" ) {
|
||||
input "sendPushMessage", "enum", title: "Send a push notification?", metadata:[values:["Yes","No"]], required:false
|
||||
input "retryPeriod", "number", title: "Minutes between notifications:"
|
||||
@@ -72,7 +79,7 @@ def temperatureHandler(evt) {
|
||||
|
||||
def currentInTemp = evt.doubleValue
|
||||
def openWindows = sensors.findAll { it?.latestValue("contact") == 'open' }
|
||||
|
||||
|
||||
log.trace "Temp event: $evt"
|
||||
log.info "In: $currentInTemp; Out: $currentOutTemp"
|
||||
|
||||
@@ -98,7 +105,7 @@ def temperatureHandler(evt) {
|
||||
if ( currentOutTemp < maxTemp && !openWindows ) {
|
||||
send( "Open some windows to cool down the house! Currently ${currentInTemp}°F inside and ${currentOutTemp}°F outside." )
|
||||
} else if ( currentOutTemp > maxTemp && openWindows ) {
|
||||
send( "It's gotten warmer outside! You should close these windows: ${openWindows.join(', ')}. Currently ${currentInTemp}°F inside and ${currentOutTemp}°F outside." )
|
||||
send( "It's gotten warmer outside! You should close these windows: ${openWindows.join(', ')}. Currently ${currentInTemp}°F inside and ${currentOutTemp}°F outside." )
|
||||
} else {
|
||||
log.debug "No notifications sent. Everything is in the right place."
|
||||
}
|
||||
@@ -125,7 +132,11 @@ def temperatureHandler(evt) {
|
||||
}
|
||||
|
||||
def weatherCheck() {
|
||||
def json = getWeatherFeature("conditions", zipCode)
|
||||
def json
|
||||
if (location.channelName != 'samsungtv')
|
||||
json = getWeatherFeature("conditions", zipCode)
|
||||
else
|
||||
json = getWeatherFeature("conditions")
|
||||
def currentTemp = json?.current_observation?.temp_f
|
||||
|
||||
if ( currentTemp ) {
|
||||
@@ -150,4 +161,4 @@ private send(msg) {
|
||||
}
|
||||
|
||||
log.info msg
|
||||
}
|
||||
}
|
||||
|
||||
253
smartapps/gideon-api/gideon.src/gideon.groovy
Normal file
253
smartapps/gideon-api/gideon.src/gideon.groovy
Normal file
@@ -0,0 +1,253 @@
|
||||
/**
|
||||
* Gideon
|
||||
*
|
||||
* Copyright 2016 Nicola Russo
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
definition(
|
||||
name: "Gideon",
|
||||
namespace: "gideon.api",
|
||||
author: "Braindrain Solutions",
|
||||
description: "Gideon AI Smart app allows you to connect and control all of your SmartThings devices through the Gideon AI app, making your SmartThings devices even smarter.",
|
||||
category: "Family",
|
||||
iconUrl: "http://s33.postimg.org/t77u7y7v3/logo.png",
|
||||
iconX2Url: "http://s33.postimg.org/t77u7y7v3/logo.png",
|
||||
iconX3Url: "http://s33.postimg.org/t77u7y7v3/logo.png",
|
||||
oauth: [displayName: "Gideon AI API", displayLink: "gideon.ai"])
|
||||
|
||||
|
||||
preferences {
|
||||
section("Control these switches...") {
|
||||
input "switches", "capability.switch", multiple:true
|
||||
}
|
||||
section("Control these motion sensors...") {
|
||||
input "motions", "capability.motionSensor", multiple:true
|
||||
}
|
||||
section("Control these presence sensors...") {
|
||||
input "presence_sensors", "capability.presenceSensor", multiple:true
|
||||
}
|
||||
section("Control these outlets...") {
|
||||
input "outlets", "capability.switch", multiple:true
|
||||
}
|
||||
section("Control these locks...") {
|
||||
input "locks", "capability.lock", multiple:true
|
||||
}
|
||||
section("Control these locks...") {
|
||||
input "temperature_sensors", "capability.temperatureMeasurement"
|
||||
}
|
||||
}
|
||||
|
||||
def installed() {
|
||||
log.debug "Installed with settings: ${settings}"
|
||||
|
||||
initialize()
|
||||
}
|
||||
|
||||
def updated() {
|
||||
log.debug "Updated with settings: ${settings}"
|
||||
|
||||
unsubscribe()
|
||||
initialize()
|
||||
}
|
||||
|
||||
def initialize() {
|
||||
// TODO: subscribe to attributes, devices, locations, etc.
|
||||
subscribe(outlet, "energy", outletHandler)
|
||||
subscribe(outlet, "switch", outletHandler)
|
||||
}
|
||||
|
||||
// TODO: implement event handlers
|
||||
def outletHandler(evt) {
|
||||
log.debug "$outlet.currentEnergy"
|
||||
//TODO call G API
|
||||
}
|
||||
|
||||
|
||||
private device(it, type) {
|
||||
it ? [id: it.id, label: it.label, type: type] : null
|
||||
}
|
||||
|
||||
//API Mapping
|
||||
mappings {
|
||||
path("/getalldevices") {
|
||||
action: [
|
||||
GET: "getAllDevices"
|
||||
]
|
||||
}
|
||||
path("/doorlocks/:id/:command") {
|
||||
action: [
|
||||
GET: "updateDoorLock"
|
||||
]
|
||||
}
|
||||
path("/doorlocks/:id") {
|
||||
action: [
|
||||
GET: "getDoorLockStatus"
|
||||
]
|
||||
}
|
||||
path("/tempsensors/:id") {
|
||||
action: [
|
||||
GET: "getTempSensorsStatus"
|
||||
]
|
||||
}
|
||||
path("/presences/:id") {
|
||||
action: [
|
||||
GET: "getPresenceStatus"
|
||||
]
|
||||
}
|
||||
path("/motions/:id") {
|
||||
action: [
|
||||
GET: "getMotionStatus"
|
||||
]
|
||||
}
|
||||
path("/outlets/:id") {
|
||||
action: [
|
||||
GET: "getOutletStatus"
|
||||
]
|
||||
}
|
||||
path("/outlets/:id/:command") {
|
||||
action: [
|
||||
GET: "updateOutlet"
|
||||
]
|
||||
}
|
||||
path("/switches/:command") {
|
||||
action: [
|
||||
PUT: "updateSwitch"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
//API Methods
|
||||
def getAllDevices() {
|
||||
def locks_list = locks.collect{device(it,"Lock")}
|
||||
def presences_list = presence_sensors.collect{device(it,"Presence")}
|
||||
def motions_list = motions.collect{device(it,"Motion")}
|
||||
def outlets_list = outlets.collect{device(it,"Outlet")}
|
||||
def switches_list = switches.collect{device(it,"Switch")}
|
||||
def temp_list = temperature_sensors.collect{device(it,"Temperature")}
|
||||
return [Locks: locks_list, Presences: presences_list, Motions: motions_list, Outlets: outlets_list, Switches: switches_list, Temperatures: temp_list]
|
||||
}
|
||||
|
||||
//LOCKS
|
||||
def getDoorLockStatus() {
|
||||
def device = locks.find { it.id == params.id }
|
||||
if (!device) {
|
||||
httpError(404, "Device not found")
|
||||
} else {
|
||||
return [Device_state: device.currentValue('lock')]
|
||||
}
|
||||
}
|
||||
|
||||
def updateDoorLock() {
|
||||
def command = params.command
|
||||
def device = locks.find { it.id == params.id }
|
||||
if (command){
|
||||
if (!device) {
|
||||
httpError(404, "Device not found")
|
||||
} else {
|
||||
if(command == "toggle")
|
||||
{
|
||||
if(device.currentValue('lock') == "locked")
|
||||
device.unlock();
|
||||
else
|
||||
device.lock();
|
||||
|
||||
return [Device_id: params.id, result_action: "200"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//PRESENCE
|
||||
def getPresenceStatus() {
|
||||
|
||||
def device = presence_sensors.find { it.id == params.id }
|
||||
if (!device) {
|
||||
httpError(404, "Device not found")
|
||||
} else {
|
||||
return [Device_state: device.currentValue('presence')]
|
||||
}
|
||||
}
|
||||
|
||||
//MOTION
|
||||
def getMotionStatus() {
|
||||
|
||||
def device = motions.find { it.id == params.id }
|
||||
if (!device) {
|
||||
httpError(404, "Device not found")
|
||||
} else {
|
||||
return [Device_state: device.currentValue('motion')]
|
||||
}
|
||||
}
|
||||
|
||||
//OUTLET
|
||||
def getOutletStatus() {
|
||||
|
||||
def device = outlets.find { it.id == params.id }
|
||||
if (!device) {
|
||||
httpError(404, "Device not found")
|
||||
} else {
|
||||
return [Device_state: device.currentSwitch, Current_watt: device.currentValue("energy")]
|
||||
}
|
||||
}
|
||||
|
||||
def updateOutlet() {
|
||||
|
||||
def command = params.command
|
||||
def device = outlets.find { it.id == params.id }
|
||||
if (command){
|
||||
if (!device) {
|
||||
httpError(404, "Device not found")
|
||||
} else {
|
||||
if(command == "toggle")
|
||||
{
|
||||
if(device.currentSwitch == "on")
|
||||
device.off();
|
||||
else
|
||||
device.on();
|
||||
|
||||
return [Device_id: params.id, result_action: "200"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//SWITCH
|
||||
def updateSwitch() {
|
||||
def command = params.command
|
||||
def device = switches.find { it.id == params.id }
|
||||
if (command){
|
||||
if (!device) {
|
||||
httpError(404, "Device not found")
|
||||
} else {
|
||||
if(command == "toggle")
|
||||
{
|
||||
if(device.currentSwitch == "on")
|
||||
device.off();
|
||||
else
|
||||
device.on();
|
||||
|
||||
return [Device_id: params.id, result_action: "200"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TEMPERATURE
|
||||
def getTempSensorsStatus() {
|
||||
|
||||
def device = temperature_sensors.find { it.id == params.id }
|
||||
if (!device) {
|
||||
httpError(404, "Device not found")
|
||||
} else {
|
||||
return [Device_state: device.currentValue('temperature')]
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,13 @@ definition(
|
||||
)
|
||||
|
||||
preferences {
|
||||
section("Zip code?") {
|
||||
input "zipcode", "text", title: "Zipcode?"
|
||||
|
||||
if (!(location.zipCode || ( location.latitude && location.longitude )) && location.channelName == 'samsungtv') {
|
||||
section { paragraph title: "Note:", "Location is required for this SmartApp. Go to 'Location Name' settings to setup your correct location." }
|
||||
}
|
||||
|
||||
if (location.channelName != 'samsungtv') {
|
||||
section( "Set your location" ) { input "zipCode", "text", title: "Zip code" }
|
||||
}
|
||||
|
||||
section("Things to check?") {
|
||||
@@ -60,7 +65,11 @@ def scheduleCheck(evt) {
|
||||
// Only need to poll if we haven't checked in a while - and if something is left open.
|
||||
if((now() - (30 * 60 * 1000) > state.lastCheck["time"]) && open) {
|
||||
log.info("Something's open - let's check the weather.")
|
||||
def response = getWeatherFeature("forecast", zipcode)
|
||||
def response
|
||||
if (location.channelName != 'samsungtv')
|
||||
response = getWeatherFeature("forecast", zipCode)
|
||||
else
|
||||
response = getWeatherFeature("forecast")
|
||||
def weather = isStormy(response)
|
||||
|
||||
if(weather) {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* my first smartthings app
|
||||
*
|
||||
* Copyright 2016 John Haines
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
definition(
|
||||
name: "my first smartthings app",
|
||||
namespace: "johnhainesjr",
|
||||
author: "John Haines",
|
||||
description: "Samsung smart things app",
|
||||
category: "SmartThings Labs",
|
||||
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
|
||||
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
|
||||
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
|
||||
oauth: true)
|
||||
|
||||
|
||||
preferences {
|
||||
section("Title") {
|
||||
// TODO: put inputs here
|
||||
}
|
||||
}
|
||||
|
||||
def installed() {
|
||||
log.debug "Installed with settings: ${settings}"
|
||||
|
||||
initialize()
|
||||
}
|
||||
|
||||
def updated() {
|
||||
log.debug "Updated with settings: ${settings}"
|
||||
|
||||
unsubscribe()
|
||||
initialize()
|
||||
}
|
||||
|
||||
def initialize() {
|
||||
// TODO: subscribe to attributes, devices, locations, etc.
|
||||
}
|
||||
|
||||
// TODO: implement event handlers
|
||||
@@ -4,6 +4,9 @@
|
||||
* Author: Juan Risso
|
||||
* Date: 2013-12-19
|
||||
*/
|
||||
|
||||
include 'asynchttp_v1'
|
||||
|
||||
definition(
|
||||
name: "Jawbone UP (Connect)",
|
||||
namespace: "juano2310",
|
||||
@@ -28,7 +31,7 @@ mappings {
|
||||
path("/receivedToken") { action: [ POST: "receivedToken", GET: "receivedToken"] }
|
||||
path("/receiveToken") { action: [ POST: "receiveToken", GET: "receiveToken"] }
|
||||
path("/hookCallback") { action: [ POST: "hookEventHandler", GET: "hookEventHandler"] }
|
||||
path("/oauth/initialize") {action: [GET: "oauthInitUrl"]}
|
||||
path("/oauth/initialize") {action: [GET: "oauthInitUrl"]}
|
||||
path("/oauth/callback") { action: [ GET: "callback" ] }
|
||||
}
|
||||
|
||||
@@ -44,7 +47,7 @@ def callback() {
|
||||
} else {
|
||||
log.warn "No authQueryString"
|
||||
}
|
||||
|
||||
|
||||
if (state.JawboneAccessToken) {
|
||||
log.debug "Access token already exists"
|
||||
setup()
|
||||
@@ -73,7 +76,7 @@ def callback() {
|
||||
|
||||
def authPage() {
|
||||
log.debug "authPage"
|
||||
def description = null
|
||||
def description = null
|
||||
if (state.JawboneAccessToken == null) {
|
||||
if (!state.accessToken) {
|
||||
log.debug "About to create access token"
|
||||
@@ -82,12 +85,13 @@ def authPage() {
|
||||
description = "Click to enter Jawbone Credentials"
|
||||
def redirectUrl = buildRedirectUrl
|
||||
log.debug "RedirectURL = ${redirectUrl}"
|
||||
def donebutton= state.JawboneAccessToken != null
|
||||
def donebutton= state.JawboneAccessToken != null
|
||||
return dynamicPage(name: "Credentials", title: "Jawbone UP", nextPage: null, uninstall: true, install: donebutton) {
|
||||
section { paragraph title: "Note:", "This device has not been officially tested and certified to “Work with SmartThings”. You can connect it to your SmartThings home but performance may vary and we will not be able to provide support or assistance." }
|
||||
section { href url:redirectUrl, style:"embedded", required:true, title:"Jawbone UP", state: hast ,description:description }
|
||||
}
|
||||
} else {
|
||||
description = "Jawbone Credentials Already Entered."
|
||||
description = "Jawbone Credentials Already Entered."
|
||||
return dynamicPage(name: "Credentials", title: "Jawbone UP", uninstall: true, install:true) {
|
||||
section { href url: buildRedirectUrl("receivedToken"), style:"embedded", state: "complete", title:"Jawbone UP", description:description }
|
||||
}
|
||||
@@ -107,7 +111,7 @@ def receiveToken(redirectUrl = null) {
|
||||
def params = [
|
||||
uri: "https://jawbone.com/auth/oauth2/token?${toQueryString(oauthParams)}",
|
||||
]
|
||||
httpGet(params) { response ->
|
||||
httpGet(params) { response ->
|
||||
log.debug "${response.data}"
|
||||
log.debug "Setting access token to ${response.data.access_token}, refresh token to ${response.data.refresh_token}"
|
||||
state.JawboneAccessToken = response.data.access_token
|
||||
@@ -149,7 +153,7 @@ def connectionStatus(message, redirectUrl = null) {
|
||||
<meta http-equiv="refresh" content="3; url=${redirectUrl}" />
|
||||
"""
|
||||
}
|
||||
|
||||
|
||||
def html = """
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
@@ -229,12 +233,12 @@ def validateCurrentToken() {
|
||||
log.debug "validateCurrentToken"
|
||||
def url = "https://jawbone.com/nudge/api/v.1.1/users/@me/refreshToken"
|
||||
def requestBody = "secret=${appSettings.clientSecret}"
|
||||
|
||||
|
||||
try {
|
||||
httpPost(uri: url, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ], body: requestBody) {response ->
|
||||
if (response.status == 200) {
|
||||
log.debug "${response.data}"
|
||||
log.debug "Setting refresh token to ${response.data.data.refresh_token}"
|
||||
log.debug "Setting refresh token"
|
||||
state.refreshToken = response.data.data.refresh_token
|
||||
}
|
||||
}
|
||||
@@ -258,7 +262,7 @@ def validateCurrentToken() {
|
||||
state.remove("refreshToken")
|
||||
}
|
||||
} else {
|
||||
log.debug "Setting access token to ${data.access_token}, refresh token to ${data.refresh_token}"
|
||||
log.debug "Setting access token"
|
||||
state.JawboneAccessToken = data.access_token
|
||||
state.refreshToken = data.refresh_token
|
||||
}
|
||||
@@ -271,10 +275,10 @@ def validateCurrentToken() {
|
||||
}
|
||||
|
||||
def initialize() {
|
||||
log.debug "Callback URL - Webhook"
|
||||
def localServerUrl = getApiServerUrl()
|
||||
log.debug "Callback URL - Webhook"
|
||||
def localServerUrl = getApiServerUrl()
|
||||
def hookUrl = "${localServerUrl}/api/token/${state.accessToken}/smartapps/installations/${app.id}/hookCallback"
|
||||
def webhook = "https://jawbone.com/nudge/api/v.1.1/users/@me/pubsub?webhook=$hookUrl"
|
||||
def webhook = "https://jawbone.com/nudge/api/v.1.1/users/@me/pubsub?webhook=$hookUrl"
|
||||
httpPost(uri: webhook, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ])
|
||||
}
|
||||
|
||||
@@ -284,16 +288,16 @@ def setup() {
|
||||
|
||||
if (state.JawboneAccessToken) {
|
||||
def urlmember = "https://jawbone.com/nudge/api/users/@me/"
|
||||
def member = null
|
||||
httpGet(uri: urlmember, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
|
||||
def member = null
|
||||
httpGet(uri: urlmember, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
|
||||
member = response.data.data
|
||||
}
|
||||
|
||||
|
||||
if (member) {
|
||||
state.member = member
|
||||
def externalId = "${app.id}.${member.xid}"
|
||||
|
||||
// find the appropriate child device based on my app id and the device network id
|
||||
// find the appropriate child device based on my app id and the device network id
|
||||
def deviceWrapper = getChildDevice("${externalId}")
|
||||
|
||||
// invoke the generatePresenceEvent method on the child device
|
||||
@@ -302,7 +306,8 @@ def setup() {
|
||||
def childDevice = addChildDevice('juano2310', "Jawbone User", "${app.id}.${member.xid}",null,[name:"Jawbone UP - " + member.first, completedSetup: true])
|
||||
if (childDevice) {
|
||||
log.debug "Child Device Successfully Created"
|
||||
generateInitialEvent (member, childDevice)
|
||||
childDevice?.generateSleepingEvent(false)
|
||||
pollChild(childDevice)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -312,7 +317,7 @@ def setup() {
|
||||
}
|
||||
|
||||
def installed() {
|
||||
|
||||
|
||||
if (!state.accessToken) {
|
||||
log.debug "About to create access token"
|
||||
createAccessToken()
|
||||
@@ -324,7 +329,7 @@ def installed() {
|
||||
}
|
||||
|
||||
def updated() {
|
||||
|
||||
|
||||
if (!state.accessToken) {
|
||||
log.debug "About to create access token"
|
||||
createAccessToken()
|
||||
@@ -348,128 +353,128 @@ def uninstalled() {
|
||||
}
|
||||
|
||||
def pollChild(childDevice) {
|
||||
def member = state.member
|
||||
generatePollingEvents (member, childDevice)
|
||||
def childMap = [ value: "$childDevice.device.deviceNetworkId}"]
|
||||
|
||||
def params = [
|
||||
uri: 'https://jawbone.com',
|
||||
path: '/nudge/api/users/@me/goals',
|
||||
headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ],
|
||||
contentType: 'application/json'
|
||||
]
|
||||
|
||||
asynchttp_v1.get('responseGoals', params, childMap)
|
||||
|
||||
def params2 = [
|
||||
uri: 'https://jawbone.com',
|
||||
path: '/nudge/api/users/@me/moves',
|
||||
headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ],
|
||||
contentType: 'application/json'
|
||||
]
|
||||
|
||||
asynchttp_v1.get('responseMoves', params2, childMap)
|
||||
}
|
||||
|
||||
def generatePollingEvents (member, childDevice) {
|
||||
// lets figure out if the member is currently "home" (At the place)
|
||||
def urlgoals = "https://jawbone.com/nudge/api/users/@me/goals"
|
||||
def urlmoves = "https://jawbone.com/nudge/api/users/@me/moves"
|
||||
def urlsleeps = "https://jawbone.com/nudge/api/users/@me/sleeps"
|
||||
def goals = null
|
||||
def moves = null
|
||||
def sleeps = null
|
||||
httpGet(uri: urlgoals, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
|
||||
goals = response.data.data
|
||||
}
|
||||
httpGet(uri: urlmoves, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
|
||||
moves = response.data.data.items[0]
|
||||
}
|
||||
|
||||
try { // we are going to just ignore any errors
|
||||
log.debug "Member = ${member.first}"
|
||||
log.debug "Moves Goal = ${goals.move_steps} Steps"
|
||||
log.debug "Moves = ${moves.details.steps} Steps"
|
||||
|
||||
childDevice?.sendEvent(name:"steps", value: moves.details.steps)
|
||||
childDevice?.sendEvent(name:"goal", value: goals.move_steps)
|
||||
//setColor(moves.details.steps,goals.move_steps,childDevice)
|
||||
}
|
||||
catch (e) {
|
||||
// eat it
|
||||
}
|
||||
def responseGoals(response, dni) {
|
||||
if (response.hasError()) {
|
||||
log.error "response has error: $response.errorMessage"
|
||||
} else {
|
||||
def goals
|
||||
try {
|
||||
// json response already parsed into JSONElement object
|
||||
goals = response.json.data
|
||||
} catch (e) {
|
||||
log.error "error parsing json from response: $e"
|
||||
}
|
||||
if (goals) {
|
||||
def childDevice = getChildDevice(dni.value)
|
||||
log.debug "Goal = ${goals.move_steps} Steps"
|
||||
childDevice?.sendEvent(name:"goal", value: goals.move_steps)
|
||||
} else {
|
||||
log.debug "did not get json results from response body: $response.data"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def generateInitialEvent (member, childDevice) {
|
||||
// lets figure out if the member is currently "home" (At the place)
|
||||
def urlgoals = "https://jawbone.com/nudge/api/users/@me/goals"
|
||||
def urlmoves = "https://jawbone.com/nudge/api/users/@me/moves"
|
||||
def urlsleeps = "https://jawbone.com/nudge/api/users/@me/sleeps"
|
||||
def goals = null
|
||||
def moves = null
|
||||
def sleeps = null
|
||||
httpGet(uri: urlgoals, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
|
||||
goals = response.data.data
|
||||
}
|
||||
httpGet(uri: urlmoves, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
|
||||
moves = response.data.data.items[0]
|
||||
}
|
||||
|
||||
try { // we are going to just ignore any errors
|
||||
log.debug "Member = ${member.first}"
|
||||
log.debug "Moves Goal = ${goals.move_steps} Steps"
|
||||
log.debug "Moves = ${moves.details.steps} Steps"
|
||||
log.debug "Sleeping state = false"
|
||||
childDevice?.generateSleepingEvent(false)
|
||||
childDevice?.sendEvent(name:"steps", value: moves.details.steps)
|
||||
childDevice?.sendEvent(name:"goal", value: goals.move_steps)
|
||||
//setColor(moves.details.steps,goals.move_steps,childDevice)
|
||||
}
|
||||
catch (e) {
|
||||
// eat it
|
||||
}
|
||||
def responseMoves(response, dni) {
|
||||
if (response.hasError()) {
|
||||
log.error "response has error: $response.errorMessage"
|
||||
} else {
|
||||
def moves
|
||||
try {
|
||||
// json response already parsed into JSONElement object
|
||||
moves = response.json.data.items[0]
|
||||
} catch (e) {
|
||||
log.error "error parsing json from response: $e"
|
||||
}
|
||||
if (moves) {
|
||||
def childDevice = getChildDevice(dni.value)
|
||||
log.debug "Moves = ${moves.details.steps} Steps"
|
||||
childDevice?.sendEvent(name:"steps", value: moves.details.steps)
|
||||
} else {
|
||||
log.debug "did not get json results from response body: $response.data"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def setColor (steps,goal,childDevice) {
|
||||
def result = steps * 100 / goal
|
||||
if (result < 25)
|
||||
if (result < 25)
|
||||
childDevice?.sendEvent(name:"steps", value: "steps", label: steps)
|
||||
else if ((result >= 25) && (result < 50))
|
||||
else if ((result >= 25) && (result < 50))
|
||||
childDevice?.sendEvent(name:"steps", value: "steps1", label: steps)
|
||||
else if ((result >= 50) && (result < 75))
|
||||
else if ((result >= 50) && (result < 75))
|
||||
childDevice?.sendEvent(name:"steps", value: "steps1", label: steps)
|
||||
else if (result >= 75)
|
||||
childDevice?.sendEvent(name:"steps", value: "stepsgoal", label: steps)
|
||||
else if (result >= 75)
|
||||
childDevice?.sendEvent(name:"steps", value: "stepsgoal", label: steps)
|
||||
}
|
||||
|
||||
def hookEventHandler() {
|
||||
// log.debug "In hookEventHandler method."
|
||||
log.debug "request = ${request}"
|
||||
|
||||
def json = request.JSON
|
||||
|
||||
|
||||
def json = request.JSON
|
||||
|
||||
// get some stuff we need
|
||||
def userId = json.events.user_xid[0]
|
||||
def json_type = json.events.type[0]
|
||||
def json_action = json.events.action[0]
|
||||
def json_action = json.events.action[0]
|
||||
|
||||
//log.debug json
|
||||
log.debug "Userid = ${userId}"
|
||||
log.debug "Notification Type: " + json_type
|
||||
log.debug "Notification Action: " + json_action
|
||||
|
||||
log.debug "Notification Action: " + json_action
|
||||
|
||||
// find the appropriate child device based on my app id and the device network id
|
||||
def externalId = "${app.id}.${userId}"
|
||||
def childDevice = getChildDevice("${externalId}")
|
||||
|
||||
|
||||
if (childDevice) {
|
||||
switch (json_action) {
|
||||
case "enter_sleep_mode":
|
||||
childDevice?.generateSleepingEvent(true)
|
||||
break
|
||||
case "exit_sleep_mode":
|
||||
childDevice?.generateSleepingEvent(false)
|
||||
break
|
||||
case "creation":
|
||||
switch (json_action) {
|
||||
case "enter_sleep_mode":
|
||||
childDevice?.generateSleepingEvent(true)
|
||||
break
|
||||
case "exit_sleep_mode":
|
||||
childDevice?.generateSleepingEvent(false)
|
||||
break
|
||||
case "creation":
|
||||
childDevice?.sendEvent(name:"steps", value: 0)
|
||||
break
|
||||
case "updation":
|
||||
def urlgoals = "https://jawbone.com/nudge/api/users/@me/goals"
|
||||
def urlmoves = "https://jawbone.com/nudge/api/users/@me/moves"
|
||||
def urlgoals = "https://jawbone.com/nudge/api/users/@me/goals"
|
||||
def urlmoves = "https://jawbone.com/nudge/api/users/@me/moves"
|
||||
def goals = null
|
||||
def moves = null
|
||||
httpGet(uri: urlgoals, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
|
||||
def moves = null
|
||||
httpGet(uri: urlgoals, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
|
||||
goals = response.data.data
|
||||
}
|
||||
httpGet(uri: urlmoves, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
|
||||
}
|
||||
httpGet(uri: urlmoves, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
|
||||
moves = response.data.data.items[0]
|
||||
}
|
||||
}
|
||||
log.debug "Goal = ${goals.move_steps} Steps"
|
||||
log.debug "Steps = ${moves.details.steps} Steps"
|
||||
log.debug "Steps = ${moves.details.steps} Steps"
|
||||
childDevice?.sendEvent(name:"steps", value: moves.details.steps)
|
||||
childDevice?.sendEvent(name:"goal", value: goals.move_steps)
|
||||
//setColor(moves.details.steps,goals.move_steps,childDevice)
|
||||
childDevice?.sendEvent(name:"goal", value: goals.move_steps)
|
||||
//setColor(moves.details.steps,goals.move_steps,childDevice)
|
||||
break
|
||||
case "deletion":
|
||||
app.delete()
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
* JLH - 02-15-2014 - Fuller use of ecobee API
|
||||
* 10-28-2015 DVCSMP-604 - accessory sensor, DVCSMP-1174, DVCSMP-1111 - not respond to routines
|
||||
*/
|
||||
include 'asynchttp_v1'
|
||||
|
||||
definition(
|
||||
name: "Ecobee (Connect)",
|
||||
namespace: "smartthings",
|
||||
@@ -246,7 +244,9 @@ def getEcobeeThermostats() {
|
||||
uri: apiEndpoint,
|
||||
path: "/1/thermostat",
|
||||
headers: ["Content-Type": "text/json", "Authorization": "Bearer ${atomicState.authToken}"],
|
||||
query: [json: toJson(bodyParams)]
|
||||
// TODO - the query string below is not consistent with the Ecobee docs:
|
||||
// https://www.ecobee.com/home/developer/api/documentation/v1/operations/get-thermostats.shtml
|
||||
query: [format: 'json', body: toJson(bodyParams)]
|
||||
]
|
||||
|
||||
def stats = [:]
|
||||
@@ -265,8 +265,9 @@ def getEcobeeThermostats() {
|
||||
} catch (groovyx.net.http.HttpResponseException e) {
|
||||
log.trace "Exception polling children: " + e.response.data.status
|
||||
if (e.response.data.status.code == 14) {
|
||||
atomicState.action = "getEcobeeThermostats"
|
||||
log.debug "Refreshing your auth_token!"
|
||||
refreshAuthToken([async: false, nextAction: "getEcobeeThermostats"])
|
||||
refreshAuthToken()
|
||||
}
|
||||
}
|
||||
atomicState.thermostats = stats
|
||||
@@ -357,22 +358,16 @@ def initialize() {
|
||||
atomicState.timeSendPush = null
|
||||
atomicState.reAttempt = 0
|
||||
|
||||
initialPoll() //first time polling data data from thermostat
|
||||
pollHandler() //first time polling data data from thermostat
|
||||
|
||||
//automatically update devices status every 5 mins
|
||||
runEvery5Minutes("poll")
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Polls the child devices (synchronously).
|
||||
* This is used during app install/update, and is synchronous
|
||||
* to maintain current behavior that will cause install/update to fail
|
||||
* if polling fails.
|
||||
*/
|
||||
def initialPoll() {
|
||||
log.debug "initialPoll()"
|
||||
pollChildrenSync() // Hit the ecobee API for update on all thermostats
|
||||
def pollHandler() {
|
||||
log.debug "pollHandler()"
|
||||
pollChildren(null) // Hit the ecobee API for update on all thermostats
|
||||
|
||||
atomicState.thermostats.each {stat ->
|
||||
def dni = stat.key
|
||||
@@ -385,101 +380,10 @@ def initialPoll() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Polls Ecobee (asynchronously) for updated device state data.
|
||||
* Called from within this Connect SmartApp as well as the child
|
||||
* devices.
|
||||
*/
|
||||
def poll() {
|
||||
log.debug "polling asynchronously"
|
||||
asynchttp_v1.get('asyncPollResponseHandler', getPollParams())
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a (synchronous) request to the Ecobee API to get the data for the thermostats.
|
||||
* This request is made synchronously here because it is called as part of the
|
||||
* install/updated lifecycle, and changing it to asynchronous during the install/update
|
||||
* lifecycle may change the behavior if there is an error in polling.
|
||||
*
|
||||
* If further analysis shows that polling can be done asynchronously during
|
||||
* install/update without any adverse consequences, this should then be made
|
||||
* asynchronous just as the scheduled polling is.
|
||||
*/
|
||||
def pollChildrenSync() {
|
||||
def pollChildren(child = null) {
|
||||
def thermostatIdsString = getChildDeviceIdsString()
|
||||
log.debug "polling children: $thermostatIdsString"
|
||||
|
||||
def params = getPollParams()
|
||||
params.query << ["Content-Type": "application/json"]
|
||||
|
||||
def result = false
|
||||
log.debug "making synchronous poll request"
|
||||
|
||||
try{
|
||||
httpGet(params) { resp ->
|
||||
if(resp.status == 200) {
|
||||
atomicState.remoteSensors = resp.data.thermostatList.remoteSensors
|
||||
updateSensorData()
|
||||
storeThermostatData(resp.data.thermostatList)
|
||||
result = true
|
||||
log.debug "updated ${atomicState.thermostats?.size()} stats: ${atomicState.thermostats}"
|
||||
}
|
||||
}
|
||||
} catch (groovyx.net.http.HttpResponseException e) {
|
||||
log.trace "Exception polling children: " + e.response.data.status
|
||||
if (e.response.data.status.code == 14) {
|
||||
log.debug "Refreshing your auth_token!"
|
||||
refreshAuthToken([async: false, nextAction: "pollChildrenSync"])
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Response handler for asynchronous request to get thermostat data.
|
||||
* Given a successful response, updates the sensor data, stores the thermostat
|
||||
* data, and generates child device events.
|
||||
*
|
||||
* If the access token has expired, will issue a request to refresh the token
|
||||
* (and pending successful token refresh, the poll request will be made again).
|
||||
*/
|
||||
def asyncPollResponseHandler(response, data) {
|
||||
log.trace "async poll response handler"
|
||||
if (!response.hasError()) {
|
||||
if (response.status == 200) {
|
||||
def json
|
||||
try {
|
||||
json = response.getJson()
|
||||
} catch (e) {
|
||||
log.error ("error parsing JSON", e)
|
||||
}
|
||||
if (json) {
|
||||
atomicState.remoteSensors = json.thermostatList.remoteSensors
|
||||
updateSensorData()
|
||||
storeThermostatData(json.thermostatList)
|
||||
generateChildThermostatEvent()
|
||||
}
|
||||
} else {
|
||||
log.warn "Response returned non-200 response. Status: ${response.status}, data: ${response.getData()}"
|
||||
}
|
||||
} else {
|
||||
log.trace "Exception polling children: ${response.getErrorMessage()}"
|
||||
def errorJson
|
||||
try {
|
||||
errorJson = response.getErrorJson()
|
||||
} catch (e) {
|
||||
log.error("Unable to parse error json response", e)
|
||||
}
|
||||
if (errorJson?.status?.code == 14) {
|
||||
log.debug "Refreshing your auth_token!"
|
||||
refreshAuthToken([async: true, nextAction: "poll"])
|
||||
} else {
|
||||
log.warn "Error polling children that is not due to an expired token. Response: ${response.getErrorData()}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private getPollParams() {
|
||||
def thermostatIdsString = getChildDeviceIdsString()
|
||||
def requestBody = [
|
||||
selection: [
|
||||
selectionType: "thermostats",
|
||||
@@ -490,32 +394,66 @@ private getPollParams() {
|
||||
includeSensors: true
|
||||
]
|
||||
]
|
||||
return [
|
||||
|
||||
def result = false
|
||||
|
||||
def pollParams = [
|
||||
uri: apiEndpoint,
|
||||
path: "/1/thermostat",
|
||||
headers: ["Authorization": "Bearer ${atomicState.authToken}"],
|
||||
query: [json: toJson(requestBody)]
|
||||
headers: ["Content-Type": "text/json", "Authorization": "Bearer ${atomicState.authToken}"],
|
||||
// TODO - the query string below is not consistent with the Ecobee docs:
|
||||
// https://www.ecobee.com/home/developer/api/documentation/v1/operations/get-thermostats.shtml
|
||||
query: [format: 'json', body: toJson(requestBody)]
|
||||
]
|
||||
|
||||
try{
|
||||
httpGet(pollParams) { resp ->
|
||||
if(resp.status == 200) {
|
||||
log.debug "poll results returned resp.data ${resp.data}"
|
||||
atomicState.remoteSensors = resp.data.thermostatList.remoteSensors
|
||||
updateSensorData()
|
||||
storeThermostatData(resp.data.thermostatList)
|
||||
result = true
|
||||
log.debug "updated ${atomicState.thermostats?.size()} stats: ${atomicState.thermostats}"
|
||||
}
|
||||
}
|
||||
} catch (groovyx.net.http.HttpResponseException e) {
|
||||
log.trace "Exception polling children: " + e.response.data.status
|
||||
if (e.response.data.status.code == 14) {
|
||||
atomicState.action = "pollChildren"
|
||||
log.debug "Refreshing your auth_token!"
|
||||
refreshAuthToken()
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls each child thermostat device to generate an event with the thermostat
|
||||
* data.
|
||||
*/
|
||||
def generateChildThermostatEvent() {
|
||||
log.trace("generateChildThermostatEvent")
|
||||
getChildDevices().each { child ->
|
||||
if (!child.device.deviceNetworkId.startsWith("ecobee_sensor")){
|
||||
if(atomicState.thermostats[child.device.deviceNetworkId] != null) {
|
||||
def tData = atomicState.thermostats[child.device.deviceNetworkId]
|
||||
log.debug "calling child.generateEvent($tData.data)"
|
||||
child.generateEvent(tData.data) //parse received message from parent
|
||||
} else if(atomicState.thermostats[child.device.deviceNetworkId] == null) {
|
||||
log.error "ERROR: Device connection removed? no data for ${child.device.deviceNetworkId}"
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
// Poll Child is invoked from the Child Device itself as part of the Poll Capability
|
||||
def pollChild() {
|
||||
def devices = getChildDevices()
|
||||
|
||||
if (pollChildren()) {
|
||||
devices.each { child ->
|
||||
if (!child.device.deviceNetworkId.startsWith("ecobee_sensor")) {
|
||||
if(atomicState.thermostats[child.device.deviceNetworkId] != null) {
|
||||
def tData = atomicState.thermostats[child.device.deviceNetworkId]
|
||||
log.info "pollChild(child)>> data for ${child.device.deviceNetworkId} : ${tData.data}"
|
||||
child.generateEvent(tData.data) //parse received message from parent
|
||||
} else if(atomicState.thermostats[child.device.deviceNetworkId] == null) {
|
||||
log.error "ERROR: Device connection removed? no data for ${child.device.deviceNetworkId}"
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.info "ERROR: pollChildren()"
|
||||
return null
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void poll() {
|
||||
pollChild()
|
||||
}
|
||||
|
||||
def availableModes(child) {
|
||||
@@ -615,104 +553,47 @@ def toQueryString(Map m) {
|
||||
return m.collect { k, v -> "${k}=${URLEncoder.encode(v.toString())}" }.sort().join("&")
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the refresh token to get a new access token, then executes the nextAction.
|
||||
* @param options - a map of options. valid options are async: true/false, which
|
||||
* specifies if the refresh token request will be done asynchronously or not (default is false)
|
||||
* nextAction: "nameOfMethod" specifies what method to execute after
|
||||
* the token is refreshed (not required).
|
||||
* (note: using a map as the parameter because we need to call it from a schedueled
|
||||
* execution and we can only pass a data map to scheduled executions)
|
||||
*/
|
||||
private void refreshAuthToken(options) {
|
||||
if(!atomicState.refreshToken) {
|
||||
log.warn "Cannot not refresh OAuth token since there is no refreshToken stored"
|
||||
} else {
|
||||
def refreshParams = [
|
||||
uri : apiEndpoint,
|
||||
path : "/token",
|
||||
query : [grant_type: 'refresh_token', code: "${atomicState.refreshToken}", client_id: smartThingsClientId],
|
||||
]
|
||||
if (options.async) {
|
||||
refreshAuthTokenAsync(refreshParams, options.nextAction)
|
||||
} else {
|
||||
refreshAuthTokenSync(refreshParams, options.nextAction)
|
||||
}
|
||||
}
|
||||
}
|
||||
private refreshAuthToken() {
|
||||
log.debug "refreshing auth token"
|
||||
|
||||
private void refreshAuthTokenSync(params, nextAction = null) {
|
||||
try {
|
||||
httpPost(refreshParams) { resp ->
|
||||
if(resp.status == 200) {
|
||||
log.debug "Token refreshed...calling saved RestAction now!"
|
||||
debugEvent("Token refreshed ... calling saved RestAction now!")
|
||||
saveTokenAndResumeAction(resp.data, nextAction)
|
||||
if(!atomicState.refreshToken) {
|
||||
log.warn "Can not refresh OAuth token since there is no refreshToken stored"
|
||||
} else {
|
||||
def refreshParams = [
|
||||
method: 'POST',
|
||||
uri : apiEndpoint,
|
||||
path : "/token",
|
||||
query : [grant_type: 'refresh_token', code: "${atomicState.refreshToken}", client_id: smartThingsClientId],
|
||||
]
|
||||
|
||||
def notificationMessage = "is disconnected from SmartThings, because the access credential changed or was lost. Please go to the Ecobee (Connect) SmartApp and re-enter your account login credentials."
|
||||
//changed to httpPost
|
||||
try {
|
||||
def jsonMap
|
||||
httpPost(refreshParams) { resp ->
|
||||
if(resp.status == 200) {
|
||||
log.debug "Token refreshed...calling saved RestAction now!"
|
||||
debugEvent("Token refreshed ... calling saved RestAction now!")
|
||||
saveTokenAndResumeAction(resp.data)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (groovyx.net.http.HttpResponseException e) {
|
||||
log.error "refreshAuthToken() >> Error: e.statusCode ${e.statusCode}"
|
||||
reauthTokenErrorHandler(e.statusCode)
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshAuthTokenAsync(refreshParams, nextAction = null) {
|
||||
log.debug "making asynchronous refresh request"
|
||||
asynchttp_v1.post('refreshTokenResponseHandler', refreshParams, [nextAction: nextAction])
|
||||
}
|
||||
|
||||
/**
|
||||
* The response handler for the request to refresh the authorization handler.
|
||||
* Stores the new authorization token and refresh token, and executes any action
|
||||
* (method) that failed due to the authorization token expiring.
|
||||
*/
|
||||
private void refreshTokenResponseHandler(response, data) {
|
||||
if (!response.hasError()) {
|
||||
if (response.status == 200) {
|
||||
def json
|
||||
try {
|
||||
json = response.getJson()
|
||||
} catch (e) {
|
||||
log.error "error parsing json from response data: $response.data"
|
||||
}
|
||||
if (json) {
|
||||
log.debug "asnyc refreshTokenHandler: Token refreshed...calling saved RestAction now!"
|
||||
debugEvent("async Token refreshed ... calling saved RestAction now!")
|
||||
saveTokenAndResumeAction(json, data.nextAction)
|
||||
} else {
|
||||
log.warn "successfully parsed json but result is empty or null"
|
||||
}
|
||||
} else {
|
||||
log.debug "Non 200 response returned. Response code: ${response.code}, data: ${response.getData()}"
|
||||
}
|
||||
} else {
|
||||
log.debug "async refreshTokenHandler: RESPONSE ERROR: ${response.getErrorJson()}"
|
||||
reauthTokenErrorHandler(response.getErrorJson().code)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retries refreshing the authorization token. Will attempt to get the refresh
|
||||
* token later, in case there were errors retrieving it.
|
||||
* Will retry a fixed number of times before sending a push notification to the
|
||||
* user instructing them to reauthenticate
|
||||
*/
|
||||
private void reauthTokenErrorHandler(responseCode) {
|
||||
def retryInterval = 300 // in seconds
|
||||
def notificationMessage = "is disconnected from SmartThings, because the access credential changed or was lost. Please go to the Ecobee (Connect) SmartApp and re-enter your account login credentials."
|
||||
// might get non-401 error from exceeding 20 second app limit, connectivity issues, etc.
|
||||
if (responseCode != 401) {
|
||||
runIn(retryInterval, "refreshAuthToken", [async: true])
|
||||
} else if (responseCode == 401) { // unauthorized
|
||||
atomicState.reAttempt = atomicState.reAttempt + 1
|
||||
log.warn "reAttempt refreshAuthToken to try = ${atomicState.reAttempt}"
|
||||
if (atomicState.reAttempt <= 3) {
|
||||
runIn(retryInterval, "refreshAuthToken", [async: true])
|
||||
} else {
|
||||
sendPushAndFeeds(notificationMessage)
|
||||
atomicState.reAttempt = 0
|
||||
}
|
||||
}
|
||||
} catch (groovyx.net.http.HttpResponseException e) {
|
||||
log.error "refreshAuthToken() >> Error: e.statusCode ${e.statusCode}"
|
||||
def reAttemptPeriod = 300 // in sec
|
||||
if (e.statusCode != 401) { // this issue might comes from exceed 20sec app execution, connectivity issue etc.
|
||||
runIn(reAttemptPeriod, "refreshAuthToken")
|
||||
} else if (e.statusCode == 401) { // unauthorized
|
||||
atomicState.reAttempt = atomicState.reAttempt + 1
|
||||
log.warn "reAttempt refreshAuthToken to try = ${atomicState.reAttempt}"
|
||||
if (atomicState.reAttempt <= 3) {
|
||||
runIn(reAttemptPeriod, "refreshAuthToken")
|
||||
} else {
|
||||
sendPushAndFeeds(notificationMessage)
|
||||
atomicState.reAttempt = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -722,20 +603,20 @@ private void reauthTokenErrorHandler(responseCode) {
|
||||
*
|
||||
* @param json - an object representing the parsed JSON response from Ecobee
|
||||
*/
|
||||
private void saveTokenAndResumeAction(json, String nextAction) {
|
||||
def debugMessage = "token response, scope: ${json?.scope}, expires_in: ${json?.expires_in}, token_type: ${json?.token_type}"
|
||||
log.debug "debugMessage"
|
||||
private void saveTokenAndResumeAction(json) {
|
||||
log.debug "token response json: $json"
|
||||
if (json) {
|
||||
debugEvent(debugMessage)
|
||||
debugEvent("Response = $json")
|
||||
atomicState.refreshToken = json?.refresh_token
|
||||
atomicState.authToken = json?.access_token
|
||||
if (nextAction) {
|
||||
log.debug "got refresh token, will execute next action (passed in!): $nextAction"
|
||||
"$nextAction"()
|
||||
if (atomicState.action) {
|
||||
log.debug "got refresh token, executing next action: ${atomicState.action}"
|
||||
"${atomicState.action}"()
|
||||
}
|
||||
} else {
|
||||
log.warn "did not get response body from refresh token response"
|
||||
}
|
||||
atomicState.action = ""
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -875,6 +756,7 @@ private boolean sendCommandToEcobee(Map bodyParams) {
|
||||
try{
|
||||
httpPost(cmdParams) { resp ->
|
||||
if(resp.status == 200) {
|
||||
log.debug "updated ${resp.data}"
|
||||
def returnStatus = resp.data.status.code
|
||||
if (returnStatus == 0) {
|
||||
log.debug "Successful call to ecobee API."
|
||||
@@ -889,10 +771,11 @@ private boolean sendCommandToEcobee(Map bodyParams) {
|
||||
log.trace "Exception Sending Json: " + e.response.data.status
|
||||
debugEvent ("sent Json & got http status ${e.statusCode} - ${e.response.data.status.code}")
|
||||
if (e.response.data.status.code == 14) {
|
||||
// TODO - figure out why we're setting the next action to be poll
|
||||
// TODO - figure out why we're setting the next action to be pollChildren
|
||||
// after refreshing auth token. Is it to keep UI in sync, or just copy/paste error?
|
||||
atomicState.action = "pollChildren"
|
||||
log.debug "Refreshing your auth_token!"
|
||||
refreshAuthToken([async: true, nextAction: "poll"])
|
||||
refreshAuthToken()
|
||||
} else {
|
||||
debugEvent("Authentication error, invalid authentication method, lack of credentials, etc.")
|
||||
log.error "Authentication error, invalid authentication method, lack of credentials, etc."
|
||||
|
||||
@@ -801,10 +801,12 @@ def parse(childDevice, description) {
|
||||
}
|
||||
|
||||
// Philips Hue priority for color is xy > ct > hs
|
||||
// For SmartThings, try to always send hue, sat and hex
|
||||
private sendColorEvents(device, xy, hue, sat, ct, colormode = null) {
|
||||
if (device == null || (xy == null && hue == null && sat == null && ct == null))
|
||||
return
|
||||
|
||||
def events = [:]
|
||||
// For now, only care about changing color temperature if requested by user
|
||||
if (ct != null && (colormode == "ct" || (xy == null && hue == null && sat == null))) {
|
||||
// for some reason setting Hue to their specified minimum off 153 yields 154, dealt with below
|
||||
@@ -818,13 +820,13 @@ private sendColorEvents(device, xy, hue, sat, ct, colormode = null) {
|
||||
if (hue != null) {
|
||||
// 0-65535
|
||||
def value = Math.min(Math.round(hue * 100 / 65535), 65535) as int
|
||||
device.sendEvent([name: "hue", value: value, descriptionText: "Color has changed"])
|
||||
events["hue"] = [name: "hue", value: value, descriptionText: "Color has changed", displayed: false]
|
||||
}
|
||||
|
||||
if (sat != null) {
|
||||
// 0-254
|
||||
def value = Math.round(sat * 100 / 254) as int
|
||||
device.sendEvent([name: "saturation", value: value, descriptionText: "Color has changed"])
|
||||
events["saturation"] = [name: "saturation", value: value, descriptionText: "Color has changed", displayed: false]
|
||||
}
|
||||
|
||||
// Following is used to decide what to base hex calculations on since it is preferred to return a colorchange in hex
|
||||
@@ -836,17 +838,28 @@ private sendColorEvents(device, xy, hue, sat, ct, colormode = null) {
|
||||
def model = state.bulbs[id]?.modelid
|
||||
def hex = colorFromXY(xy, model)
|
||||
|
||||
// TODO Disabled until a solution for the jumping color picker can be figured out
|
||||
//device.sendEvent([name: "color", value: hex.toUpperCase(), descriptionText: "Color has changed", displayed: false])
|
||||
// Create Hue and Saturation events if not previously existing
|
||||
def hsv = hexToHsv(hex)
|
||||
if (events["hue"] == null)
|
||||
events["hue"] = [name: "hue", value: hsv[0], descriptionText: "Color has changed", displayed: false]
|
||||
if (events["saturation"] == null)
|
||||
events["saturation"] = [name: "saturation", value: hsv[1], descriptionText: "Color has changed", displayed: false]
|
||||
|
||||
events["color"] = [name: "color", value: hex.toUpperCase(), descriptionText: "Color has changed", displayed: true]
|
||||
} else if (colormode == "hs" || colormode == null) {
|
||||
// colormode is "hs" or "xy" is missing, default to follow hue/sat which is already handled above
|
||||
def hueValue = (hue != null) ? events["hue"].value : Integer.parseInt("$device.currentHue")
|
||||
def satValue = (sat != null) ? events["saturation"].value : Integer.parseInt("$device.currentSaturation")
|
||||
|
||||
// TODO Disabled until the standard behavior of lights is defined (hue and sat events are sent above)
|
||||
//def hex = colorUtil.hslToHex((int) device.currentHue, (int) device.currentSaturation)
|
||||
// device.sendEvent([name: "color", value: hex.toUpperCase(), descriptionText: "Color has changed"])
|
||||
|
||||
def hex = hsvToHex(hueValue, satValue)
|
||||
events["color"] = [name: "color", value: hex.toUpperCase(), descriptionText: "Color has changed", displayed: true]
|
||||
}
|
||||
|
||||
return debug
|
||||
boolean sendColorChanged = false
|
||||
events.each {
|
||||
device.sendEvent(it.value)
|
||||
}
|
||||
}
|
||||
|
||||
private sendBasicEvents(device, param, value) {
|
||||
@@ -887,8 +900,6 @@ private handleCommandResponse(body) {
|
||||
def updates = [:]
|
||||
|
||||
body.each { payload ->
|
||||
log.debug $payload
|
||||
|
||||
if (payload?.success) {
|
||||
def childDeviceNetworkId = app.id + "/"
|
||||
def eventType
|
||||
@@ -1101,26 +1112,22 @@ def setColor(childDevice, huesettings) {
|
||||
def sat = null
|
||||
def xy = 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
|
||||
if (huesettings.hex != null) {
|
||||
// Prefer hue/sat over hex to make sure it works with the majority of the smartapps
|
||||
if (huesettings.hue != null || huesettings.sat != null) {
|
||||
// If both hex and hue/sat are set, send all values to bridge to get hue/sat in response from bridge to
|
||||
// generate hue/sat events even though bridge will prioritize XY when setting color
|
||||
if (huesettings.hue != null)
|
||||
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) {
|
||||
// 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)
|
||||
// Once groups, or scenes are introduced it might be a good idea to use unique models again
|
||||
value.xy = calculateXY(huesettings.hex)
|
||||
}
|
||||
|
||||
// If both hex and hue/sat are set, send all values to bridge to get hue/sat in response from bridge to
|
||||
// generate hue/sat events even though bridge will prioritize XY when setting color
|
||||
if (huesettings.hue != null)
|
||||
value.hue = Math.min(Math.round(huesettings.hue * 65535 / 100), 65535)
|
||||
else
|
||||
value.hue = Math.min(Math.round(childDevice.device?.currentValue("hue") * 65535 / 100), 65535)
|
||||
|
||||
if (huesettings.saturation != null)
|
||||
value.sat = Math.min(Math.round(huesettings.saturation * 254 / 100), 254)
|
||||
else
|
||||
value.sat = Math.min(Math.round(childDevice.device?.currentValue("saturation") * 254 / 100), 254)
|
||||
|
||||
/* Disabled for now due to bad behavior via Lightning Wizard
|
||||
if (!value.xy) {
|
||||
// Below will translate values to hex->XY to take into account the color support of the different hue types
|
||||
@@ -1175,9 +1182,8 @@ private poll() {
|
||||
def host = getBridgeIP()
|
||||
def uri = "/api/${state.username}/lights/"
|
||||
log.debug "GET: $host$uri"
|
||||
sendHubCommand(new physicalgraph.device.HubAction("""GET ${uri} HTTP/1.1
|
||||
HOST: ${host}
|
||||
""", physicalgraph.device.Protocol.LAN, selectedHue))
|
||||
sendHubCommand(new physicalgraph.device.HubAction("GET ${uri} HTTP/1.1\r\n" +
|
||||
"HOST: ${host}\r\n\r\n", physicalgraph.device.Protocol.LAN, selectedHue))
|
||||
}
|
||||
|
||||
private isOnline(id) {
|
||||
@@ -1193,13 +1199,11 @@ private put(path, body) {
|
||||
log.debug "PUT: $host$uri"
|
||||
log.debug "BODY: ${bodyJSON}"
|
||||
|
||||
sendHubCommand(new physicalgraph.device.HubAction("""PUT $uri HTTP/1.1
|
||||
HOST: ${host}
|
||||
Content-Length: ${length}
|
||||
|
||||
${bodyJSON}
|
||||
""", physicalgraph.device.Protocol.LAN, "${selectedHue}"))
|
||||
|
||||
sendHubCommand(new physicalgraph.device.HubAction("PUT $uri HTTP/1.1\r\n" +
|
||||
"HOST: ${host}\r\n" +
|
||||
"Content-Length: ${length}\r\n" +
|
||||
"\r\n" +
|
||||
"${bodyJSON}", physicalgraph.device.Protocol.LAN, "${selectedHue}"))
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1657,3 +1661,101 @@ private boolean checkPointInLampsReach(p, colorPoints) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an RGB color in hex to HSV.
|
||||
* Algorithm based on http://en.wikipedia.org/wiki/HSV_color_space.
|
||||
*
|
||||
* @param colorStr color value in hex (#ff03d3)
|
||||
*
|
||||
* @return HSV representation in an array (0-100) [hue, sat, value]
|
||||
*/
|
||||
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 max = Math.max(Math.max(r, g), b)
|
||||
def min = Math.min(Math.min(r, g), b)
|
||||
|
||||
def h, s, v = max;
|
||||
|
||||
def d = max - min;
|
||||
s = max == 0 ? 0 : d / max;
|
||||
|
||||
if(max == min){
|
||||
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;
|
||||
}
|
||||
h /= 6;
|
||||
}
|
||||
|
||||
return [(h * 100).round(), (s * 100).round(), (v * 100).round()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts HSV color to RGB in hex.
|
||||
* Algorithm based on http://en.wikipedia.org/wiki/HSV_color_space.
|
||||
*
|
||||
* @param hue hue 0-100
|
||||
* @param sat saturation 0-100
|
||||
* @param value value 0-100 (defaults to 100)
|
||||
|
||||
* @return the color in hex (#ff03d3)
|
||||
*/
|
||||
def hsvToHex(hue, sat, value = 100){
|
||||
def r, g, b;
|
||||
def h = hue / 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);
|
||||
|
||||
switch (i % 6) {
|
||||
case 0:
|
||||
r = v
|
||||
g = t
|
||||
b = p
|
||||
break
|
||||
case 1:
|
||||
r = q
|
||||
g = v
|
||||
b = p
|
||||
break
|
||||
case 2:
|
||||
r = p
|
||||
g = v
|
||||
b = t
|
||||
break
|
||||
case 3:
|
||||
r = p
|
||||
g = q
|
||||
b = v
|
||||
break
|
||||
case 4:
|
||||
r = t
|
||||
g = p
|
||||
b = v
|
||||
break
|
||||
case 5:
|
||||
r = v
|
||||
g = p
|
||||
b = q
|
||||
break
|
||||
}
|
||||
|
||||
// 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));
|
||||
|
||||
return "#$r1$g1$b1"
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ definition(
|
||||
}
|
||||
|
||||
preferences(oauthPage: "deviceAuthorization") {
|
||||
page(name: "Credentials", title: "Connect to your Logitech Harmony device", content: "authPage", install: false, nextPage: "deviceAuthorization")
|
||||
page(name: "Credentials", title: "Connect to your Logitech Harmony device", content: "authPage", install: false, nextPage: "deviceAuthorization")
|
||||
page(name: "deviceAuthorization", title: "Logitech Harmony device authorization", install: true) {
|
||||
section("Allow Logitech Harmony to control these things...") {
|
||||
input "switches", "capability.switch", title: "Which Switches?", multiple: true, required: false
|
||||
@@ -102,7 +102,8 @@ def authPage() {
|
||||
description = "Click to enter Harmony Credentials"
|
||||
def redirectUrl = buildRedirectUrl
|
||||
return dynamicPage(name: "Credentials", title: "Harmony", nextPage: null, uninstall: true, install:false) {
|
||||
section { href url:redirectUrl, style:"embedded", required:true, title:"Harmony", description:description }
|
||||
section { paragraph title: "Note:", "This device has not been officially tested and certified to “Work with SmartThings”. You can connect it to your SmartThings home but performance may vary and we will not be able to provide support or assistance." }
|
||||
section { href url:redirectUrl, style:"embedded", required:true, title:"Harmony", description:description }
|
||||
}
|
||||
} else {
|
||||
//device discovery request every 5 //25 seconds
|
||||
@@ -314,8 +315,6 @@ def installed() {
|
||||
}
|
||||
|
||||
def updated() {
|
||||
unsubscribe()
|
||||
unschedule()
|
||||
if (!state.accessToken) {
|
||||
log.debug "About to create access token"
|
||||
createAccessToken()
|
||||
|
||||
@@ -26,17 +26,22 @@ definition(
|
||||
)
|
||||
|
||||
preferences {
|
||||
section ("In addition to push notifications, send text alerts to...") {
|
||||
input("recipients", "contact", title: "Send notifications to") {
|
||||
input "phone1", "phone", title: "Phone Number 1", required: false
|
||||
input "phone2", "phone", title: "Phone Number 2", required: false
|
||||
input "phone3", "phone", title: "Phone Number 3", required: false
|
||||
}
|
||||
|
||||
if (!(location.zipCode || ( location.latitude && location.longitude )) && location.channelName == 'samsungtv') {
|
||||
section { paragraph title: "Note:", "Location is required for this SmartApp. Go to 'Location Name' settings to setup your correct location." }
|
||||
}
|
||||
|
||||
section ("Zip code (optional, defaults to location coordinates)...") {
|
||||
input "zipcode", "text", title: "Zip Code", required: false
|
||||
}
|
||||
if (location.channelName != 'samsungtv') {
|
||||
section( "Set your location" ) { input "zipCode", "text", title: "Zip code" }
|
||||
}
|
||||
|
||||
section ("In addition to push notifications, send text alerts to...") {
|
||||
input("recipients", "contact", title: "Send notifications to") {
|
||||
input "phone1", "phone", title: "Phone Number 1", required: false
|
||||
input "phone2", "phone", title: "Phone Number 2", required: false
|
||||
input "phone3", "phone", title: "Phone Number 3", required: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def installed() {
|
||||
@@ -61,7 +66,7 @@ def checkForSevereWeather() {
|
||||
def alerts
|
||||
if(locationIsDefined()) {
|
||||
if(zipcodeIsValid()) {
|
||||
alerts = getWeatherFeature("alerts", zipcode)?.alerts
|
||||
alerts = getWeatherFeature("alerts", zipCode)?.alerts
|
||||
} else {
|
||||
log.warn "Severe Weather Alert: Invalid zipcode entered, defaulting to location's zipcode"
|
||||
alerts = getWeatherFeature("alerts")?.alerts
|
||||
|
||||
@@ -86,6 +86,7 @@ def firstPage()
|
||||
def lightSwitchesDiscovered = lightSwitchesDiscovered()
|
||||
|
||||
return dynamicPage(name:"firstPage", title:"Discovery Started!", nextPage:"", refreshInterval: refreshInterval, install:true, uninstall: true) {
|
||||
section { paragraph title: "Note:", "This device has not been officially tested and certified to “Work with SmartThings”. You can connect it to your SmartThings home but performance may vary and we will not be able to provide support or assistance." }
|
||||
section("Select a device...") {
|
||||
input "selectedSwitches", "enum", required:false, title:"Select Wemo Switches \n(${switchesDiscovered.size() ?: 0} found)", multiple:true, options:switchesDiscovered
|
||||
input "selectedMotions", "enum", required:false, title:"Select Wemo Motions \n(${motionsDiscovered.size() ?: 0} found)", multiple:true, options:motionsDiscovered
|
||||
@@ -681,4 +682,4 @@ private Boolean hasAllHubsOver(String desiredFirmware) {
|
||||
|
||||
private List getRealHubFirmwareVersions() {
|
||||
return location.hubs*.firmwareVersionString.findAll { it }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,800 @@
|
||||
/**
|
||||
* Home Remote
|
||||
*
|
||||
* Copyright 2015 The Home Remote
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
definition(
|
||||
name: "Home Remote",
|
||||
namespace: "thehomeremote.homeremote",
|
||||
author: "The Home Remote",
|
||||
description: "Web service that enables communication between the Home Remote app and a SmartThings hub.",
|
||||
category: "My Apps",
|
||||
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
|
||||
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
|
||||
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
|
||||
oauth: [displayName: "The Home Remote", displayLink: "http://thehomeremote.com/"])
|
||||
|
||||
|
||||
preferences {
|
||||
section() {
|
||||
input "accelerationSensors", "capability.accelerationSensor",title: "Acceleration Sensors", multiple: true, required: false
|
||||
input "alarms", "capability.alarm",title: "Alarms", multiple: true, required: false
|
||||
input "batteries", "capability.battery",title: "Batteries", multiple: true, required: false
|
||||
input "beacons", "capability.beacon",title: "Beacons", multiple: true, required: false
|
||||
input "buttonGroup", "capability.button",title: "Buttons", multiple: true, required: false
|
||||
input "carbonMonoxideDetectors", "capability.carbonMonoxideDetector",title: "CO Detectors", multiple: true, required: false
|
||||
input "colorControls", "capability.colorControl",title: "Color Lights", multiple: true, required: false
|
||||
input "contactSensors", "capability.contactSensor",title: "Contact Sensors", multiple: true, required: false
|
||||
input "doorControls", "capability.doorControl",title: "Door Controllers", multiple: true, required: false
|
||||
input "energyMeters", "capability.energyMeter",title: "Energy Meters", multiple: true, required: false
|
||||
input "illuminanceMeasurements", "capability.illuminanceMeasurement",title: "Illuminance Sensors", multiple: true, required: false
|
||||
input "imageCaptures", "capability.imageCapture",title: "Cameras", multiple: true, required: false
|
||||
input "locks", "capability.lock",title: "Locks", multiple: true, required: false
|
||||
input "mediaControllers", "capability.mediaController",title: "Media Controllers", multiple: true, required: false
|
||||
input "momentaries", "capability.momentary",title: "Momentary Buttons", multiple: true, required: false
|
||||
input "motionSensors", "capability.motionSensor",title: "Motion Sensors", multiple: true, required: false
|
||||
input "musicPlayers", "capability.musicPlayer",title: "Music Players", multiple: true, required: false
|
||||
input "powerMeters", "capability.powerMeter",title: "Power Meters", multiple: true, required: false
|
||||
input "presenceSensors", "capability.presenceSensor",title: "Presence Sensors", multiple: true, required: false
|
||||
input "relativeHumidityMeasurements", "capability.relativeHumidityMeasurement",title: "Humidity Sensors", multiple: true, required: false
|
||||
input "relaySwitches", "capability.relaySwitch",title: "Relays", multiple: true, required: false
|
||||
input "signalStrengths", "capability.signalStrength",title: "Signal Strengths", multiple: true, required: false
|
||||
input "sleepSensors", "capability.sleepSensor",title: "Sleep Sensors", multiple: true, required: false
|
||||
input "smokeDetectors", "capability.smokeDetector",title: "Smoke Detectors", multiple: true, required: false
|
||||
input "speechSyntheses", "capability.speechSynthesis",title: "Speech Syntheses", multiple: true, required: false
|
||||
input "stepSensors", "capability.stepSensor",title: "Step Sensors", multiple: true, required: false
|
||||
input "switches", "capability.switch",title: "Switches", multiple: true, required: false
|
||||
input "switchLevels", "capability.switchLevel",title: "Dimmers", multiple: true, required: false
|
||||
input "temperatureMeasurements", "capability.temperatureMeasurement",title: "Temperature Sensors", multiple: true, required: false
|
||||
input "thermostats", "capability.thermostat",title: "Thermostats", multiple: true, required: false
|
||||
input "threeAxes", "capability.threeAxis",title: "Three axis Sensors", multiple: true, required: false
|
||||
input "tones", "capability.tone",title: "Tones", multiple: true, required: false
|
||||
input "touchSensors", "capability.touchSensor",title: "Touch Sensors", multiple: true, required: false
|
||||
input "valves", "capability.valve",title: "Valves", multiple: true, required: false
|
||||
input "waterSensors", "capability.waterSensor",title: "Water Sensors", multiple: true, required: false
|
||||
}
|
||||
}
|
||||
|
||||
mappings {
|
||||
path("/GetCurrentValues") {
|
||||
action: [
|
||||
GET: "getCurrentValues"
|
||||
]
|
||||
}
|
||||
path("/GetCurrentValuesWithDisplayName") {
|
||||
action: [
|
||||
GET: "getCurrentValuesWithDisplayName"
|
||||
]
|
||||
}
|
||||
path("/GetRoutines") {
|
||||
action: [
|
||||
GET: "getRoutines"
|
||||
]
|
||||
}
|
||||
path("/ExecuteCommand") {
|
||||
action: [
|
||||
PUT: "executeCommand"
|
||||
]
|
||||
}
|
||||
path("/ExecuteRoutine") {
|
||||
action: [
|
||||
PUT: "executeRoutine"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
def getCurrentValues() {
|
||||
def resp = []
|
||||
|
||||
accelerationSensors.each {
|
||||
resp << [id: it.id, capability: "AccelerationSensor", attribute: "acceleration", value: it.currentValue("acceleration")]
|
||||
}
|
||||
|
||||
alarms.each {
|
||||
resp << [id: it.id, capability: "Alarm", attribute: "alarm", value: it.currentValue("alarm")]
|
||||
}
|
||||
|
||||
batteries.each {
|
||||
resp << [id: it.id, capability: "Battery", attribute: "battery", value: it.currentValue("battery")]
|
||||
}
|
||||
|
||||
beacons.each {
|
||||
resp << [id: it.id, capability: "Beacon", attribute: "presence", value: it.currentValue("presence")]
|
||||
}
|
||||
|
||||
buttonGroup.each {
|
||||
resp << [id: it.id, capability: "Button", attribute: "button", value: it.currentValue("button")]
|
||||
}
|
||||
|
||||
carbonMonoxideDetectors.each {
|
||||
resp << [id: it.id, capability: "CarbonMonoxideDetector", attribute: "carbonMonoxide", value: it.currentValue("carbonMonoxide")]
|
||||
}
|
||||
|
||||
colorControls.each {
|
||||
resp << [id: it.id, capability: "ColorControl", attribute: "hue", value: it.currentValue("hue")]
|
||||
}
|
||||
|
||||
colorControls.each {
|
||||
resp << [id: it.id, capability: "ColorControl", attribute: "saturation", value: it.currentValue("saturation")]
|
||||
}
|
||||
|
||||
colorControls.each {
|
||||
resp << [id: it.id, capability: "ColorControl", attribute: "color", value: it.currentValue("color")]
|
||||
}
|
||||
|
||||
contactSensors.each {
|
||||
resp << [id: it.id, capability: "ContactSensor", attribute: "contact", value: it.currentValue("contact")]
|
||||
}
|
||||
|
||||
doorControls.each {
|
||||
resp << [id: it.id, capability: "DoorControl", attribute: "door", value: it.currentValue("door")]
|
||||
}
|
||||
|
||||
energyMeters.each {
|
||||
resp << [id: it.id, capability: "EnergyMeter", attribute: "energy", value: it.currentValue("energy")]
|
||||
}
|
||||
|
||||
illuminanceMeasurements.each {
|
||||
resp << [id: it.id, capability: "IlluminanceMeasurement", attribute: "illuminance", value: it.currentValue("illuminance")]
|
||||
}
|
||||
|
||||
imageCaptures.each {
|
||||
resp << [id: it.id, capability: "ImageCapture", attribute: "image", value: it.currentValue("image")]
|
||||
}
|
||||
|
||||
locks.each {
|
||||
resp << [id: it.id, capability: "Lock", attribute: "lock", value: it.currentValue("lock")]
|
||||
}
|
||||
|
||||
mediaControllers.each {
|
||||
resp << [id: it.id, capability: "MediaController", attribute: "activities", value: it.currentValue("activities")]
|
||||
}
|
||||
|
||||
mediaControllers.each {
|
||||
resp << [id: it.id, capability: "MediaController", attribute: "currentActivity", value: it.currentValue("currentActivity")]
|
||||
}
|
||||
|
||||
motionSensors.each {
|
||||
resp << [id: it.id, capability: "MotionSensor", attribute: "motion", value: it.currentValue("motion")]
|
||||
}
|
||||
|
||||
musicPlayers.each {
|
||||
resp << [id: it.id, capability: "MusicPlayer", attribute: "status", value: it.currentValue("status")]
|
||||
}
|
||||
|
||||
musicPlayers.each {
|
||||
resp << [id: it.id, capability: "MusicPlayer", attribute: "level", value: it.currentValue("level")]
|
||||
}
|
||||
|
||||
musicPlayers.each {
|
||||
resp << [id: it.id, capability: "MusicPlayer", attribute: "trackDescription", value: it.currentValue("trackDescription")]
|
||||
}
|
||||
|
||||
musicPlayers.each {
|
||||
resp << [id: it.id, capability: "MusicPlayer", attribute: "trackData", value: it.currentValue("trackData")]
|
||||
}
|
||||
|
||||
musicPlayers.each {
|
||||
resp << [id: it.id, capability: "MusicPlayer", attribute: "mute", value: it.currentValue("mute")]
|
||||
}
|
||||
|
||||
powerMeters.each {
|
||||
resp << [id: it.id, capability: "PowerMeter", attribute: "power", value: it.currentValue("power")]
|
||||
}
|
||||
|
||||
presenceSensors.each {
|
||||
resp << [id: it.id, capability: "PresenceSensor", attribute: "presence", value: it.currentValue("presence")]
|
||||
}
|
||||
|
||||
relativeHumidityMeasurements.each {
|
||||
resp << [id: it.id, capability: "RelativeHumidityMeasurement", attribute: "humidity", value: it.currentValue("humidity")]
|
||||
}
|
||||
|
||||
relaySwitches.each {
|
||||
resp << [id: it.id, capability: "RelaySwitch", attribute: "switch", value: it.currentValue("switch")]
|
||||
}
|
||||
|
||||
signalStrengths.each {
|
||||
resp << [id: it.id, capability: "SignalStrength", attribute: "lqi", value: it.currentValue("lqi")]
|
||||
}
|
||||
|
||||
signalStrengths.each {
|
||||
resp << [id: it.id, capability: "SignalStrength", attribute: "rssi", value: it.currentValue("rssi")]
|
||||
}
|
||||
|
||||
sleepSensors.each {
|
||||
resp << [id: it.id, capability: "SleepSensor", attribute: "sleeping", value: it.currentValue("sleeping")]
|
||||
}
|
||||
|
||||
smokeDetectors.each {
|
||||
resp << [id: it.id, capability: "SmokeDetector", attribute: "smoke", value: it.currentValue("smoke")]
|
||||
}
|
||||
|
||||
stepSensors.each {
|
||||
resp << [id: it.id, capability: "StepSensor", attribute: "steps", value: it.currentValue("steps")]
|
||||
}
|
||||
|
||||
stepSensors.each {
|
||||
resp << [id: it.id, capability: "StepSensor", attribute: "goal", value: it.currentValue("goal")]
|
||||
}
|
||||
|
||||
switches.each {
|
||||
resp << [id: it.id, capability: "Switch", attribute: "switch", value: it.currentValue("switch")]
|
||||
}
|
||||
|
||||
switchLevels.each {
|
||||
resp << [id: it.id, capability: "SwitchLevel", attribute: "level", value: it.currentValue("level")]
|
||||
}
|
||||
|
||||
temperatureMeasurements.each {
|
||||
resp << [id: it.id, capability: "TemperatureMeasurement", attribute: "temperature", value: it.currentValue("temperature")]
|
||||
}
|
||||
|
||||
thermostats.each {
|
||||
resp << [id: it.id, capability: "Thermostat", attribute: "temperature", value: it.currentValue("temperature")]
|
||||
}
|
||||
|
||||
thermostats.each {
|
||||
resp << [id: it.id, capability: "Thermostat", attribute: "heatingSetpoint", value: it.currentValue("heatingSetpoint")]
|
||||
}
|
||||
|
||||
thermostats.each {
|
||||
resp << [id: it.id, capability: "Thermostat", attribute: "coolingSetpoint", value: it.currentValue("coolingSetpoint")]
|
||||
}
|
||||
|
||||
//Commented out on 7/23/2016. This randomly started throwing number format exceptions with either my ecobee or Lyric thermostat.
|
||||
//thermostats.each {
|
||||
// resp << [id: it.id, capability: "Thermostat", attribute: "thermostatSetpoint", value: it.currentValue("thermostatSetpoint")]
|
||||
//}
|
||||
|
||||
thermostats.each {
|
||||
resp << [id: it.id, capability: "Thermostat", attribute: "thermostatMode", value: it.currentValue("thermostatMode")]
|
||||
}
|
||||
|
||||
thermostats.each {
|
||||
resp << [id: it.id, capability: "Thermostat", attribute: "thermostatFanMode", value: it.currentValue("thermostatFanMode")]
|
||||
}
|
||||
|
||||
thermostats.each {
|
||||
resp << [id: it.id, capability: "Thermostat", attribute: "thermostatOperatingState", value: it.currentValue("thermostatOperatingState")]
|
||||
}
|
||||
|
||||
threeAxes.each {
|
||||
resp << [id: it.id, capability: "ThreeAxis", attribute: "threeAxis", value: it.currentValue("threeAxis")]
|
||||
}
|
||||
|
||||
touchSensors.each {
|
||||
resp << [id: it.id, capability: "TouchSensor", attribute: "touch", value: it.currentValue("touch")]
|
||||
}
|
||||
|
||||
valves.each {
|
||||
resp << [id: it.id, capability: "Valve", attribute: "contact", value: it.currentValue("contact")]
|
||||
}
|
||||
|
||||
waterSensors.each {
|
||||
resp << [id: it.id, capability: "WaterSensor", attribute: "water", value: it.currentValue("water")]
|
||||
}
|
||||
|
||||
//resp << [id: 0, capability: "Heartbeat", attribute: "heartbeat", value: String.valueOf(state.heartbeat)]
|
||||
|
||||
state.heartbeat = !state.heartbeat
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
def getCurrentValuesWithDisplayName() {
|
||||
def resp = []
|
||||
|
||||
accelerationSensors.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "AccelerationSensor", attribute: "acceleration", value: it.currentValue("acceleration")]
|
||||
}
|
||||
|
||||
alarms.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "Alarm", attribute: "alarm", value: it.currentValue("alarm")]
|
||||
}
|
||||
|
||||
batteries.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "Battery", attribute: "battery", value: it.currentValue("battery")]
|
||||
}
|
||||
|
||||
beacons.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "Beacon", attribute: "presence", value: it.currentValue("presence")]
|
||||
}
|
||||
|
||||
buttonGroup.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "Button", attribute: "button", value: it.currentValue("button")]
|
||||
}
|
||||
|
||||
carbonMonoxideDetectors.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "CarbonMonoxideDetector", attribute: "carbonMonoxide", value: it.currentValue("carbonMonoxide")]
|
||||
}
|
||||
|
||||
colorControls.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "ColorControl", attribute: "hue", value: it.currentValue("hue")]
|
||||
}
|
||||
|
||||
colorControls.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "ColorControl", attribute: "saturation", value: it.currentValue("saturation")]
|
||||
}
|
||||
|
||||
colorControls.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "ColorControl", attribute: "color", value: it.currentValue("color")]
|
||||
}
|
||||
|
||||
contactSensors.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "ContactSensor", attribute: "contact", value: it.currentValue("contact")]
|
||||
}
|
||||
|
||||
doorControls.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "DoorControl", attribute: "door", value: it.currentValue("door")]
|
||||
}
|
||||
|
||||
energyMeters.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "EnergyMeter", attribute: "energy", value: it.currentValue("energy")]
|
||||
}
|
||||
|
||||
illuminanceMeasurements.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "IlluminanceMeasurement", attribute: "illuminance", value: it.currentValue("illuminance")]
|
||||
}
|
||||
|
||||
imageCaptures.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "ImageCapture", attribute: "image", value: it.currentValue("image")]
|
||||
}
|
||||
|
||||
locks.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "Lock", attribute: "lock", value: it.currentValue("lock")]
|
||||
}
|
||||
|
||||
mediaControllers.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "MediaController", attribute: "activities", value: it.currentValue("activities")]
|
||||
}
|
||||
|
||||
mediaControllers.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "MediaController", attribute: "currentActivity", value: it.currentValue("currentActivity")]
|
||||
}
|
||||
|
||||
motionSensors.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "MotionSensor", attribute: "motion", value: it.currentValue("motion")]
|
||||
}
|
||||
|
||||
musicPlayers.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "MusicPlayer", attribute: "status", value: it.currentValue("status")]
|
||||
}
|
||||
|
||||
musicPlayers.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "MusicPlayer", attribute: "level", value: it.currentValue("level")]
|
||||
}
|
||||
|
||||
musicPlayers.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "MusicPlayer", attribute: "trackDescription", value: it.currentValue("trackDescription")]
|
||||
}
|
||||
|
||||
musicPlayers.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "MusicPlayer", attribute: "trackData", value: it.currentValue("trackData")]
|
||||
}
|
||||
|
||||
musicPlayers.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "MusicPlayer", attribute: "mute", value: it.currentValue("mute")]
|
||||
}
|
||||
|
||||
powerMeters.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "PowerMeter", attribute: "power", value: it.currentValue("power")]
|
||||
}
|
||||
|
||||
presenceSensors.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "PresenceSensor", attribute: "presence", value: it.currentValue("presence")]
|
||||
}
|
||||
|
||||
relativeHumidityMeasurements.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "RelativeHumidityMeasurement", attribute: "humidity", value: it.currentValue("humidity")]
|
||||
}
|
||||
|
||||
relaySwitches.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "RelaySwitch", attribute: "switch", value: it.currentValue("switch")]
|
||||
}
|
||||
|
||||
signalStrengths.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "SignalStrength", attribute: "lqi", value: it.currentValue("lqi")]
|
||||
}
|
||||
|
||||
signalStrengths.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "SignalStrength", attribute: "rssi", value: it.currentValue("rssi")]
|
||||
}
|
||||
|
||||
sleepSensors.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "SleepSensor", attribute: "sleeping", value: it.currentValue("sleeping")]
|
||||
}
|
||||
|
||||
smokeDetectors.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "SmokeDetector", attribute: "smoke", value: it.currentValue("smoke")]
|
||||
}
|
||||
|
||||
stepSensors.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "StepSensor", attribute: "steps", value: it.currentValue("steps")]
|
||||
}
|
||||
|
||||
stepSensors.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "StepSensor", attribute: "goal", value: it.currentValue("goal")]
|
||||
}
|
||||
|
||||
switches.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "Switch", attribute: "switch", value: it.currentValue("switch")]
|
||||
}
|
||||
|
||||
switchLevels.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "SwitchLevel", attribute: "level", value: it.currentValue("level")]
|
||||
}
|
||||
|
||||
temperatureMeasurements.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "TemperatureMeasurement", attribute: "temperature", value: it.currentValue("temperature")]
|
||||
}
|
||||
|
||||
thermostats.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "temperature", value: it.currentValue("temperature")]
|
||||
}
|
||||
|
||||
thermostats.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "heatingSetpoint", value: it.currentValue("heatingSetpoint")]
|
||||
}
|
||||
|
||||
thermostats.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "coolingSetpoint", value: it.currentValue("coolingSetpoint")]
|
||||
}
|
||||
|
||||
//Commented out on 7/23/2016. This randomly started throwing number format exceptions with either my ecobee or Lyric thermostat.
|
||||
//thermostats.each {
|
||||
// resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "thermostatSetpoint", value: it.currentValue("thermostatSetpoint")]
|
||||
//}
|
||||
|
||||
thermostats.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "thermostatMode", value: it.currentValue("thermostatMode")]
|
||||
}
|
||||
|
||||
thermostats.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "thermostatFanMode", value: it.currentValue("thermostatFanMode")]
|
||||
}
|
||||
|
||||
thermostats.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "thermostatOperatingState", value: it.currentValue("thermostatOperatingState")]
|
||||
}
|
||||
|
||||
threeAxes.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "ThreeAxis", attribute: "threeAxis", value: it.currentValue("threeAxis")]
|
||||
}
|
||||
|
||||
touchSensors.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "TouchSensor", attribute: "touch", value: it.currentValue("touch")]
|
||||
}
|
||||
|
||||
valves.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "Valve", attribute: "contact", value: it.currentValue("contact")]
|
||||
}
|
||||
|
||||
waterSensors.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "WaterSensor", attribute: "water", value: it.currentValue("water")]
|
||||
}
|
||||
|
||||
momentaries.each {
|
||||
resp << [id: it.id, displayName: it.displayName, capability: "Momentary", attribute: "", value: ""]
|
||||
}
|
||||
|
||||
//resp << [id: 0, displayName: "Heartbeat", capability: "Heartbeat", attribute: "heartbeat", value: state.heartbeat]
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
def getDevices(capability){
|
||||
|
||||
def result
|
||||
|
||||
switch (capability) {
|
||||
case "Alarm":
|
||||
result = alarms
|
||||
break
|
||||
case "ColorControl":
|
||||
result = colorControls
|
||||
break
|
||||
case "DoorControl":
|
||||
result = doorControls
|
||||
break
|
||||
case "ImageCapture":
|
||||
result = imageCaptures
|
||||
break
|
||||
case "Lock":
|
||||
result = locks
|
||||
break
|
||||
case "MediaController":
|
||||
result = mediaControllers
|
||||
break
|
||||
case "Momentary":
|
||||
result = momentaries
|
||||
break
|
||||
case "MusicPlayer":
|
||||
result = musicPlayers
|
||||
break
|
||||
case "RelaySwitch":
|
||||
result = relaySwitches
|
||||
break
|
||||
case "SpeechSynthesis":
|
||||
result = speechSyntheses
|
||||
break
|
||||
case "Switch":
|
||||
result = switches
|
||||
break
|
||||
case "SwitchLevel":
|
||||
result = switchLevels
|
||||
break
|
||||
case "Thermostat":
|
||||
result = thermostats
|
||||
break
|
||||
case "ThermostatCoolingSetpoint":
|
||||
result = thermostatCoolingSetpoints
|
||||
break
|
||||
case "ThermostatFanMode":
|
||||
result = thermostatFanModes
|
||||
break
|
||||
case "ThermostatHeatingSetpoint":
|
||||
result = thermostatHeatingSetpoints
|
||||
break
|
||||
case "ThermostatMode":
|
||||
result = thermostatModes
|
||||
break
|
||||
case "Tone":
|
||||
result = tones
|
||||
break
|
||||
case "Valve":
|
||||
result = valves
|
||||
break
|
||||
default:
|
||||
result = valves
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
def getDoorControlCommand(value){
|
||||
def result
|
||||
switch (value) {
|
||||
case "closed":
|
||||
result = "close"
|
||||
break
|
||||
case "open":
|
||||
result = "open"
|
||||
break
|
||||
default:
|
||||
result = value
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
def getLockCommand(value){
|
||||
def result
|
||||
switch (value) {
|
||||
case "locked":
|
||||
result = "lock"
|
||||
break
|
||||
case "unlocked":
|
||||
result = "unlock"
|
||||
break
|
||||
default:
|
||||
result = value
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
def getMuteCommand(value){
|
||||
def result
|
||||
switch (value) {
|
||||
case "muted":
|
||||
result = "mute"
|
||||
break
|
||||
case "unmuted":
|
||||
result = "unmute"
|
||||
break
|
||||
default:
|
||||
result = value
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
def getContactCommand(value){
|
||||
def result
|
||||
switch (value) {
|
||||
case "closed":
|
||||
result = "close"
|
||||
break
|
||||
case "open":
|
||||
result = "open"
|
||||
break
|
||||
default:
|
||||
result = value
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
def getRoutines() {
|
||||
return location.helloHome?.getPhrases()*.label
|
||||
}
|
||||
|
||||
def getThermostatFanModeCommand(value){
|
||||
def result
|
||||
switch (value) {
|
||||
case "on":
|
||||
result = "fanOn"
|
||||
break
|
||||
case "auto":
|
||||
result = "fanAuto"
|
||||
break
|
||||
case "circulate":
|
||||
result = "fanCirculate"
|
||||
break
|
||||
default:
|
||||
result = value
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
void executeCommand() {
|
||||
def deviceId = request.JSON?.deviceId
|
||||
def capability = request.JSON?.capability
|
||||
def attribute = request.JSON?.attribute
|
||||
def value = request.JSON?.value
|
||||
if (deviceId) {
|
||||
def devices = getDevices(capability)
|
||||
def command
|
||||
def valueIsParameter = false
|
||||
def valueIsInteger = false
|
||||
switch (attribute) {
|
||||
case "hue":
|
||||
command = "setHue"
|
||||
valueIsParameter = true
|
||||
valueIsInteger = true
|
||||
break
|
||||
case "saturation":
|
||||
command = "setSaturation"
|
||||
valueIsParameter = true
|
||||
valueIsInteger = true
|
||||
break
|
||||
case "color":
|
||||
command = "setColor"
|
||||
def rgb = hexToRgb(value)
|
||||
def hsl = rgbToHSL(rgb)
|
||||
value = [hue:hsl.h.toInteger(), saturation:hsl.s.toInteger()]
|
||||
valueIsParameter = true
|
||||
break
|
||||
case "level":
|
||||
command = "setLevel"
|
||||
valueIsParameter = true
|
||||
valueIsInteger = true
|
||||
break
|
||||
case "heatingSetpoint":
|
||||
command = "setHeatingSetpoint"
|
||||
valueIsParameter = true
|
||||
break
|
||||
case "coolingSetpoint":
|
||||
command = "setCoolingSetpoint"
|
||||
valueIsParameter = true
|
||||
break
|
||||
case "currentActivity":
|
||||
command = "startActivity"
|
||||
valueIsParameter = true
|
||||
break
|
||||
case "door":
|
||||
command = getDoorControlCommand(value)
|
||||
break
|
||||
case "lock":
|
||||
command = getLockCommand(value)
|
||||
break
|
||||
case "mute":
|
||||
command = getMuteCommand(value)
|
||||
break
|
||||
case "thermostatFanMode":
|
||||
command = getThermostatFanModeCommand(value)
|
||||
break
|
||||
case "thermostatMode":
|
||||
if (value == "emergency heat") {
|
||||
command = "emergencyHeat"
|
||||
}
|
||||
else
|
||||
{
|
||||
command = value
|
||||
}
|
||||
break
|
||||
case "contact":
|
||||
command = getContactCommand(value)
|
||||
break
|
||||
default:
|
||||
command = value
|
||||
}
|
||||
devices.each {
|
||||
if (it.id == deviceId) {
|
||||
// check that the device supports the specified command
|
||||
// If not, return an error using httpError, providing a HTTP status code.
|
||||
if (!it.hasCommand(command)) {
|
||||
httpError(501, "$command is not a valid command for the device")
|
||||
}
|
||||
if(valueIsParameter){
|
||||
if(valueIsInteger){
|
||||
it."$command"(value as int)
|
||||
}
|
||||
else{
|
||||
it."$command"(value)
|
||||
}
|
||||
}
|
||||
else{
|
||||
it."$command"()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void executeRoutine() {
|
||||
def routine = request.JSON?.routine
|
||||
location.helloHome?.execute(routine)
|
||||
}
|
||||
|
||||
def rgbToHSL(rgb) {
|
||||
def r = rgb.r / 255
|
||||
def g = rgb.g / 255
|
||||
def b = rgb.b / 255
|
||||
def h = 0
|
||||
def s = 0
|
||||
def l = 0
|
||||
|
||||
def var_min = [r,g,b].min()
|
||||
def var_max = [r,g,b].max()
|
||||
def del_max = var_max - var_min
|
||||
|
||||
l = (var_max + var_min) / 2
|
||||
|
||||
if (del_max == 0) {
|
||||
h = 0
|
||||
s = 0
|
||||
} else {
|
||||
if (l < 0.5) { s = del_max / (var_max + var_min) }
|
||||
else { s = del_max / (2 - var_max - var_min) }
|
||||
|
||||
def del_r = (((var_max - r) / 6) + (del_max / 2)) / del_max
|
||||
def del_g = (((var_max - g) / 6) + (del_max / 2)) / del_max
|
||||
def del_b = (((var_max - b) / 6) + (del_max / 2)) / del_max
|
||||
|
||||
if (r == var_max) { h = del_b - del_g }
|
||||
else if (g == var_max) { h = (1 / 3) + del_r - del_b }
|
||||
else if (b == var_max) { h = (2 / 3) + del_g - del_r }
|
||||
|
||||
if (h < 0) { h += 1 }
|
||||
if (h > 1) { h -= 1 }
|
||||
}
|
||||
def hsl = [:]
|
||||
hsl = [h: h * 100, s: s * 100, l: l]
|
||||
|
||||
hsl
|
||||
}
|
||||
|
||||
def hexToRgb(colorHex) {
|
||||
def rrInt = Integer.parseInt(colorHex.substring(1,3),16)
|
||||
def ggInt = Integer.parseInt(colorHex.substring(3,5),16)
|
||||
def bbInt = Integer.parseInt(colorHex.substring(5,7),16)
|
||||
|
||||
def colorData = [:]
|
||||
colorData = [r: rrInt, g: ggInt, b: bbInt]
|
||||
colorData
|
||||
}
|
||||
|
||||
def installed() {
|
||||
state.heartbeat = false
|
||||
}
|
||||
|
||||
def updated() {
|
||||
state.heartbeat = false
|
||||
}
|
||||
Reference in New Issue
Block a user