mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-20 05:10:51 +00:00
Compare commits
19 Commits
MSA-1306-2
...
MSA-1327-2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce8a629cef | ||
|
|
031a15ec86 | ||
|
|
fc2db2575d | ||
|
|
fd549631e6 | ||
|
|
417c246d61 | ||
|
|
0f1781c02e | ||
|
|
4ce6ee0890 | ||
|
|
f8050a5cd5 | ||
|
|
d44dac448b | ||
|
|
67c20abcba | ||
|
|
d56e132896 | ||
|
|
009ec2539d | ||
|
|
ff0860cbe1 | ||
|
|
ecfb99974b | ||
|
|
c2f18a91be | ||
|
|
0c1208928f | ||
|
|
02d9963fab | ||
|
|
32f0385e30 | ||
|
|
d17cadc4c7 |
@@ -1,294 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2015 SmartThings
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License. You may obtain a copy of the License at:
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
|
||||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
|
||||||
* for the specific language governing permissions and limitations under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
metadata {
|
|
||||||
definition (name: "재부재 센서", namespace: "smartthings", author: "김성훈") {
|
|
||||||
capability "Tone"
|
|
||||||
capability "Actuator"
|
|
||||||
capability "Signal Strength"
|
|
||||||
capability "Presence Sensor"
|
|
||||||
capability "Sensor"
|
|
||||||
capability "Battery"
|
|
||||||
|
|
||||||
fingerprint profileId: "FC01", deviceId: "019A"
|
|
||||||
fingerprint profileId: "FC01", deviceId: "0131", inClusters: "0000,0003", outClusters: "0003"
|
|
||||||
fingerprint profileId: "FC01", deviceId: "0131", inClusters: "0000", outClusters: "0006"
|
|
||||||
}
|
|
||||||
|
|
||||||
simulator {
|
|
||||||
status "present": "presence: 1"
|
|
||||||
status "not present": "presence: 0"
|
|
||||||
status "battery": "battery: 27, batteryDivisor: 0A, rssi: 100, lqi: 64"
|
|
||||||
}
|
|
||||||
|
|
||||||
preferences {
|
|
||||||
section {
|
|
||||||
image(name: 'educationalcontent', multiple: true, images: [
|
|
||||||
"http://cdn.device-gse.smartthings.com/Arrival/Arrival1.jpg",
|
|
||||||
"http://cdn.device-gse.smartthings.com/Arrival/Arrival2.jpg"
|
|
||||||
])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tiles {
|
|
||||||
standardTile("presence", "device.presence", width: 2, height: 2, canChangeBackground: true) {
|
|
||||||
state "present", labelIcon:"st.presence.tile.present", backgroundColor:"#53a7c0"
|
|
||||||
state "not present", labelIcon:"st.presence.tile.not-present", backgroundColor:"#ebeef2"
|
|
||||||
}
|
|
||||||
standardTile("beep", "device.beep", decoration: "flat") {
|
|
||||||
state "beep", label:'', action:"tone.beep", icon:"st.secondary.beep", backgroundColor:"#ffffff"
|
|
||||||
}
|
|
||||||
valueTile("battery", "device.battery", decoration: "flat", inactiveLabel: false) {
|
|
||||||
state "battery", label:'${currentValue}% battery', unit:""/*, backgroundColors:[
|
|
||||||
[value: 5, color: "#BC2323"],
|
|
||||||
[value: 10, color: "#D04E00"],
|
|
||||||
[value: 15, color: "#F1D801"],
|
|
||||||
[value: 16, color: "#FFFFFF"]
|
|
||||||
]*/
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
valueTile("lqi", "device.lqi", decoration: "flat", inactiveLabel: false) {
|
|
||||||
state "lqi", label:'${currentValue}% signal', unit:""
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
main "presence"
|
|
||||||
details(["presence", "beep", "battery"/*, "lqi"*/])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def beep() {
|
|
||||||
/*
|
|
||||||
You can make the speaker turn on for 0.5-second beeps by sending some CLI commands:
|
|
||||||
|
|
||||||
Command: send raw, wait 7, send raw, wait 7, send raw
|
|
||||||
Future: new packet type "st.beep"
|
|
||||||
|
|
||||||
raw 0xFC05 {15 0A 11 00 00 15 01}
|
|
||||||
send 0x2F7F 2 2
|
|
||||||
|
|
||||||
where "0xABCD" is the node ID of the Smart Tag, everything else above is a constant. Except
|
|
||||||
the "15 01" at the end of the first raw command, that sets the speaker's period (reciprocal
|
|
||||||
of frequency). You can play with this value up or down to experiment with loudness as the
|
|
||||||
loudness will be strongly dependent upon frequency and the enclosure that it's in. Note that
|
|
||||||
"15 01" represents the hex number 0x0115 so a lower frequency is "16 01" (longer period) and
|
|
||||||
a higher frequency is "14 01" (shorter period). Note that since the tag only checks its parent
|
|
||||||
for messages every 5 seconds (while at rest) or every 3 seconds (while in motion) it will take
|
|
||||||
up to this long from the time you send the message to the time you hear a sound.
|
|
||||||
*/
|
|
||||||
|
|
||||||
[
|
|
||||||
"raw 0xFC05 {15 0A 11 00 00 15 01}",
|
|
||||||
"delay 7000",
|
|
||||||
"raw 0xFC05 {15 0A 11 00 00 15 01}",
|
|
||||||
"delay 7000",
|
|
||||||
"raw 0xFC05 {15 0A 11 00 00 15 01}",
|
|
||||||
"delay 7000",
|
|
||||||
"raw 0xFC05 {15 0A 11 00 00 15 01}",
|
|
||||||
"delay 7000",
|
|
||||||
"raw 0xFC05 {15 0A 11 00 00 15 01}"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
def parse(String description) {
|
|
||||||
def results
|
|
||||||
if (isBatteryMessage(description)) {
|
|
||||||
results = parseBatteryMessage(description)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
results = parsePresenceMessage(description)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.debug "Parse returned $results.descriptionText"
|
|
||||||
results
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map parsePresenceMessage(String description) {
|
|
||||||
def name = parseName(description)
|
|
||||||
def value = parseValue(description)
|
|
||||||
def linkText = getLinkText(device)
|
|
||||||
def descriptionText = parseDescriptionText(linkText, value, description)
|
|
||||||
def handlerName = getState(value)
|
|
||||||
def isStateChange = isStateChange(device, name, value)
|
|
||||||
|
|
||||||
def results = [
|
|
||||||
name: name,
|
|
||||||
value: value,
|
|
||||||
unit: null,
|
|
||||||
linkText: linkText,
|
|
||||||
descriptionText: descriptionText,
|
|
||||||
handlerName: handlerName,
|
|
||||||
isStateChange: isStateChange,
|
|
||||||
displayed: displayed(description, isStateChange)
|
|
||||||
]
|
|
||||||
|
|
||||||
results
|
|
||||||
}
|
|
||||||
|
|
||||||
private String parseName(String description) {
|
|
||||||
if (description?.startsWith("presence: ")) {
|
|
||||||
return "presence"
|
|
||||||
}
|
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
private String parseValue(String description) {
|
|
||||||
if (description?.startsWith("presence: "))
|
|
||||||
{
|
|
||||||
if (description?.endsWith("1"))
|
|
||||||
{
|
|
||||||
return "present"
|
|
||||||
}
|
|
||||||
else if (description?.endsWith("0"))
|
|
||||||
{
|
|
||||||
return "not present"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
description
|
|
||||||
}
|
|
||||||
|
|
||||||
private parseDescriptionText(String linkText, String value, String description) {
|
|
||||||
switch(value) {
|
|
||||||
case "present": return "$linkText has arrived"
|
|
||||||
case "not present": return "$linkText has left"
|
|
||||||
default: return value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private getState(String value) {
|
|
||||||
def state = value
|
|
||||||
if (value == "present") {
|
|
||||||
state = "arrived"
|
|
||||||
}
|
|
||||||
else if (value == "not present") {
|
|
||||||
state = "left"
|
|
||||||
}
|
|
||||||
|
|
||||||
state
|
|
||||||
}
|
|
||||||
|
|
||||||
private Boolean isBatteryMessage(String description) {
|
|
||||||
// "raw:36EF1C, dni:36EF, battery:1B, rssi:, lqi:"
|
|
||||||
description ==~ /.*battery:.*rssi:.*lqi:.*/
|
|
||||||
}
|
|
||||||
|
|
||||||
private List parseBatteryMessage(String description) {
|
|
||||||
def results = []
|
|
||||||
def parts = description.split(',')
|
|
||||||
parts.each { part ->
|
|
||||||
part = part.trim()
|
|
||||||
if (part.startsWith('battery:')) {
|
|
||||||
def batteryResult = getBatteryResult(part, description)
|
|
||||||
if (batteryResult) {
|
|
||||||
results << batteryResult
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (part.startsWith('rssi:')) {
|
|
||||||
def rssiResult = getRssiResult(part, description)
|
|
||||||
if (rssiResult) {
|
|
||||||
results << rssiResult
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (part.startsWith('lqi:')) {
|
|
||||||
def lqiResult = getLqiResult(part, description)
|
|
||||||
if (lqiResult) {
|
|
||||||
results << lqiResult
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
results
|
|
||||||
}
|
|
||||||
|
|
||||||
private getBatteryResult(part, description) {
|
|
||||||
def batteryDivisor = description.split(",").find {it.split(":")[0].trim() == "batteryDivisor"} ? description.split(",").find {it.split(":")[0].trim() == "batteryDivisor"}.split(":")[1].trim() : null
|
|
||||||
def name = "battery"
|
|
||||||
def value = zigbee.parseSmartThingsBatteryValue(part, batteryDivisor)
|
|
||||||
def unit = "%"
|
|
||||||
def linkText = getLinkText(device)
|
|
||||||
def descriptionText = "$linkText battery was ${value}${unit}"
|
|
||||||
def isStateChange = isStateChange(device, name, value)
|
|
||||||
|
|
||||||
[
|
|
||||||
name: name,
|
|
||||||
value: value,
|
|
||||||
unit: unit,
|
|
||||||
linkText: linkText,
|
|
||||||
descriptionText: descriptionText,
|
|
||||||
handlerName: name,
|
|
||||||
isStateChange: isStateChange,
|
|
||||||
//displayed: displayed(description, isStateChange)
|
|
||||||
displayed: false
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
private getRssiResult(part, description) {
|
|
||||||
def name = "rssi"
|
|
||||||
def parts = part.split(":")
|
|
||||||
if (parts.size() != 2) return null
|
|
||||||
|
|
||||||
def valueString = parts[1].trim()
|
|
||||||
def valueInt = Integer.parseInt(valueString, 16)
|
|
||||||
def value = (valueInt - 128).toString()
|
|
||||||
def linkText = getLinkText(device)
|
|
||||||
def descriptionText = "$linkText was $value dBm"
|
|
||||||
def isStateChange = isStateChange(device, name, value)
|
|
||||||
|
|
||||||
[
|
|
||||||
name: name,
|
|
||||||
value: value,
|
|
||||||
unit: "dBm",
|
|
||||||
linkText: linkText,
|
|
||||||
descriptionText: descriptionText,
|
|
||||||
handlerName: null,
|
|
||||||
isStateChange: isStateChange,
|
|
||||||
//displayed: displayed(description, isStateChange)
|
|
||||||
displayed: false
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use LQI (Link Quality Indicator) as a measure of signal strength. The values
|
|
||||||
* are 0 to 255 (0x00 to 0xFF) and higher values represent higher signal
|
|
||||||
* strength. Return as a percentage of 255.
|
|
||||||
*
|
|
||||||
* Note: To make the signal strength indicator more accurate, we could combine
|
|
||||||
* LQI with RSSI.
|
|
||||||
*/
|
|
||||||
private getLqiResult(part, description) {
|
|
||||||
def name = "lqi"
|
|
||||||
def parts = part.split(":")
|
|
||||||
if (parts.size() != 2) return null
|
|
||||||
|
|
||||||
def valueString = parts[1].trim()
|
|
||||||
def valueInt = Integer.parseInt(valueString, 16)
|
|
||||||
def percentageOf = 255
|
|
||||||
def value = Math.round((valueInt / percentageOf * 100)).toString()
|
|
||||||
def unit = "%"
|
|
||||||
def linkText = getLinkText(device)
|
|
||||||
def descriptionText = "$linkText Signal (LQI) was ${value}${unit}"
|
|
||||||
def isStateChange = isStateChange(device, name, value)
|
|
||||||
|
|
||||||
[
|
|
||||||
name: name,
|
|
||||||
value: value,
|
|
||||||
unit: unit,
|
|
||||||
linkText: linkText,
|
|
||||||
descriptionText: descriptionText,
|
|
||||||
handlerName: null,
|
|
||||||
isStateChange: isStateChange,
|
|
||||||
//displayed: displayed(description, isStateChange)
|
|
||||||
displayed: false
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -21,6 +21,7 @@ metadata {
|
|||||||
attribute "tamper", "enum", ["detected", "clear"]
|
attribute "tamper", "enum", ["detected", "clear"]
|
||||||
attribute "heatAlarm", "enum", ["overheat detected", "clear", "rapid temperature rise", "underheat detected"]
|
attribute "heatAlarm", "enum", ["overheat detected", "clear", "rapid temperature rise", "underheat detected"]
|
||||||
fingerprint deviceId: "0x0701", inClusters: "0x5E, 0x86, 0x72, 0x5A, 0x59, 0x85, 0x73, 0x84, 0x80, 0x71, 0x56, 0x70, 0x31, 0x8E, 0x22, 0x9C, 0x98, 0x7A", outClusters: "0x20, 0x8B"
|
fingerprint deviceId: "0x0701", inClusters: "0x5E, 0x86, 0x72, 0x5A, 0x59, 0x85, 0x73, 0x84, 0x80, 0x71, 0x56, 0x70, 0x31, 0x8E, 0x22, 0x9C, 0x98, 0x7A", outClusters: "0x20, 0x8B"
|
||||||
|
fingerprint mfr:"010F", prod:"0C02", model:"1002"
|
||||||
}
|
}
|
||||||
simulator {
|
simulator {
|
||||||
//battery
|
//battery
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
/**
|
||||||
|
* Hue White Ambiance Bulb
|
||||||
|
*
|
||||||
|
* Philips Hue Type "Color Temperature Light"
|
||||||
|
*
|
||||||
|
* Author: SmartThings
|
||||||
|
*/
|
||||||
|
|
||||||
|
// for the UI
|
||||||
|
metadata {
|
||||||
|
// Automatically generated. Make future change here.
|
||||||
|
definition (name: "Hue White Ambiance Bulb", namespace: "smartthings", author: "SmartThings") {
|
||||||
|
capability "Switch Level"
|
||||||
|
capability "Actuator"
|
||||||
|
capability "Color Temperature"
|
||||||
|
capability "Switch"
|
||||||
|
capability "Refresh"
|
||||||
|
|
||||||
|
command "refresh"
|
||||||
|
}
|
||||||
|
|
||||||
|
simulator {
|
||||||
|
// TODO: define status and reply messages here
|
||||||
|
}
|
||||||
|
|
||||||
|
tiles (scale: 2){
|
||||||
|
multiAttributeTile(name:"rich-control", type: "lighting", width: 6, height: 4, canChangeIcon: true){
|
||||||
|
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
|
||||||
|
attributeState "on", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff"
|
||||||
|
attributeState "off", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn"
|
||||||
|
attributeState "turningOn", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff"
|
||||||
|
attributeState "turningOff", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn"
|
||||||
|
}
|
||||||
|
tileAttribute ("device.level", key: "SLIDER_CONTROL") {
|
||||||
|
attributeState "level", action:"switch level.setLevel", range:"(0..100)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
controlTile("colorTempSliderControl", "device.colorTemperature", "slider", width: 4, height: 2, inactiveLabel: false, range:"(2000..6500)") {
|
||||||
|
state "colorTemperature", action:"color temperature.setColorTemperature"
|
||||||
|
}
|
||||||
|
|
||||||
|
valueTile("colorTemp", "device.colorTemperature", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
|
||||||
|
state "colorTemperature", label: '${currentValue} K'
|
||||||
|
}
|
||||||
|
|
||||||
|
standardTile("refresh", "device.refresh", height: 2, width: 2, inactiveLabel: false, decoration: "flat") {
|
||||||
|
state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
|
||||||
|
}
|
||||||
|
|
||||||
|
main(["rich-control"])
|
||||||
|
details(["rich-control", "colorTempSliderControl", "colorTemp", "refresh"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse events into attributes
|
||||||
|
def parse(description) {
|
||||||
|
log.debug "parse() - $description"
|
||||||
|
def results = []
|
||||||
|
|
||||||
|
def map = description
|
||||||
|
if (description instanceof String) {
|
||||||
|
log.debug "Hue Ambience Bulb stringToMap - ${map}"
|
||||||
|
map = stringToMap(description)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (map?.name && map?.value) {
|
||||||
|
results << createEvent(name: "${map?.name}", value: "${map?.value}")
|
||||||
|
}
|
||||||
|
results
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle commands
|
||||||
|
void on() {
|
||||||
|
log.trace parent.on(this)
|
||||||
|
sendEvent(name: "switch", value: "on")
|
||||||
|
}
|
||||||
|
|
||||||
|
void off() {
|
||||||
|
log.trace parent.off(this)
|
||||||
|
sendEvent(name: "switch", value: "off")
|
||||||
|
}
|
||||||
|
|
||||||
|
void setLevel(percent) {
|
||||||
|
log.debug "Executing 'setLevel'"
|
||||||
|
if (percent != null && percent >= 0 && percent <= 100) {
|
||||||
|
parent.setLevel(this, percent)
|
||||||
|
sendEvent(name: "level", value: percent)
|
||||||
|
sendEvent(name: "switch", value: "on")
|
||||||
|
} else {
|
||||||
|
log.warn "$percent is not 0-100"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setColorTemperature(value) {
|
||||||
|
if (value) {
|
||||||
|
log.trace "setColorTemperature: ${value}k"
|
||||||
|
parent.setColorTemperature(this, value)
|
||||||
|
sendEvent(name: "colorTemperature", value: value)
|
||||||
|
sendEvent(name: "switch", value: "on")
|
||||||
|
} else {
|
||||||
|
log.warn "Invalid color temperature"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void refresh() {
|
||||||
|
log.debug "Executing 'refresh'"
|
||||||
|
parent.manualRefresh()
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
.st-ignore
|
||||||
|
README.md
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
# Smartsense Motion Sensor
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Works with:
|
||||||
|
|
||||||
|
* [Samsung SmartThings Motion Sensor](https://shop.smartthings.com/#!/products/samsung-smartthings-motion-sensor)
|
||||||
|
|
||||||
|
## Table of contents
|
||||||
|
|
||||||
|
* [Capabilities](#capabilities)
|
||||||
|
* [Health]($health)
|
||||||
|
|
||||||
|
## Capabilities
|
||||||
|
|
||||||
|
* **Configuration** - _configure()_ command called when device is installed or device preferences updated
|
||||||
|
* **Motion Sensor** - can detect motion
|
||||||
|
* **Battery** - defines device uses a battery
|
||||||
|
* **Refresh** - _refresh()_ command for status updates
|
||||||
|
* **Health Check** - indicates ability to get device health notifications
|
||||||
|
|
||||||
|
## Device Health
|
||||||
|
|
||||||
|
A Category C2 motion sensor that has 120min check-in interval
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -323,6 +323,8 @@ private getDeviceType(hueType) {
|
|||||||
return "Hue Bulb"
|
return "Hue Bulb"
|
||||||
else if (hueType?.equalsIgnoreCase("Color Light"))
|
else if (hueType?.equalsIgnoreCase("Color Light"))
|
||||||
return "Hue Bloom"
|
return "Hue Bloom"
|
||||||
|
else if (hueType?.equalsIgnoreCase("Color Temperature Light"))
|
||||||
|
return "Hue White Ambiance Bulb"
|
||||||
else
|
else
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2015 SmartThings
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License. You may obtain a copy of the License at:
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
|
||||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
|
||||||
* for the specific language governing permissions and limitations under the License.
|
|
||||||
*
|
|
||||||
* Turn It On For 5 Minutes
|
|
||||||
* Turn on a switch when a contact sensor opens and then turn it back off 5 minutes later.
|
|
||||||
*
|
|
||||||
* Author: SmartThings
|
|
||||||
*/
|
|
||||||
definition(
|
|
||||||
name: "Turn It On For 1 Minutes",
|
|
||||||
namespace: "smartthings",
|
|
||||||
author: "mr.kim",
|
|
||||||
description: "When a SmartSense Multi is opened, a switch will be turned on, and then turned off after 5 minutes.",
|
|
||||||
category: "Safety & Security",
|
|
||||||
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_contact-outlet.png",
|
|
||||||
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/light_contact-outlet@2x.png"
|
|
||||||
)
|
|
||||||
|
|
||||||
preferences {
|
|
||||||
section("When it opens..."){
|
|
||||||
input "contact1", "capability.contactSensor"
|
|
||||||
}
|
|
||||||
section("Turn on a switch for 5 minutes..."){
|
|
||||||
input "switch1", "capability.switch"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def installed() {
|
|
||||||
log.debug "Installed with settings: ${settings}"
|
|
||||||
subscribe(contact1, "contact.open", contactOpenHandler)
|
|
||||||
}
|
|
||||||
|
|
||||||
def updated(settings) {
|
|
||||||
log.debug "Updated with settings: ${settings}"
|
|
||||||
unsubscribe()
|
|
||||||
subscribe(contact1, "contact.open", contactOpenHandler)
|
|
||||||
}
|
|
||||||
|
|
||||||
def contactOpenHandler(evt) {
|
|
||||||
switch1.on()
|
|
||||||
def fiveMinuteDelay = 60 * 1
|
|
||||||
runIn(fiveMinuteDelay, turnOffSwitch)
|
|
||||||
}
|
|
||||||
|
|
||||||
def turnOffSwitch() {
|
|
||||||
switch1.off()
|
|
||||||
}
|
|
||||||
@@ -107,8 +107,8 @@ mappings {
|
|||||||
path("/locks") {
|
path("/locks") {
|
||||||
action: [
|
action: [
|
||||||
GET: "listLocks",
|
GET: "listLocks",
|
||||||
PUT: "updateLock",
|
PUT: "updateLocks",
|
||||||
POST: "updateLock"
|
POST: "updateLocks"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
path("/locks/:id") {
|
path("/locks/:id") {
|
||||||
@@ -442,31 +442,87 @@ def executePhrase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateAll(devices) {
|
private void updateAll(devices) {
|
||||||
|
def type = params.param1
|
||||||
def command = request.JSON?.command
|
def command = request.JSON?.command
|
||||||
if (command)
|
if (!devices) {
|
||||||
{
|
httpError(404, "Devices not found")
|
||||||
command = command.toLowerCase()
|
}
|
||||||
devices."$command"()
|
if (command){
|
||||||
|
devices.each { device ->
|
||||||
|
executeCommand(device, type, command)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update(devices) {
|
private void update(devices) {
|
||||||
log.debug "update, request: ${request.JSON}, params: ${params}, devices: $devices.id"
|
log.debug "update, request: ${request.JSON}, params: ${params}, devices: $devices.id"
|
||||||
//def command = request.JSON?.command
|
def type = params.param1
|
||||||
def command = params.command
|
def command = request.JSON?.command
|
||||||
if (command)
|
def device = devices?.find { it.id == params.id }
|
||||||
{
|
|
||||||
command = command.toLowerCase()
|
if (!device) {
|
||||||
def device = devices.find { it.id == params.id }
|
|
||||||
if (!device)
|
|
||||||
{
|
|
||||||
httpError(404, "Device not found")
|
httpError(404, "Device not found")
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
device."$command"()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (command) {
|
||||||
|
executeCommand(device, type, command)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validating the command passed by the user based on capability.
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
def validateCommand(device, deviceType, command) {
|
||||||
|
def capabilityCommands = getDeviceCapabilityCommands(device.capabilities)
|
||||||
|
def currentDeviceCapability = getCapabilityName(deviceType)
|
||||||
|
if (capabilityCommands[currentDeviceCapability]) {
|
||||||
|
return command in capabilityCommands[currentDeviceCapability] ? true : false
|
||||||
|
} else {
|
||||||
|
// Handling other device types here, which don't accept commands
|
||||||
|
httpError(400, "Bad request.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Need to get the attribute name to do the lookup. Only
|
||||||
|
* doing it for the device types which accept commands
|
||||||
|
* @return attribute name of the device type
|
||||||
|
*/
|
||||||
|
def getCapabilityName(type) {
|
||||||
|
switch(type) {
|
||||||
|
case "switches":
|
||||||
|
return "Switch"
|
||||||
|
case "locks":
|
||||||
|
return "Lock"
|
||||||
|
default:
|
||||||
|
return type
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructing the map over here of
|
||||||
|
* supported commands by device capability
|
||||||
|
* @return a map of device capability -> supported commands
|
||||||
|
*/
|
||||||
|
def getDeviceCapabilityCommands(deviceCapabilities) {
|
||||||
|
def map = [:]
|
||||||
|
deviceCapabilities.collect {
|
||||||
|
map[it.name] = it.commands.collect{ it.name.toString() }
|
||||||
|
}
|
||||||
|
return map
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates and executes the command
|
||||||
|
* on the device or devices
|
||||||
|
*/
|
||||||
|
def executeCommand(device, type, command) {
|
||||||
|
if (validateCommand(device, type, command)) {
|
||||||
|
device."$command"()
|
||||||
|
} else {
|
||||||
|
httpError(403, "Access denied. This command is not supported by current capability.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private show(devices, type) {
|
private show(devices, type) {
|
||||||
|
|||||||
129
smartapps/vlaminck/-.src/-.groovy
Normal file
129
smartapps/vlaminck/-.src/-.groovy
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2015 SmartThings
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License. You may obtain a copy of the License at:
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||||
|
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
||||||
|
* for the specific language governing permissions and limitations under the License.
|
||||||
|
*
|
||||||
|
* Alfred Workflow
|
||||||
|
*
|
||||||
|
* Author: SmartThings
|
||||||
|
*/
|
||||||
|
|
||||||
|
definition(
|
||||||
|
name: "김신동",
|
||||||
|
namespace: "vlaminck",
|
||||||
|
author: "SmartThings",
|
||||||
|
description: "This SmartApp allows you to interact with the things in your physical graph through Alfred.",
|
||||||
|
category: "Convenience",
|
||||||
|
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/alfred-app.png",
|
||||||
|
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/alfred-app@2x.png",
|
||||||
|
oauth: [displayName: "SmartThings Alfred Workflow", displayLink: ""]
|
||||||
|
)
|
||||||
|
|
||||||
|
preferences {
|
||||||
|
section("Allow Alfred to Control These Things...") {
|
||||||
|
input "switches", "capability.switch", title: "Which Switches?", multiple: true, required: false
|
||||||
|
input "locks", "capability.lock", title: "Which Locks?", multiple: true, required: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mappings {
|
||||||
|
path("/switches") {
|
||||||
|
action: [
|
||||||
|
GET: "listSwitches",
|
||||||
|
PUT: "updateSwitches"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/switches/:id") {
|
||||||
|
action: [
|
||||||
|
GET: "showSwitch",
|
||||||
|
PUT: "updateSwitch"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/locks") {
|
||||||
|
action: [
|
||||||
|
GET: "listLocks",
|
||||||
|
PUT: "updateLocks"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/locks/:id") {
|
||||||
|
action: [
|
||||||
|
GET: "showLock",
|
||||||
|
PUT: "updateLock"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def installed() {}
|
||||||
|
|
||||||
|
def updated() {}
|
||||||
|
|
||||||
|
def listSwitches() {
|
||||||
|
switches.collect { device(it,"switch") }
|
||||||
|
}
|
||||||
|
void updateSwitches() {
|
||||||
|
updateAll(switches)
|
||||||
|
}
|
||||||
|
def showSwitch() {
|
||||||
|
show(switches, "switch")
|
||||||
|
}
|
||||||
|
void updateSwitch() {
|
||||||
|
update(switches)
|
||||||
|
}
|
||||||
|
|
||||||
|
def listLocks() {
|
||||||
|
locks.collect { device(it, "lock") }
|
||||||
|
}
|
||||||
|
void updateLocks() {
|
||||||
|
updateAll(locks)
|
||||||
|
}
|
||||||
|
def showLock() {
|
||||||
|
show(locks, "lock")
|
||||||
|
}
|
||||||
|
void updateLock() {
|
||||||
|
update(locks)
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateAll(devices) {
|
||||||
|
def command = request.JSON?.command
|
||||||
|
if (command) {
|
||||||
|
devices."$command"()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void update(devices) {
|
||||||
|
log.debug "update, request: ${request.JSON}, params: ${params}, devices: $devices.id"
|
||||||
|
def command = request.JSON?.command
|
||||||
|
if (command) {
|
||||||
|
def device = devices.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
device."$command"()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private show(devices, name) {
|
||||||
|
def device = devices.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
def s = device.currentState(name)
|
||||||
|
[id: device.id, label: device.displayName, name: device.displayName, state: s]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private device(it, name) {
|
||||||
|
if (it) {
|
||||||
|
def s = it.currentState(name)
|
||||||
|
[id: it.id, label: it.displayName, name: it.displayName, state: s]
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user