mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-19 13:20:53 +00:00
Compare commits
27 Commits
PROD_2016.
...
MSA-1577-2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0bcde8a1f0 | ||
|
|
9d63d0bbf9 | ||
|
|
385463772b | ||
|
|
284828c42f | ||
|
|
bbdc8faa93 | ||
|
|
48ceadcdb6 | ||
|
|
8e59df0de5 | ||
|
|
d276b80c90 | ||
|
|
8d838ead33 | ||
|
|
bf23f19af5 | ||
|
|
d5bce43a99 | ||
|
|
08c6f143dc | ||
|
|
b6f4581d6d | ||
|
|
a56cad5e03 | ||
|
|
4ed48c8ed4 | ||
|
|
0bfd77745e | ||
|
|
355f641853 | ||
|
|
aba1f48f1f | ||
|
|
9bf39136de | ||
|
|
97fdc03c00 | ||
|
|
8e37b1fce7 | ||
|
|
439dd634bd | ||
|
|
1db5f75ec5 | ||
|
|
7978f45996 | ||
|
|
0ab657d5f2 | ||
|
|
0ae836b023 | ||
|
|
0b4d555d33 |
@@ -1,10 +1,10 @@
|
|||||||
# SmartThings Public Github Repo
|
# SmartThings Public GitHub Repo
|
||||||
|
|
||||||
An official list of SmartApps and Device Types from SmartThings.
|
An official list of SmartApps and Device Types from SmartThings.
|
||||||
|
|
||||||
Here are some links to help you get started coding right away:
|
Here are some links to help you get started coding right away:
|
||||||
|
|
||||||
* [Github-specific Documentation](http://docs.smartthings.com/en/latest/tools-and-ide/github-integration.html)
|
* [GitHub-specific Documentation](http://docs.smartthings.com/en/latest/tools-and-ide/github-integration.html)
|
||||||
* [Full Documentation](http://docs.smartthings.com)
|
* [Full Documentation](http://docs.smartthings.com)
|
||||||
* [IDE & Simulator](http://ide.smartthings.com)
|
* [IDE & Simulator](http://ide.smartthings.com)
|
||||||
* [Community Forums](http://community.smartthings.com)
|
* [Community Forums](http://community.smartthings.com)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ metadata {
|
|||||||
definition (name: "Aeon Key Fob", namespace: "smartthings", author: "SmartThings") {
|
definition (name: "Aeon Key Fob", namespace: "smartthings", author: "SmartThings") {
|
||||||
capability "Actuator"
|
capability "Actuator"
|
||||||
capability "Button"
|
capability "Button"
|
||||||
|
capability "Holdable Button"
|
||||||
capability "Configuration"
|
capability "Configuration"
|
||||||
capability "Sensor"
|
capability "Sensor"
|
||||||
capability "Battery"
|
capability "Battery"
|
||||||
@@ -118,3 +119,7 @@ def configure() {
|
|||||||
log.debug("Sending configuration: $cmd")
|
log.debug("Sending configuration: $cmd")
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def updated() {
|
||||||
|
sendEvent(name: "numberOfButtons", value: 4)
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ metadata {
|
|||||||
definition (name: "Aeon Minimote", namespace: "smartthings", author: "SmartThings") {
|
definition (name: "Aeon Minimote", namespace: "smartthings", author: "SmartThings") {
|
||||||
capability "Actuator"
|
capability "Actuator"
|
||||||
capability "Button"
|
capability "Button"
|
||||||
|
capability "Holdable Button"
|
||||||
capability "Configuration"
|
capability "Configuration"
|
||||||
capability "Sensor"
|
capability "Sensor"
|
||||||
|
|
||||||
@@ -107,3 +108,7 @@ def configure() {
|
|||||||
log.debug("Sending configuration: $cmds")
|
log.debug("Sending configuration: $cmds")
|
||||||
return cmds
|
return cmds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def updated() {
|
||||||
|
sendEvent(name: "numberOfButtons", value: 4)
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ metadata {
|
|||||||
capability "Switch"
|
capability "Switch"
|
||||||
capability "Switch Level"
|
capability "Switch Level"
|
||||||
capability "Button"
|
capability "Button"
|
||||||
capability "Actuator"
|
capability "Actuator"
|
||||||
|
|
||||||
//fingerprint deviceId: "0x1200", inClusters: "0x77 0x86 0x75 0x73 0x85 0x72 0xEF", outClusters: "0x26"
|
//fingerprint deviceId: "0x1200", inClusters: "0x77 0x86 0x75 0x73 0x85 0x72 0xEF", outClusters: "0x26"
|
||||||
}
|
}
|
||||||
@@ -182,3 +182,7 @@ def updateState(String name, String value) {
|
|||||||
state[name] = value
|
state[name] = value
|
||||||
device.updateDataValue(name, value)
|
device.updateDataValue(name, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def updated() {
|
||||||
|
sendEvent(name: "numberOfButtons", value: 3)
|
||||||
|
}
|
||||||
|
|||||||
@@ -236,17 +236,17 @@ def refresh() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void indicatorWhenOn() {
|
void indicatorWhenOn() {
|
||||||
sendEvent(name: "indicatorStatus", value: "when on", display: false)
|
sendEvent(name: "indicatorStatus", value: "when on", displayed: false)
|
||||||
sendHubCommand(new physicalgraph.device.HubAction(zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 3, size: 1).format()))
|
sendHubCommand(new physicalgraph.device.HubAction(zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 3, size: 1).format()))
|
||||||
}
|
}
|
||||||
|
|
||||||
void indicatorWhenOff() {
|
void indicatorWhenOff() {
|
||||||
sendEvent(name: "indicatorStatus", value: "when off", display: false)
|
sendEvent(name: "indicatorStatus", value: "when off", displayed: false)
|
||||||
sendHubCommand(new physicalgraph.device.HubAction(zwave.configurationV1.configurationSet(configurationValue: [0], parameterNumber: 3, size: 1).format()))
|
sendHubCommand(new physicalgraph.device.HubAction(zwave.configurationV1.configurationSet(configurationValue: [0], parameterNumber: 3, size: 1).format()))
|
||||||
}
|
}
|
||||||
|
|
||||||
void indicatorNever() {
|
void indicatorNever() {
|
||||||
sendEvent(name: "indicatorStatus", value: "never", display: false)
|
sendEvent(name: "indicatorStatus", value: "never", displayed: false)
|
||||||
sendHubCommand(new physicalgraph.device.HubAction(zwave.configurationV1.configurationSet(configurationValue: [2], parameterNumber: 3, size: 1).format()))
|
sendHubCommand(new physicalgraph.device.HubAction(zwave.configurationV1.configurationSet(configurationValue: [2], parameterNumber: 3, size: 1).format()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -546,7 +546,7 @@ def zwaveEvent(physicalgraph.zwave.commands.configurationv1.ConfigurationReport
|
|||||||
def value = "when off"
|
def value = "when off"
|
||||||
if (cmd.configurationValue[0] == 1) {value = "when on"}
|
if (cmd.configurationValue[0] == 1) {value = "when on"}
|
||||||
if (cmd.configurationValue[0] == 2) {value = "never"}
|
if (cmd.configurationValue[0] == 2) {value = "never"}
|
||||||
[name: "indicatorStatus", value: value, display: false]
|
[name: "indicatorStatus", value: value, displayed: false]
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
def createEvent(physicalgraph.zwave.Command cmd, Map map) {
|
def createEvent(physicalgraph.zwave.Command cmd, Map map) {
|
||||||
@@ -829,7 +829,7 @@ def toggleTiles(color) {
|
|||||||
state.colorTiles.each({
|
state.colorTiles.each({
|
||||||
if ( it == color ) {
|
if ( it == color ) {
|
||||||
log.debug "Turning ${it} on"
|
log.debug "Turning ${it} on"
|
||||||
cmds << sendEvent(name: it, value: "on${it}", display: True, descriptionText: "${device.displayName} ${color} is 'ON'", isStateChange: true)
|
cmds << sendEvent(name: it, value: "on${it}", displayed: True, descriptionText: "${device.displayName} ${color} is 'ON'", isStateChange: true)
|
||||||
} else {
|
} else {
|
||||||
//log.debug "Turning ${it} off"
|
//log.debug "Turning ${it} off"
|
||||||
cmds << sendEvent(name: it, value: "off${it}", displayed: false)
|
cmds << sendEvent(name: it, value: "off${it}", displayed: false)
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ def parse(String description) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def push() {
|
def push() {
|
||||||
sendEvent(name: "switch", value: "on", isStateChange: true, display: false)
|
sendEvent(name: "switch", value: "on", isStateChange: true, displayed: false)
|
||||||
sendEvent(name: "switch", value: "off", isStateChange: true, display: false)
|
sendEvent(name: "switch", value: "off", isStateChange: true, displayed: false)
|
||||||
sendEvent(name: "momentary", value: "pushed", isStateChange: true)
|
sendEvent(name: "momentary", value: "pushed", isStateChange: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ metadata {
|
|||||||
definition (name: "Simulated Minimote", namespace: "smartthings/testing", author: "SmartThings") {
|
definition (name: "Simulated Minimote", namespace: "smartthings/testing", author: "SmartThings") {
|
||||||
capability "Actuator"
|
capability "Actuator"
|
||||||
capability "Button"
|
capability "Button"
|
||||||
|
capability "Holdable Button"
|
||||||
capability "Configuration"
|
capability "Configuration"
|
||||||
capability "Sensor"
|
capability "Sensor"
|
||||||
|
|
||||||
@@ -125,3 +126,6 @@ private hold(button) {
|
|||||||
sendEvent(name: "button", value: "held", data: [buttonNumber: button], descriptionText: "$device.displayName button $button was held", isStateChange: true)
|
sendEvent(name: "button", value: "held", data: [buttonNumber: button], descriptionText: "$device.displayName button $button was held", isStateChange: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def updated() {
|
||||||
|
sendEvent(name: "numberOfButtons", value: 4)
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ metadata {
|
|||||||
capability "Actuator"
|
capability "Actuator"
|
||||||
capability "Battery"
|
capability "Battery"
|
||||||
capability "Button"
|
capability "Button"
|
||||||
|
capability "Holdable Button"
|
||||||
capability "Configuration"
|
capability "Configuration"
|
||||||
capability "Refresh"
|
capability "Refresh"
|
||||||
capability "Sensor"
|
capability "Sensor"
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ def zwaveEvent(physicalgraph.zwave.commands.configurationv1.ConfigurationReport
|
|||||||
def value = "when off"
|
def value = "when off"
|
||||||
if (cmd.configurationValue[0] == 1) {value = "when on"}
|
if (cmd.configurationValue[0] == 1) {value = "when on"}
|
||||||
if (cmd.configurationValue[0] == 2) {value = "never"}
|
if (cmd.configurationValue[0] == 2) {value = "never"}
|
||||||
[name: "indicatorStatus", value: value, display: false]
|
[name: "indicatorStatus", value: value, displayed: false]
|
||||||
}
|
}
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.commands.hailv1.Hail cmd) {
|
def zwaveEvent(physicalgraph.zwave.commands.hailv1.Hail cmd) {
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ def zwaveEvent(physicalgraph.zwave.commands.configurationv1.ConfigurationReport
|
|||||||
def value = "when off"
|
def value = "when off"
|
||||||
if (cmd.configurationValue[0] == 1) {value = "when on"}
|
if (cmd.configurationValue[0] == 1) {value = "when on"}
|
||||||
if (cmd.configurationValue[0] == 2) {value = "never"}
|
if (cmd.configurationValue[0] == 2) {value = "never"}
|
||||||
[name: "indicatorStatus", value: value, display: false]
|
[name: "indicatorStatus", value: value, displayed: false]
|
||||||
}
|
}
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.commands.hailv1.Hail cmd) {
|
def zwaveEvent(physicalgraph.zwave.commands.hailv1.Hail cmd) {
|
||||||
@@ -174,17 +174,17 @@ def refresh() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void indicatorWhenOn() {
|
void indicatorWhenOn() {
|
||||||
sendEvent(name: "indicatorStatus", value: "when on", display: false)
|
sendEvent(name: "indicatorStatus", value: "when on", displayed: false)
|
||||||
sendHubCommand(new physicalgraph.device.HubAction(zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 3, size: 1).format()))
|
sendHubCommand(new physicalgraph.device.HubAction(zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 3, size: 1).format()))
|
||||||
}
|
}
|
||||||
|
|
||||||
void indicatorWhenOff() {
|
void indicatorWhenOff() {
|
||||||
sendEvent(name: "indicatorStatus", value: "when off", display: false)
|
sendEvent(name: "indicatorStatus", value: "when off", displayed: false)
|
||||||
sendHubCommand(new physicalgraph.device.HubAction(zwave.configurationV1.configurationSet(configurationValue: [0], parameterNumber: 3, size: 1).format()))
|
sendHubCommand(new physicalgraph.device.HubAction(zwave.configurationV1.configurationSet(configurationValue: [0], parameterNumber: 3, size: 1).format()))
|
||||||
}
|
}
|
||||||
|
|
||||||
void indicatorNever() {
|
void indicatorNever() {
|
||||||
sendEvent(name: "indicatorStatus", value: "never", display: false)
|
sendEvent(name: "indicatorStatus", value: "never", displayed: false)
|
||||||
sendHubCommand(new physicalgraph.device.HubAction(zwave.configurationV1.configurationSet(configurationValue: [2], parameterNumber: 3, size: 1).format()))
|
sendHubCommand(new physicalgraph.device.HubAction(zwave.configurationV1.configurationSet(configurationValue: [2], parameterNumber: 3, size: 1).format()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
/**
|
/**
|
||||||
* Color Coordinator
|
* Color Coordinator
|
||||||
* Version 1.0.0 - 7/4/15
|
* Version 1.1.0 - 11/9/16
|
||||||
* By Michael Struck
|
* By Michael Struck
|
||||||
*
|
*
|
||||||
* 1.0.0 - Initial release
|
* 1.0.0 - Initial release
|
||||||
|
* 1.1.0 - Fixed issue where master can be part of slaves. This causes a loop that impacts SmartThings.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||||
@@ -31,27 +32,35 @@ preferences {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def mainPage() {
|
def mainPage() {
|
||||||
dynamicPage(name: "mainPage", title: "", install: true, uninstall: true) {
|
dynamicPage(name: "mainPage", title: "", install: true, uninstall: false) {
|
||||||
section("Master Light") {
|
def masterInList = slaves.id.find{it==master.id}
|
||||||
|
if (masterInList) {
|
||||||
|
section ("**WARNING**"){
|
||||||
|
paragraph "You have included the Master Light in the Slave Group. This will cause a loop in execution. Please remove this device from the Slave Group.", image: "https://raw.githubusercontent.com/MichaelStruck/SmartThingsPublic/master/img/caution.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
section("Master Light") {
|
||||||
input "master", "capability.colorControl", title: "Colored Light"
|
input "master", "capability.colorControl", title: "Colored Light"
|
||||||
}
|
}
|
||||||
section("Lights that follow the master settings") {
|
section("Lights that follow the master settings") {
|
||||||
input "slaves", "capability.colorControl", title: "Colored Lights", multiple: true, required: false
|
input "slaves", "capability.colorControl", title: "Colored Lights", multiple: true, required: false, submitOnChange: true
|
||||||
}
|
}
|
||||||
section([mobileOnly:true], "Options") {
|
section([mobileOnly:true], "Options") {
|
||||||
label(title: "Assign a name", required: false)
|
input "randomYes", "bool",title: "When Master Turned On, Randomize Color", defaultValue: false
|
||||||
href "pageAbout", title: "About ${textAppName()}", description: "Tap to get application version, license and instructions"
|
href "pageAbout", title: "About ${textAppName()}", description: "Tap to get application version, license and instructions"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
page(name: "pageAbout", title: "About ${textAppName()}") {
|
page(name: "pageAbout", title: "About ${textAppName()}", uninstall: true) {
|
||||||
section {
|
section {
|
||||||
paragraph "${textVersion()}\n${textCopyright()}\n\n${textLicense()}\n"
|
paragraph "${textVersion()}\n${textCopyright()}\n\n${textLicense()}\n"
|
||||||
}
|
}
|
||||||
section("Instructions") {
|
section("Instructions") {
|
||||||
paragraph textHelp()
|
paragraph textHelp()
|
||||||
}
|
}
|
||||||
|
section("Tap button below to remove application"){
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def installed() {
|
def installed() {
|
||||||
@@ -72,27 +81,55 @@ def init() {
|
|||||||
}
|
}
|
||||||
//-----------------------------------
|
//-----------------------------------
|
||||||
def onOffHandler(evt){
|
def onOffHandler(evt){
|
||||||
if (master.currentValue("switch") == "on"){
|
if (!slaves.id.find{it==master.id}){
|
||||||
slaves?.on()
|
if (master.currentValue("switch") == "on"){
|
||||||
}
|
if (randomYes) getRandomColorMaster()
|
||||||
else {
|
else slaves?.on()
|
||||||
slaves?.off()
|
}
|
||||||
}
|
else {
|
||||||
|
slaves?.off()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def colorHandler(evt) {
|
def colorHandler(evt) {
|
||||||
def dimLevel = master.currentValue("level")
|
if (!slaves.id.find{it==master.id} && master.currentValue("switch") == "on"){
|
||||||
def hueLevel = master.currentValue("hue")
|
log.debug "Changing Slave units H,S,L"
|
||||||
def saturationLevel = master.currentValue("saturation")
|
def dimLevel = master.currentValue("level")
|
||||||
|
def hueLevel = master.currentValue("hue")
|
||||||
|
def saturationLevel = master.currentValue("saturation")
|
||||||
|
def newValue = [hue: hueLevel, saturation: saturationLevel, level: dimLevel as Integer]
|
||||||
|
slaves?.setColor(newValue)
|
||||||
|
try {
|
||||||
|
log.debug "Changing Slave color temp"
|
||||||
|
def tempLevel = master.currentValue("colorTemperature")
|
||||||
|
slaves?.setColorTemperature(tempLevel)
|
||||||
|
}
|
||||||
|
catch (e){
|
||||||
|
log.debug "Color temp for master --"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def getRandomColorMaster(){
|
||||||
|
def hueLevel = Math.floor(Math.random() *1000)
|
||||||
|
def saturationLevel = Math.floor(Math.random() * 100)
|
||||||
|
def dimLevel = master.currentValue("level")
|
||||||
def newValue = [hue: hueLevel, saturation: saturationLevel, level: dimLevel as Integer]
|
def newValue = [hue: hueLevel, saturation: saturationLevel, level: dimLevel as Integer]
|
||||||
|
log.debug hueLevel
|
||||||
|
log.debug saturationLevel
|
||||||
|
master.setColor(newValue)
|
||||||
slaves?.setColor(newValue)
|
slaves?.setColor(newValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
def tempHandler(evt){
|
def tempHandler(evt){
|
||||||
if (evt.value != "--") {
|
if (!slaves.id.find{it==master.id} && master.currentValue("switch") == "on"){
|
||||||
def tempLevel = master.currentValue("colorTemperature")
|
if (evt.value != "--") {
|
||||||
slaves?.setColorTemperature(tempLevel)
|
log.debug "Changing Slave color temp based on Master change"
|
||||||
}
|
def tempLevel = master.currentValue("colorTemperature")
|
||||||
|
slaves?.setColorTemperature(tempLevel)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Version/Copyright/Information/Help
|
//Version/Copyright/Information/Help
|
||||||
@@ -102,11 +139,11 @@ private def textAppName() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private def textVersion() {
|
private def textVersion() {
|
||||||
def text = "Version 1.0.0 (07/04/2015)"
|
def text = "Version 1.1.0 (11/09/2016)"
|
||||||
}
|
}
|
||||||
|
|
||||||
private def textCopyright() {
|
private def textCopyright() {
|
||||||
def text = "Copyright © 2015 Michael Struck"
|
def text = "Copyright © 2016 Michael Struck"
|
||||||
}
|
}
|
||||||
|
|
||||||
private def textLicense() {
|
private def textLicense() {
|
||||||
@@ -128,5 +165,5 @@ private def textHelp() {
|
|||||||
def text =
|
def text =
|
||||||
"This application will allow you to control the settings of multiple colored lights with one control. " +
|
"This application will allow you to control the settings of multiple colored lights with one control. " +
|
||||||
"Simply choose a master control light, and then choose the lights that will follow the settings of the master, "+
|
"Simply choose a master control light, and then choose the lights that will follow the settings of the master, "+
|
||||||
"including on/off conditions, hue, saturation, level and color temperature."
|
"including on/off conditions, hue, saturation, level and color temperature. Also includes a random color feature."
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,662 @@
|
|||||||
|
import javax.crypto.Mac;
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
import java.security.InvalidKeyException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OpenT2T SmartApp Test
|
||||||
|
*
|
||||||
|
* Copyright 2016 OpenT2T
|
||||||
|
*
|
||||||
|
* 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: "OpenT2T SmartApp Test",
|
||||||
|
namespace: "opent2t",
|
||||||
|
author: "OpenT2T",
|
||||||
|
description: "Test app to test end to end SmartThings scenarios via OpenT2T",
|
||||||
|
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")
|
||||||
|
|
||||||
|
/** --------------------+---------------+-----------------------+------------------------------------
|
||||||
|
* Device Type | Attribute Name| Commands | Attribute Values
|
||||||
|
* --------------------+---------------+-----------------------+------------------------------------
|
||||||
|
* switches | switch | on, off | on, off
|
||||||
|
* motionSensors | motion | | active, inactive
|
||||||
|
* contactSensors | contact | | open, closed
|
||||||
|
* presenceSensors | presence | | present, 'not present'
|
||||||
|
* temperatureSensors | temperature | | <numeric, F or C according to unit>
|
||||||
|
* accelerationSensors | acceleration | | active, inactive
|
||||||
|
* waterSensors | water | | wet, dry
|
||||||
|
* lightSensors | illuminance | | <numeric, lux>
|
||||||
|
* humiditySensors | humidity | | <numeric, percent>
|
||||||
|
* locks | lock | lock, unlock | locked, unlocked
|
||||||
|
* garageDoors | door | open, close | unknown, closed, open, closing, opening
|
||||||
|
* cameras | image | take | <String>
|
||||||
|
* thermostats | thermostat | setHeatingSetpoint, | temperature, heatingSetpoint, coolingSetpoint,
|
||||||
|
* | | setCoolingSetpoint, | thermostatSetpoint, thermostatMode,
|
||||||
|
* | | off, heat, cool, auto,| thermostatFanMode, thermostatOperatingState
|
||||||
|
* | | emergencyHeat, |
|
||||||
|
* | | setThermostatMode, |
|
||||||
|
* | | fanOn, fanAuto, |
|
||||||
|
* | | fanCirculate, |
|
||||||
|
* | | setThermostatFanMode |
|
||||||
|
* --------------------+---------------+-----------------------+------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Device Inputs
|
||||||
|
preferences {
|
||||||
|
section("Allow OpenT2T to control these things...") {
|
||||||
|
input "contactSensors", "capability.contactSensor", title: "Which Contact Sensors", multiple: true, required: false, hideWhenEmpty: true
|
||||||
|
input "garageDoors", "capability.garageDoorControl", title: "Which Garage Doors?", multiple: true, required: false, hideWhenEmpty: true
|
||||||
|
input "locks", "capability.lock", title: "Which Locks?", multiple: true, required: false, hideWhenEmpty: true
|
||||||
|
input "cameras", "capability.videoCapture", title: "Which Cameras?", multiple: true, required: false, hideWhenEmpty: true
|
||||||
|
input "motionSensors", "capability.motionSensor", title: "Which Motion Sensors?", multiple: true, required: false, hideWhenEmpty: true
|
||||||
|
input "presenceSensors", "capability.presenceSensor", title: "Which Presence Sensors", multiple: true, required: false, hideWhenEmpty: true
|
||||||
|
input "switches", "capability.switch", title: "Which Switches and Lights?", multiple: true, required: false, hideWhenEmpty: true
|
||||||
|
input "thermostats", "capability.thermostat", title: "Which Thermostat?", multiple: true, required: false, hideWhenEmpty: true
|
||||||
|
input "waterSensors", "capability.waterSensor", title: "Which Water Leak Sensors?", multiple: true, required: false, hideWhenEmpty: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def getInputs() {
|
||||||
|
def inputList = []
|
||||||
|
inputList += contactSensors?: []
|
||||||
|
inputList += garageDoors?: []
|
||||||
|
inputList += locks?: []
|
||||||
|
inputList += cameras?: []
|
||||||
|
inputList += motionSensors?: []
|
||||||
|
inputList += presenceSensors?: []
|
||||||
|
inputList += switches?: []
|
||||||
|
inputList += thermostats?: []
|
||||||
|
inputList += waterSensors?: []
|
||||||
|
return inputList
|
||||||
|
}
|
||||||
|
|
||||||
|
//API external Endpoints
|
||||||
|
mappings {
|
||||||
|
path("/devices") {
|
||||||
|
action: [
|
||||||
|
GET: "getDevices"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/devices/:id") {
|
||||||
|
action: [
|
||||||
|
GET: "getDevice"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/update/:id") {
|
||||||
|
action: [
|
||||||
|
PUT: "updateDevice"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/deviceSubscription") {
|
||||||
|
action: [
|
||||||
|
POST: "registerDeviceChange",
|
||||||
|
DELETE: "unregisterDeviceChange"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/locationSubscription") {
|
||||||
|
action: [
|
||||||
|
POST: "registerDeviceGraph",
|
||||||
|
DELETE: "unregisterDeviceGraph"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def installed() {
|
||||||
|
log.debug "Installing with settings: ${settings}"
|
||||||
|
initialize()
|
||||||
|
}
|
||||||
|
|
||||||
|
def updated() {
|
||||||
|
log.debug "Updating with settings: ${settings}"
|
||||||
|
|
||||||
|
//Initialize state variables if didn't exist.
|
||||||
|
if( state.deviceSubscriptionMap == null ){
|
||||||
|
state.deviceSubscriptionMap = [:]
|
||||||
|
log.debug "deviceSubscriptionMap created."
|
||||||
|
}
|
||||||
|
if( state.locationSubscriptionMap == null ){
|
||||||
|
state.locationSubscriptionMap = [:]
|
||||||
|
log.debug "locationSubscriptionMap created."
|
||||||
|
}
|
||||||
|
if(state.verificationKeyMap == null){
|
||||||
|
state.verificationKeyMap = [:]
|
||||||
|
log.debug "verificationKeyMap created."
|
||||||
|
}
|
||||||
|
|
||||||
|
unsubscribe()
|
||||||
|
registerAllDeviceSubscriptions()
|
||||||
|
}
|
||||||
|
|
||||||
|
def initialize() {
|
||||||
|
log.debug "Initializing with settings: ${settings}"
|
||||||
|
state.deviceSubscriptionMap = [:]
|
||||||
|
log.debug "deviceSubscriptionMap created."
|
||||||
|
state.locationSubscriptionMap = [:]
|
||||||
|
log.debug "locationSubscriptionMap created."
|
||||||
|
state.verificationKeyMap = [:]
|
||||||
|
log.debug "verificationKeyMap created."
|
||||||
|
registerAllDeviceSubscriptions()
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** Subscription Functions ***/
|
||||||
|
|
||||||
|
//Subscribe events for all devices
|
||||||
|
def registerAllDeviceSubscriptions() {
|
||||||
|
registerChangeHandler(inputs)
|
||||||
|
}
|
||||||
|
|
||||||
|
//Subscribe to events from a list of devices
|
||||||
|
def registerChangeHandler(myList) {
|
||||||
|
myList.each { myDevice ->
|
||||||
|
def theAtts = myDevice.supportedAttributes
|
||||||
|
theAtts.each {att ->
|
||||||
|
subscribe(myDevice, att.name, deviceEventHandler)
|
||||||
|
log.info "Registering for ${myDevice.displayName}.${att.name}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Endpoints function: Subscribe to events from a specific device
|
||||||
|
def registerDeviceChange() {
|
||||||
|
def subscriptionEndpt = params.subscriptionURL
|
||||||
|
def deviceId = params.deviceId
|
||||||
|
def myDevice = findDevice(deviceId)
|
||||||
|
|
||||||
|
if( myDevice == null ){
|
||||||
|
httpError(404, "Cannot find device with device ID ${deviceId}.")
|
||||||
|
}
|
||||||
|
|
||||||
|
def theAtts = myDevice.supportedAttributes
|
||||||
|
try {
|
||||||
|
theAtts.each {att ->
|
||||||
|
subscribe(myDevice, att.name, deviceEventHandler)
|
||||||
|
}
|
||||||
|
log.info "Subscribing for ${myDevice.displayName}"
|
||||||
|
|
||||||
|
if(subscriptionEndpt != null){
|
||||||
|
if(state.deviceSubscriptionMap[deviceId] == null){
|
||||||
|
state.deviceSubscriptionMap.put(deviceId, [subscriptionEndpt])
|
||||||
|
log.info "Added subscription URL: ${subscriptionEndpt} for ${myDevice.displayName}"
|
||||||
|
} else if (!state.deviceSubscriptionMap[deviceId].contains(subscriptionEndpt)){
|
||||||
|
// state.deviceSubscriptionMap[deviceId] << subscriptionEndpt
|
||||||
|
// For now, we will only have one subscription endpoint per device
|
||||||
|
state.deviceSubscriptionMap.remove(deviceId)
|
||||||
|
state.deviceSubscriptionMap.put(deviceId, [subscriptionEndpt])
|
||||||
|
log.info "Added subscription URL: ${subscriptionEndpt} for ${myDevice.displayName}"
|
||||||
|
}
|
||||||
|
|
||||||
|
if(params.key != null){
|
||||||
|
state.verificationKeyMap[subscriptionEndpt] = params.key
|
||||||
|
log.info "Added verification key: ${params.key} for ${subscriptionEndpt}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
httpError(500, "something went wrong: $e")
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info "Current subscription map is ${state.deviceSubscriptionMap}"
|
||||||
|
log.info "Current verification key map is ${state.verificationKeyMap}"
|
||||||
|
return ["succeed"]
|
||||||
|
}
|
||||||
|
|
||||||
|
//Endpoints function: Unsubscribe to events from a specific device
|
||||||
|
def unregisterDeviceChange() {
|
||||||
|
def subscriptionEndpt = params.subscriptionURL
|
||||||
|
def deviceId = params.deviceId
|
||||||
|
def myDevice = findDevice(deviceId)
|
||||||
|
|
||||||
|
if( myDevice == null ){
|
||||||
|
httpError(404, "Cannot find device with device ID ${deviceId}.")
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if(subscriptionEndpt != null && subscriptionEndpt != "undefined"){
|
||||||
|
if (state.deviceSubscriptionMap[deviceId]?.contains(subscriptionEndpt)){
|
||||||
|
if(state.deviceSubscriptionMap[deviceId].size() == 1){
|
||||||
|
state.deviceSubscriptionMap.remove(deviceId)
|
||||||
|
} else {
|
||||||
|
state.deviceSubscriptionMap[deviceId].remove(subscriptionEndpt)
|
||||||
|
}
|
||||||
|
state.verificationKeyMap.remove(subscriptionEndpt)
|
||||||
|
log.info "Removed subscription URL: ${subscriptionEndpt} for ${myDevice.displayName}"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
state.deviceSubscriptionMap.remove(deviceId)
|
||||||
|
log.info "Unsubscriping for ${myDevice.displayName}"
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
httpError(500, "something went wrong: $e")
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info "Current subscription map is ${state.deviceSubscriptionMap}"
|
||||||
|
log.info "Current verification key map is ${state.verificationKeyMap}"
|
||||||
|
}
|
||||||
|
|
||||||
|
//Endpoints function: Subscribe to device additiona/removal updated in a location
|
||||||
|
def registerDeviceGraph() {
|
||||||
|
def subscriptionEndpt = params.subscriptionURL
|
||||||
|
|
||||||
|
if (subscriptionEndpt != null && subscriptionEndpt != "undefined"){
|
||||||
|
subscribe(location, "DeviceCreated", locationEventHandler, [filterEvents: false])
|
||||||
|
subscribe(location, "DeviceUpdated", locationEventHandler, [filterEvents: false])
|
||||||
|
subscribe(location, "DeviceDeleted", locationEventHandler, [filterEvents: false])
|
||||||
|
|
||||||
|
if(state.locationSubscriptionMap[location.id] == null){
|
||||||
|
state.locationSubscriptionMap.put(location.id, [subscriptionEndpt])
|
||||||
|
log.info "Added subscription URL: ${subscriptionEndpt} for Location ${location.name}"
|
||||||
|
}else if (!state.locationSubscriptionMap[location.id].contains(subscriptionEndpt)){
|
||||||
|
state.locationSubscriptionMap[location.id] << subscriptionEndpt
|
||||||
|
log.info "Added subscription URL: ${subscriptionEndpt} for Location ${location.name}"
|
||||||
|
}
|
||||||
|
|
||||||
|
if(params.key != null){
|
||||||
|
state.verificationKeyMap[subscriptionEndpt] = params.key
|
||||||
|
log.info "Added verification key: ${params.key} for ${subscriptionEndpt}"
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info "Current location subscription map is ${state.locationSubscriptionMap}"
|
||||||
|
log.info "Current verification key map is ${state.verificationKeyMap}"
|
||||||
|
return ["succeed"]
|
||||||
|
} else {
|
||||||
|
httpError(400, "missing input parameter: subscriptionURL")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Endpoints function: Unsubscribe to events from a specific device
|
||||||
|
def unregisterDeviceGraph() {
|
||||||
|
def subscriptionEndpt = params.subscriptionURL
|
||||||
|
|
||||||
|
try {
|
||||||
|
if(subscriptionEndpt != null && subscriptionEndpt != "undefined"){
|
||||||
|
if (state.locationSubscriptionMap[location.id]?.contains(subscriptionEndpt)){
|
||||||
|
if(state.locationSubscriptionMap[location.id].size() == 1){
|
||||||
|
state.locationSubscriptionMap.remove(location.id)
|
||||||
|
} else {
|
||||||
|
state.locationSubscriptionMap[location.id].remove(subscriptionEndpt)
|
||||||
|
}
|
||||||
|
state.verificationKeyMap.remove(subscriptionEndpt)
|
||||||
|
log.info "Removed subscription URL: ${subscriptionEndpt} for Location ${location.name}"
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
httpError(400, "missing input parameter: subscriptionURL")
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
httpError(500, "something went wrong: $e")
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info "Current location subscription map is ${state.locationSubscriptionMap}"
|
||||||
|
log.info "Current verification key map is ${state.verificationKeyMap}"
|
||||||
|
}
|
||||||
|
|
||||||
|
//When events are triggered, send HTTP post to web socket servers
|
||||||
|
def deviceEventHandler(evt) {
|
||||||
|
def evtDevice = evt.device
|
||||||
|
def evtDeviceType = getDeviceType(evtDevice)
|
||||||
|
def deviceData = [];
|
||||||
|
|
||||||
|
if(evt.data != null){
|
||||||
|
def evtData = parseJson(evt.data)
|
||||||
|
log.info "Received event for ${evtDevice.displayName}, data: ${evtData}, description: ${evt.descriptionText}"
|
||||||
|
}
|
||||||
|
|
||||||
|
if(evtDeviceType == "thermostat") {
|
||||||
|
deviceData = [name: evtDevice.displayName, id: evtDevice.id, status:evtDevice.status, deviceType:evtDeviceType, manufacturer:evtDevice.manufacturerName, model:evtDevice.modelName, attributes: deviceAttributeList(evtDevice, evtDeviceType), locationMode: getLocationModeInfo(), locationId: location.id ]
|
||||||
|
} else {
|
||||||
|
deviceData = [name: evtDevice.displayName, id: evtDevice.id, status:evtDevice.status, deviceType:evtDeviceType, manufacturer:evtDevice.manufacturerName, model:evtDevice.modelName, attributes: deviceAttributeList(evtDevice, evtDeviceType), locationId: location.id ]
|
||||||
|
}
|
||||||
|
|
||||||
|
def params = [ body: deviceData ]
|
||||||
|
|
||||||
|
//send event to all subscriptions urls
|
||||||
|
log.debug "Current subscription urls for ${evtDevice.displayName} is ${state.deviceSubscriptionMap[evtDevice.id]}"
|
||||||
|
state.deviceSubscriptionMap[evtDevice.id].each {
|
||||||
|
params.uri = "${it}"
|
||||||
|
if(state.verificationKeyMap[it] != null ){
|
||||||
|
def key = state.verificationKeyMap[it]
|
||||||
|
params.header = [Signature: ComputHMACValue(key, groovy.json.JsonOutput.toJson(params.body))]
|
||||||
|
}
|
||||||
|
log.trace "POST URI: ${params.uri}"
|
||||||
|
log.trace "Header: ${params.header}"
|
||||||
|
log.trace "Payload: ${params.body}"
|
||||||
|
try{
|
||||||
|
httpPostJson(params) { resp ->
|
||||||
|
log.trace "response status code: ${resp.status}"
|
||||||
|
log.trace "response data: ${resp.data}"
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.error "something went wrong: $e"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def locationEventHandler(evt) {
|
||||||
|
log.info "Received event for location ${location.name}/${location.id}, Event: ${evt.name}, description: ${evt.descriptionText}, apiServerUrl: ${apiServerUrl("")}"
|
||||||
|
switch(evt.name){
|
||||||
|
case "DeviceCreated":
|
||||||
|
case "DeviceDeleted":
|
||||||
|
def evtDevice = evt.device
|
||||||
|
def evtDeviceType = getDeviceType(evtDevice)
|
||||||
|
def params = [ body: [ eventType:evt.name, deviceId: evtDevice.id, locationId: location.id ] ]
|
||||||
|
|
||||||
|
if (evt.name == "DeviceDeleted" && state.deviceSubscriptionMap[deviceId] != null){
|
||||||
|
state.deviceSubscriptionMap.remove(evtDevice.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
state.locationSubscriptionMap[location.id].each {
|
||||||
|
params.uri = "${it}"
|
||||||
|
if(state.verificationKeyMap[it] != null ){
|
||||||
|
def key = state.verificationKeyMap[it]
|
||||||
|
params.header = [Signature: ComputHMACValue(key, groovy.json.JsonOutput.toJson(params.body))]
|
||||||
|
}
|
||||||
|
log.trace "POST URI: ${params.uri}"
|
||||||
|
log.trace "Header: ${params.header}"
|
||||||
|
log.trace "Payload: ${params.body}"
|
||||||
|
try{
|
||||||
|
httpPostJson(params) { resp ->
|
||||||
|
log.trace "response status code: ${resp.status}"
|
||||||
|
log.trace "response data: ${resp.data}"
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.error "something went wrong: $e"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "DeviceUpdated":
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ComputHMACValue(key, data){
|
||||||
|
try {
|
||||||
|
SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA1")
|
||||||
|
Mac mac = Mac.getInstance("HmacSHA1")
|
||||||
|
mac.init(secretKeySpec)
|
||||||
|
byte[] digest = mac.doFinal(data.getBytes("UTF-8"))
|
||||||
|
return byteArrayToString(digest)
|
||||||
|
} catch (InvalidKeyException e) {
|
||||||
|
log.error "Invalid key exception while converting to HMac SHA1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private def byteArrayToString(byte[] data) {
|
||||||
|
BigInteger bigInteger = new BigInteger(1, data)
|
||||||
|
String hash = bigInteger.toString(16)
|
||||||
|
return hash
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** Device Query/Update Functions ***/
|
||||||
|
|
||||||
|
//Endpoints function: return all device data in json format
|
||||||
|
def getDevices() {
|
||||||
|
def deviceData = []
|
||||||
|
inputs?.each {
|
||||||
|
def deviceType = getDeviceType(it)
|
||||||
|
if(deviceType == "thermostat") {
|
||||||
|
deviceData << [name: it.displayName, id: it.id, status:it.status, deviceType:deviceType, manufacturer:it.manufacturerName, model:it.modelName, attributes: deviceAttributeList(it, deviceType), locationMode: getLocationModeInfo()]
|
||||||
|
} else {
|
||||||
|
deviceData << [name: it.displayName, id: it.id, status:it.status, deviceType:deviceType, manufacturer:it.manufacturerName, model:it.modelName, attributes: deviceAttributeList(it, deviceType)]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug "getDevices, return: ${deviceData}"
|
||||||
|
return deviceData
|
||||||
|
}
|
||||||
|
|
||||||
|
//Endpoints function: get device data
|
||||||
|
def getDevice() {
|
||||||
|
def it = findDevice(params.id)
|
||||||
|
def deviceType = getDeviceType(it)
|
||||||
|
def device
|
||||||
|
if(deviceType == "thermostat") {
|
||||||
|
device = [name: it.displayName, id: it.id, status:it.status, deviceType:deviceType, manufacturer:it.manufacturerName, model:it.modelName, attributes: deviceAttributeList(it,deviceType), locationMode: getLocationModeInfo()]
|
||||||
|
} else {
|
||||||
|
device = [name: it.displayName, id: it.id, status:it.status, deviceType:deviceType, manufacturer:it.manufacturerName, model:it.modelName, attributes: deviceAttributeList(it, deviceType)]
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug "getDevice, return: ${device}"
|
||||||
|
return device
|
||||||
|
}
|
||||||
|
|
||||||
|
//Endpoints function: update device data
|
||||||
|
void updateDevice() {
|
||||||
|
def device = findDevice(params.id)
|
||||||
|
request.JSON.each {
|
||||||
|
def command = it.key
|
||||||
|
def value = it.value
|
||||||
|
if (command){
|
||||||
|
def commandList = mapDeviceCommands(command, value)
|
||||||
|
command = commandList[0]
|
||||||
|
value = commandList[1]
|
||||||
|
|
||||||
|
if (command == "setAwayMode") {
|
||||||
|
log.info "Setting away mode to ${value}"
|
||||||
|
if (location.modes?.find {it.name == value}) {
|
||||||
|
location.setMode(value)
|
||||||
|
}
|
||||||
|
}else if (command == "thermostatSetpoint"){
|
||||||
|
switch(device.currentThermostatMode){
|
||||||
|
case "cool":
|
||||||
|
log.info "Update: ${device.displayName}, [${command}, ${value}]"
|
||||||
|
device.setCoolingSetpoint(value)
|
||||||
|
break
|
||||||
|
case "heat":
|
||||||
|
case "emergency heat":
|
||||||
|
log.info "Update: ${device.displayName}, [${command}, ${value}]"
|
||||||
|
device.setHeatingSetpoint(value)
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
httpError(501, "this mode: ${device.currentThermostatMode} does not allow changing thermostat setpoint.")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}else if (!device) {
|
||||||
|
log.error "updateDevice, Device not found"
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else if (!device.hasCommand(command)) {
|
||||||
|
log.error "updateDevice, Device does not have the command"
|
||||||
|
httpError(404, "Device does not have such command")
|
||||||
|
} else {
|
||||||
|
if (command == "setColor") {
|
||||||
|
log.info "Update: ${device.displayName}, [${command}, ${value}]"
|
||||||
|
device."$command"(hex: value)
|
||||||
|
} else if(value.isNumber()) {
|
||||||
|
def intValue = value as Integer
|
||||||
|
log.info "Update: ${device.displayName}, [${command}, ${intValue}(int)]"
|
||||||
|
device."$command"(intValue)
|
||||||
|
} else if (value){
|
||||||
|
log.info "Update: ${device.displayName}, [${command}, ${value}]"
|
||||||
|
device."$command"(value)
|
||||||
|
} else {
|
||||||
|
log.info "Update: ${device.displayName}, [${command}]"
|
||||||
|
device."$command"()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** Private Functions ***/
|
||||||
|
|
||||||
|
//Return current location mode info
|
||||||
|
private getLocationModeInfo() {
|
||||||
|
return [mode: location.mode, supported: location.modes.name]
|
||||||
|
}
|
||||||
|
|
||||||
|
//Map each device to a type given it's capabilities
|
||||||
|
private getDeviceType(device) {
|
||||||
|
def deviceType
|
||||||
|
def capabilities = device.capabilities
|
||||||
|
log.debug "capabilities: [${device}, ${capabilities}]"
|
||||||
|
log.debug "supported commands: [${device}, ${device.supportedCommands}]"
|
||||||
|
|
||||||
|
//Loop through the device capability list to determine the device type.
|
||||||
|
capabilities.each {capability ->
|
||||||
|
switch(capability.name.toLowerCase())
|
||||||
|
{
|
||||||
|
case "switch":
|
||||||
|
deviceType = "switch"
|
||||||
|
|
||||||
|
//If the device also contains "Switch Level" capability, identify it as a "light" device.
|
||||||
|
if (capabilities.any{it.name.toLowerCase() == "switch level"}){
|
||||||
|
|
||||||
|
//If the device also contains "Power Meter" capability, identify it as a "dimmerSwitch" device.
|
||||||
|
if (capabilities.any{it.name.toLowerCase() == "power meter"}){
|
||||||
|
deviceType = "dimmerSwitch"
|
||||||
|
return deviceType
|
||||||
|
} else {
|
||||||
|
deviceType = "light"
|
||||||
|
return deviceType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case "garageDoorControl":
|
||||||
|
deviceType = "garageDoor"
|
||||||
|
return deviceType
|
||||||
|
case "lock":
|
||||||
|
deviceType = "lock"
|
||||||
|
return deviceType
|
||||||
|
case "video camera":
|
||||||
|
deviceType = "camera"
|
||||||
|
return deviceType
|
||||||
|
case "thermostat":
|
||||||
|
deviceType = "thermostat"
|
||||||
|
return deviceType
|
||||||
|
case "acceleration sensor":
|
||||||
|
case "contact sensor":
|
||||||
|
case "motion sensor":
|
||||||
|
case "presence sensor":
|
||||||
|
case "water sensor":
|
||||||
|
deviceType = "genericSensor"
|
||||||
|
return deviceType
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deviceType
|
||||||
|
}
|
||||||
|
|
||||||
|
//Return a specific device give the device ID.
|
||||||
|
private findDevice(deviceId) {
|
||||||
|
return inputs?.find { it.id == deviceId }
|
||||||
|
}
|
||||||
|
|
||||||
|
//Return a list of device attributes
|
||||||
|
private deviceAttributeList(device, deviceType) {
|
||||||
|
def attributeList = [:]
|
||||||
|
def allAttributes = device.supportedAttributes
|
||||||
|
allAttributes.each { attribute ->
|
||||||
|
try {
|
||||||
|
def currentState = device.currentState(attribute.name)
|
||||||
|
if(currentState != null ){
|
||||||
|
switch(attribute.name){
|
||||||
|
case 'temperature':
|
||||||
|
attributeList.putAll([ (attribute.name): currentState.value, 'temperatureScale':location.temperatureScale ])
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
attributeList.putAll([(attribute.name): currentState.value ])
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if( deviceType == "genericSensor" ){
|
||||||
|
def key = attribute.name + "_lastUpdated"
|
||||||
|
attributeList.putAll([ (key): currentState.isoDate ])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
attributeList.putAll([ (attribute.name): null ]);
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
attributeList.putAll([ (attribute.name): null ]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return attributeList
|
||||||
|
}
|
||||||
|
|
||||||
|
//Map device command and value.
|
||||||
|
//input command and value are from UWP,
|
||||||
|
//returns resultCommand and resultValue that corresponds with function and value in SmartApps
|
||||||
|
private mapDeviceCommands(command, value) {
|
||||||
|
log.debug "mapDeviceCommands: [${command}, ${value}]"
|
||||||
|
def resultCommand = command
|
||||||
|
def resultValue = value
|
||||||
|
switch (command) {
|
||||||
|
case "switch":
|
||||||
|
if (value == 1 || value == "1" || value == "on") {
|
||||||
|
resultCommand = "on"
|
||||||
|
resultValue = ""
|
||||||
|
} else if (value == 0 || value == "0" || value == "off") {
|
||||||
|
resultCommand = "off"
|
||||||
|
resultValue = ""
|
||||||
|
}
|
||||||
|
break
|
||||||
|
// light attributes
|
||||||
|
case "level":
|
||||||
|
resultCommand = "setLevel"
|
||||||
|
resultValue = value
|
||||||
|
break
|
||||||
|
case "hue":
|
||||||
|
resultCommand = "setHue"
|
||||||
|
resultValue = value
|
||||||
|
break
|
||||||
|
case "saturation":
|
||||||
|
resultCommand = "setSaturation"
|
||||||
|
resultValue = value
|
||||||
|
break
|
||||||
|
case "colorTemperature":
|
||||||
|
resultCommand = "setColorTemperature"
|
||||||
|
resultValue = value
|
||||||
|
break
|
||||||
|
case "color":
|
||||||
|
resultCommand = "setColor"
|
||||||
|
resultValue = value
|
||||||
|
// thermostat attributes
|
||||||
|
case "hvacMode":
|
||||||
|
resultCommand = "setThermostatMode"
|
||||||
|
resultValue = value
|
||||||
|
break
|
||||||
|
case "fanMode":
|
||||||
|
resultCommand = "setThermostatFanMode"
|
||||||
|
resultValue = value
|
||||||
|
break
|
||||||
|
case "awayMode":
|
||||||
|
resultCommand = "setAwayMode"
|
||||||
|
resultValue = value
|
||||||
|
break
|
||||||
|
case "coolingSetpoint":
|
||||||
|
resultCommand = "setCoolingSetpoint"
|
||||||
|
resultValue = value
|
||||||
|
break
|
||||||
|
case "heatingSetpoint":
|
||||||
|
resultCommand = "setHeatingSetpoint"
|
||||||
|
resultValue = value
|
||||||
|
break
|
||||||
|
case "thermostatSetpoint":
|
||||||
|
resultCommand = "thermostatSetpoint"
|
||||||
|
resultValue = value
|
||||||
|
break
|
||||||
|
// lock attributes
|
||||||
|
case "locked":
|
||||||
|
if (value == 1 || value == "1" || value == "lock") {
|
||||||
|
resultCommand = "lock"
|
||||||
|
resultValue = ""
|
||||||
|
}
|
||||||
|
else if (value == 0 || value == "0" || value == "unlock") {
|
||||||
|
resultCommand = "unlock"
|
||||||
|
resultValue = ""
|
||||||
|
}
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
return [resultCommand,resultValue]
|
||||||
|
}
|
||||||
@@ -516,7 +516,7 @@ def pollResponse(response, data) {
|
|||||||
def hub = getChildDevice("harmony-${it.key}")
|
def hub = getChildDevice("harmony-${it.key}")
|
||||||
if (hub) {
|
if (hub) {
|
||||||
if (it.value.response.data.currentAvActivity == "-1") {
|
if (it.value.response.data.currentAvActivity == "-1") {
|
||||||
hub.sendEvent(name: "currentActivity", value: "--", descriptionText: "There isn't any activity running", display: false)
|
hub.sendEvent(name: "currentActivity", value: "--", descriptionText: "There isn't any activity running", displayed: false)
|
||||||
} else {
|
} else {
|
||||||
def currentActivity
|
def currentActivity
|
||||||
def activityDTH = getChildDevice("harmony-${it.key}-${it.value.response.data.currentAvActivity}")
|
def activityDTH = getChildDevice("harmony-${it.key}-${it.value.response.data.currentAvActivity}")
|
||||||
@@ -524,7 +524,7 @@ def pollResponse(response, data) {
|
|||||||
currentActivity = activityDTH.device.displayName
|
currentActivity = activityDTH.device.displayName
|
||||||
else
|
else
|
||||||
currentActivity = getActivityName(it.value.response.data.currentAvActivity,it.key)
|
currentActivity = getActivityName(it.value.response.data.currentAvActivity,it.key)
|
||||||
hub.sendEvent(name: "currentActivity", value: currentActivity, descriptionText: "Current activity is ${currentActivity}", display: false)
|
hub.sendEvent(name: "currentActivity", value: currentActivity, descriptionText: "Current activity is ${currentActivity}", displayed: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -576,7 +576,7 @@ def getActivityList() {
|
|||||||
}
|
}
|
||||||
activities += [id: "off", name: "Activity OFF", type: "0"]
|
activities += [id: "off", name: "Activity OFF", type: "0"]
|
||||||
}
|
}
|
||||||
hub.sendEvent(name: "activities", value: new groovy.json.JsonBuilder(activities).toString(), descriptionText: "Activities are ${activities.collect { it.name }?.join(', ')}", display: false)
|
hub.sendEvent(name: "activities", value: new groovy.json.JsonBuilder(activities).toString(), descriptionText: "Activities are ${activities.collect { it.name }?.join(', ')}", displayed: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user