mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-22 21:03:51 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b44a03b90e | ||
|
|
3b89368d45 | ||
|
|
12f6039de5 | ||
|
|
65c9da32e7 | ||
|
|
7147770e2d |
@@ -5,7 +5,7 @@ metadata {
|
|||||||
capability "Switch"
|
capability "Switch"
|
||||||
capability "Sensor"
|
capability "Sensor"
|
||||||
|
|
||||||
fingerprint profileId: "0104", inClusters: "0000,0003,0006", outClusters: "0019"
|
fingerprint profileId: "0104", inClusters: "0006, 0004, 0003, 0000, 0005", outClusters: "0019", manufacturer: "Compacta International, Ltd", model: "ZBMPlug15", deviceJoinName: "SmartPower Outlet V1"
|
||||||
}
|
}
|
||||||
|
|
||||||
// simulator metadata
|
// simulator metadata
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/**
|
||||||
|
* Fortrezz siren test by open and close sensor
|
||||||
|
*
|
||||||
|
* Copyright 2016 Cz
|
||||||
|
*
|
||||||
|
* 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: "Fortrezz siren test by open and close sensor",
|
||||||
|
namespace: "alarm",
|
||||||
|
author: "Cz",
|
||||||
|
description: "alarm",
|
||||||
|
category: "My Apps",
|
||||||
|
iconUrl: "https://static.wixstatic.com/media/15eeff_b050ea350d0f4733aa6a881660a2c49a.png/v1/fill/w_200,h_200,al_c/15eeff_b050ea350d0f4733aa6a881660a2c49a.png",
|
||||||
|
iconX2Url: "https://static.wixstatic.com/media/15eeff_b050ea350d0f4733aa6a881660a2c49a.png/v1/fill/w_200,h_200,al_c/15eeff_b050ea350d0f4733aa6a881660a2c49a.png",
|
||||||
|
iconX3Url: "https://static.wixstatic.com/media/15eeff_b050ea350d0f4733aa6a881660a2c49a.png/v1/fill/w_200,h_200,al_c/15eeff_b050ea350d0f4733aa6a881660a2c49a.png")
|
||||||
|
|
||||||
|
|
||||||
|
preferences {
|
||||||
|
section("Siren by open and close sensor")
|
||||||
|
section("When Multipurpose Sencor do something"){
|
||||||
|
input "theMultipurpose","capability.contactSensor",required:true,title:"which Multipurpose sensor?"
|
||||||
|
}
|
||||||
|
section("Siren or alarm"){
|
||||||
|
input "theAlarm","capability.alarm",required:true,title:"which switch Siren or alarm?"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def installed() {
|
||||||
|
log.debug "Installed with settings: ${settings}"
|
||||||
|
|
||||||
|
initialize()
|
||||||
|
}
|
||||||
|
|
||||||
|
def updated() {
|
||||||
|
log.debug "Updated with settings: ${settings}"
|
||||||
|
|
||||||
|
unsubscribe()
|
||||||
|
initialize()
|
||||||
|
}
|
||||||
|
|
||||||
|
def initialize() {
|
||||||
|
subscribe(theMultipurpose,"contact",contactHandler)
|
||||||
|
}
|
||||||
|
def contactHandler(evt)
|
||||||
|
{
|
||||||
|
if(evt.value=="open")
|
||||||
|
{
|
||||||
|
//theAlarm.strobe()
|
||||||
|
//theAlarm.siren()
|
||||||
|
theAlarm.both()
|
||||||
|
runIn(1,theAlarmoff)
|
||||||
|
}
|
||||||
|
else if(evt.value=="closed")
|
||||||
|
{
|
||||||
|
theAlarm.off()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def theAlarmoff()
|
||||||
|
{
|
||||||
|
theAlarm.off()
|
||||||
|
}
|
||||||
|
// TODO: implement event handlers
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* Initial State Event Streamer
|
* Initial State Event Streamer
|
||||||
*
|
*
|
||||||
* Copyright 2015 David Sulpy
|
* Copyright 2016 David Sulpy
|
||||||
*
|
*
|
||||||
* 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
|
||||||
* in compliance with the License. You may obtain a copy of the License at:
|
* in compliance with the License. You may obtain a copy of the License at:
|
||||||
@@ -77,6 +77,62 @@ mappings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def getAccessKey() {
|
||||||
|
log.trace "get access key"
|
||||||
|
if (atomicState.accessKey == null) {
|
||||||
|
httpError(404, "Access Key Not Found")
|
||||||
|
} else {
|
||||||
|
[
|
||||||
|
accessKey: atomicState.accessKey
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def getBucketKey() {
|
||||||
|
log.trace "get bucket key"
|
||||||
|
if (atomicState.bucketKey == null) {
|
||||||
|
httpError(404, "Bucket key Not Found")
|
||||||
|
} else {
|
||||||
|
[
|
||||||
|
bucketKey: atomicState.bucketKey,
|
||||||
|
bucketName: atomicState.bucketName
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def setBucketKey() {
|
||||||
|
log.trace "set bucket key"
|
||||||
|
def newBucketKey = request.JSON?.bucketKey
|
||||||
|
def newBucketName = request.JSON?.bucketName
|
||||||
|
|
||||||
|
log.debug "bucket name: $newBucketName"
|
||||||
|
log.debug "bucket key: $newBucketKey"
|
||||||
|
|
||||||
|
if (newBucketKey && (newBucketKey != atomicState.bucketKey || newBucketName != atomicState.bucketName)) {
|
||||||
|
atomicState.bucketKey = "$newBucketKey"
|
||||||
|
atomicState.bucketName = "$newBucketName"
|
||||||
|
atomicState.isBucketCreated = false
|
||||||
|
}
|
||||||
|
|
||||||
|
tryCreateBucket()
|
||||||
|
}
|
||||||
|
|
||||||
|
def setAccessKey() {
|
||||||
|
log.trace "set access key"
|
||||||
|
def newAccessKey = request.JSON?.accessKey
|
||||||
|
def newGrokerSubdomain = request.JSON?.grokerSubdomain
|
||||||
|
|
||||||
|
if (newGrokerSubdomain && newGrokerSubdomain != "" && newGrokerSubdomain != atomicState.grokerSubdomain) {
|
||||||
|
atomicState.grokerSubdomain = "$newGrokerSubdomain"
|
||||||
|
atomicState.isBucketCreated = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newAccessKey && newAccessKey != atomicState.accessKey) {
|
||||||
|
atomicState.accessKey = "$newAccessKey"
|
||||||
|
atomicState.isBucketCreated = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def subscribeToEvents() {
|
def subscribeToEvents() {
|
||||||
if (accelerometers != null) {
|
if (accelerometers != null) {
|
||||||
subscribe(accelerometers, "acceleration", genericHandler)
|
subscribe(accelerometers, "acceleration", genericHandler)
|
||||||
@@ -169,85 +225,27 @@ def subscribeToEvents() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def getAccessKey() {
|
|
||||||
log.trace "get access key"
|
|
||||||
if (atomicState.accessKey == null) {
|
|
||||||
httpError(404, "Access Key Not Found")
|
|
||||||
} else {
|
|
||||||
[
|
|
||||||
accessKey: atomicState.accessKey
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def getBucketKey() {
|
|
||||||
log.trace "get bucket key"
|
|
||||||
if (atomicState.bucketKey == null) {
|
|
||||||
httpError(404, "Bucket key Not Found")
|
|
||||||
} else {
|
|
||||||
[
|
|
||||||
bucketKey: atomicState.bucketKey,
|
|
||||||
bucketName: atomicState.bucketName
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def setBucketKey() {
|
|
||||||
log.trace "set bucket key"
|
|
||||||
def newBucketKey = request.JSON?.bucketKey
|
|
||||||
def newBucketName = request.JSON?.bucketName
|
|
||||||
|
|
||||||
log.debug "bucket name: $newBucketName"
|
|
||||||
log.debug "bucket key: $newBucketKey"
|
|
||||||
|
|
||||||
if (newBucketKey && (newBucketKey != atomicState.bucketKey || newBucketName != atomicState.bucketName)) {
|
|
||||||
atomicState.bucketKey = "$newBucketKey"
|
|
||||||
atomicState.bucketName = "$newBucketName"
|
|
||||||
atomicState.isBucketCreated = false
|
|
||||||
}
|
|
||||||
|
|
||||||
tryCreateBucket()
|
|
||||||
}
|
|
||||||
|
|
||||||
def setAccessKey() {
|
|
||||||
log.trace "set access key"
|
|
||||||
def newAccessKey = request.JSON?.accessKey
|
|
||||||
def newGrokerSubdomain = request.JSON?.grokerSubdomain
|
|
||||||
|
|
||||||
if (newGrokerSubdomain && newGrokerSubdomain != "" && newGrokerSubdomain != atomicState.grokerSubdomain) {
|
|
||||||
atomicState.grokerSubdomain = "$newGrokerSubdomain"
|
|
||||||
atomicState.isBucketCreated = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newAccessKey && newAccessKey != atomicState.accessKey) {
|
|
||||||
atomicState.accessKey = "$newAccessKey"
|
|
||||||
atomicState.isBucketCreated = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def installed() {
|
def installed() {
|
||||||
atomicState.version = "1.0.18"
|
atomicState.version = "1.1.0"
|
||||||
|
|
||||||
|
atomicState.isBucketCreated = false
|
||||||
|
atomicState.grokerSubdomain = "groker"
|
||||||
|
|
||||||
subscribeToEvents()
|
subscribeToEvents()
|
||||||
|
|
||||||
atomicState.isBucketCreated = false
|
atomicState.isBucketCreated = false
|
||||||
atomicState.grokerSubdomain = "groker"
|
atomicState.grokerSubdomain = "groker"
|
||||||
atomicState.eventBuffer = []
|
|
||||||
|
|
||||||
runEvery15Minutes(flushBuffer)
|
|
||||||
|
|
||||||
log.debug "installed (version $atomicState.version)"
|
log.debug "installed (version $atomicState.version)"
|
||||||
}
|
}
|
||||||
|
|
||||||
def updated() {
|
def updated() {
|
||||||
atomicState.version = "1.0.18"
|
atomicState.version = "1.1.0"
|
||||||
unsubscribe()
|
unsubscribe()
|
||||||
|
|
||||||
if (atomicState.bucketKey != null && atomicState.accessKey != null) {
|
if (atomicState.bucketKey != null && atomicState.accessKey != null) {
|
||||||
atomicState.isBucketCreated = false
|
atomicState.isBucketCreated = false
|
||||||
}
|
}
|
||||||
if (atomicState.eventBuffer == null) {
|
|
||||||
atomicState.eventBuffer = []
|
|
||||||
}
|
|
||||||
if (atomicState.grokerSubdomain == null || atomicState.grokerSubdomain == "") {
|
if (atomicState.grokerSubdomain == null || atomicState.grokerSubdomain == "") {
|
||||||
atomicState.grokerSubdomain = "groker"
|
atomicState.grokerSubdomain = "groker"
|
||||||
}
|
}
|
||||||
@@ -327,37 +325,17 @@ def genericHandler(evt) {
|
|||||||
eventHandler(key, value)
|
eventHandler(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a handler function for flushing the event buffer
|
|
||||||
// after a specified amount of time to reduce the load on ST servers
|
|
||||||
def flushBuffer() {
|
|
||||||
def eventBuffer = atomicState.eventBuffer
|
|
||||||
log.trace "About to flush the buffer on schedule"
|
|
||||||
if (eventBuffer != null && eventBuffer.size() > 0) {
|
|
||||||
atomicState.eventBuffer = []
|
|
||||||
tryShipEvents(eventBuffer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def eventHandler(name, value) {
|
def eventHandler(name, value) {
|
||||||
def epoch = now() / 1000
|
def epoch = now() / 1000
|
||||||
def eventBuffer = atomicState.eventBuffer ?: []
|
|
||||||
eventBuffer << [key: "$name", value: "$value", epoch: "$epoch"]
|
|
||||||
|
|
||||||
if (eventBuffer.size() >= 10) {
|
def event = new JsonSlurper().parseText("{\"key\": \"$name\", \"value\": \"$value\", \"epoch\": \"$epoch\"}")
|
||||||
// Clear eventBuffer right away since we've already pulled it off of atomicState to reduce the risk of missing
|
|
||||||
// events. This assumes the grokerSubdomain, accessKey, and bucketKey are set correctly to avoid the eventBuffer
|
tryShipEvents(event)
|
||||||
// from growing unbounded.
|
|
||||||
atomicState.eventBuffer = []
|
log.debug "Shipped Event: " + event
|
||||||
tryShipEvents(eventBuffer)
|
|
||||||
} else {
|
|
||||||
// Make sure we persist the updated eventBuffer with the new event added back to atomicState
|
|
||||||
atomicState.eventBuffer = eventBuffer
|
|
||||||
}
|
|
||||||
log.debug "Event added to buffer: " + eventBuffer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// a helper function for shipping the atomicState.eventBuffer to Initial State
|
def tryShipEvents(event) {
|
||||||
def tryShipEvents(eventBuffer) {
|
|
||||||
|
|
||||||
def grokerSubdomain = atomicState.grokerSubdomain
|
def grokerSubdomain = atomicState.grokerSubdomain
|
||||||
// can't ship events if there is no grokerSubdomain
|
// can't ship events if there is no grokerSubdomain
|
||||||
@@ -380,7 +358,7 @@ def tryShipEvents(eventBuffer) {
|
|||||||
"X-IS-AccessKey": "${accessKey}",
|
"X-IS-AccessKey": "${accessKey}",
|
||||||
"Accept-Version": "0.0.2"
|
"Accept-Version": "0.0.2"
|
||||||
],
|
],
|
||||||
body: eventBuffer
|
body: event
|
||||||
]
|
]
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
67
smartapps/lock/lock-test.src/lock-test.groovy
Normal file
67
smartapps/lock/lock-test.src/lock-test.groovy
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
/**
|
||||||
|
* Lock Test
|
||||||
|
*
|
||||||
|
* Copyright 2016 Cz
|
||||||
|
*
|
||||||
|
* 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: "Lock Test",
|
||||||
|
namespace: "Lock",
|
||||||
|
author: "Cz",
|
||||||
|
description: "Lock Test",
|
||||||
|
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")
|
||||||
|
|
||||||
|
|
||||||
|
preferences {
|
||||||
|
section("Turn on when motion detected:") {
|
||||||
|
input "themotion", "capability.contactSensor", required: true, title: "Where?"
|
||||||
|
}
|
||||||
|
section("Turn on the lock") {
|
||||||
|
input "thelock", "capability.lock", required: true,titel:"lock?"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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(themotion, "contact", motionAction)
|
||||||
|
}
|
||||||
|
|
||||||
|
def motionAction(evt)
|
||||||
|
{
|
||||||
|
if(evt.value=="open")
|
||||||
|
{
|
||||||
|
thelock.unlock()
|
||||||
|
}
|
||||||
|
else if(evt.value=="closed")
|
||||||
|
{
|
||||||
|
thelock.lock()
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug "thelock:${thelock.lock}"
|
||||||
|
}
|
||||||
|
// TODO: implement event handlers
|
||||||
Reference in New Issue
Block a user