mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-19 21:03:46 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bdb1390ad0 | ||
|
|
65c1228931 | ||
|
|
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,117 @@
|
|||||||
|
definition(
|
||||||
|
name: "EyXAr Notifications",
|
||||||
|
namespace: "eyxar",
|
||||||
|
author: "EyXAr",
|
||||||
|
description: "Phone and Voice notification of your door sensor status and phone presence sensor autonitification.",
|
||||||
|
category: "SmartThings Labs",
|
||||||
|
iconUrl: "https://s3.amazonaws.com/for-st/For_ST_60px.png",
|
||||||
|
iconX2Url: "https://s3.amazonaws.com/for-st/For_ST_120px.png",
|
||||||
|
iconX3Url: "https://s3.amazonaws.com/for-st/For_ST_256px.png"
|
||||||
|
)
|
||||||
|
|
||||||
|
/* For ST will only work if EyXAr Notification is installed and set-up first. */
|
||||||
|
|
||||||
|
preferences {
|
||||||
|
section("EyXAr Auto Notifications - For Voice Notification, Install the app 'FOR ST' in Google Play")
|
||||||
|
{
|
||||||
|
input "door", "capability.contactSensor", title: "Select Door/Contact", required: false, multiple: true
|
||||||
|
}
|
||||||
|
|
||||||
|
section("Send Notifications by Text or use below option?") {
|
||||||
|
input("recipients", "contact", title: "Send notifications to"){
|
||||||
|
input "phone", "phone", title: "Phone Number (optional, text charges may apply)",
|
||||||
|
description: "Phone Number", required: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
section("If combine with 'For ST' android app, this will add features of voice notifications.") {
|
||||||
|
input "sendPush", "bool", required: false,
|
||||||
|
title: "Phone/Tablet Auto Notification (Must be set to On =>>)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Presense */
|
||||||
|
|
||||||
|
section("Phone Presence Auto Notifications - For Voice notifications install 'FOR ST' in Google Play") {
|
||||||
|
input "presence", "capability.presenceSensor", title: "Select Phone/Tablet to Detect: (mandatory & rest below are optional)", required: false, multiple: true
|
||||||
|
}
|
||||||
|
|
||||||
|
def installed() {
|
||||||
|
initialize()
|
||||||
|
/* Presense */
|
||||||
|
subscribe(door, "contact.open", doorOpenHandler)
|
||||||
|
subscribe(door, "contact.closed", doorClosedHandler)
|
||||||
|
subscribe(presence, "presence", myHandler)
|
||||||
|
subscribe(presence, "presence", presenceHandler)
|
||||||
|
}
|
||||||
|
|
||||||
|
def updated() {
|
||||||
|
initialize()
|
||||||
|
}
|
||||||
|
|
||||||
|
def initialize() {
|
||||||
|
subscribe(door, "contact.open", doorOpenHandler)
|
||||||
|
subscribe(door, "contact.closed", doorClosedHandler)
|
||||||
|
subscribe(presence, "presence", myHandler)
|
||||||
|
subscribe(presence, "presence", presenceHandler)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
def doorOpenHandler(evt) {
|
||||||
|
def message = "EyXAr Detected the ${evt.displayName} is ${evt.value}!"
|
||||||
|
if (sendPush) {
|
||||||
|
sendPush(message)
|
||||||
|
}
|
||||||
|
if (phone) {
|
||||||
|
sendSms(phone, message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def doorClosedHandler(evt) {
|
||||||
|
def message = "EyXAr Detected the ${evt.displayName} is ${evt.value}!"
|
||||||
|
if (sendPush) {
|
||||||
|
sendPush(message)
|
||||||
|
}
|
||||||
|
if (phone) {
|
||||||
|
sendSms(phone, message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def contactHandler(evt) {
|
||||||
|
if("open" == evt.value)
|
||||||
|
|
||||||
|
// contact was opened, turn on a light maybe?
|
||||||
|
log.debug "Contact is in ${evt.value} state"
|
||||||
|
|
||||||
|
if("closed" == evt.value)
|
||||||
|
// contact was closed, turn off the light?
|
||||||
|
log.debug "Contact is in ${evt.value} state"
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Presense */
|
||||||
|
def myHandler(evt) {
|
||||||
|
if("present" == evt.value)
|
||||||
|
def message = "EyXAr Detected ${evt.displayName} is ${evt.value}!"
|
||||||
|
if (sendPush) {
|
||||||
|
sendPush(message)
|
||||||
|
}
|
||||||
|
if (phone) {
|
||||||
|
sendSms(phone, message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def presenceHandler(evt) {
|
||||||
|
|
||||||
|
if (evt.value == "present") {
|
||||||
|
log.debug "EyXAr ${evt.displayName} has arrived at the ${location}!"
|
||||||
|
sendPush("EyXAr ${evt.displayName} has arrived at the ${location}!")
|
||||||
|
} else if (evt.value == "not present") {
|
||||||
|
|
||||||
|
log.debug "EyXAr ${evt.displayName} has left the ${location}!"
|
||||||
|
|
||||||
|
sendPush("EyXAr ${evt.displayName} has left the ${location}!")
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user