mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-17 13:10:52 +00:00
Compare commits
5 Commits
PROD_2016.
...
MSA-1385-2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c448455fa | ||
|
|
fc38c534f9 | ||
|
|
fd47bcb8a8 | ||
|
|
972599b1b5 | ||
|
|
f5d3cca6a0 |
88
smartapps/smartthings/beep-when.src/beep-when.groovy
Normal file
88
smartapps/smartthings/beep-when.src/beep-when.groovy
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2016 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.
|
||||||
|
*
|
||||||
|
* Beep When
|
||||||
|
*
|
||||||
|
* Author: SmartThings
|
||||||
|
* Date: 2016-06-05
|
||||||
|
*/
|
||||||
|
definition(
|
||||||
|
name: "Beep When",
|
||||||
|
namespace: "smartthings",
|
||||||
|
author: "SmartThings",
|
||||||
|
description: "Beep Presence sensor when anything happens in your home.",
|
||||||
|
category: "Convenience",
|
||||||
|
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/window_contact.png",
|
||||||
|
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/window_contact@2x.png"
|
||||||
|
)
|
||||||
|
|
||||||
|
preferences {
|
||||||
|
section("Choose one or more, when..."){
|
||||||
|
input "button", "capability.button", title: "Button Pushed", required: false, multiple: true //tw
|
||||||
|
input "motion", "capability.motionSensor", title: "Motion Here", required: false, multiple: true
|
||||||
|
input "contact", "capability.contactSensor", title: "Contact Opens", required: false, multiple: true
|
||||||
|
input "contactClosed", "capability.contactSensor", title: "Contact Closes", required: false, multiple: true
|
||||||
|
input "acceleration", "capability.accelerationSensor", title: "Acceleration Detected", required: false, multiple: true
|
||||||
|
input "mySwitch", "capability.switch", title: "Switch Turned On", required: false, multiple: true
|
||||||
|
input "mySwitchOff", "capability.switch", title: "Switch Turned Off", required: false, multiple: true
|
||||||
|
input "arrivalPresence", "capability.presenceSensor", title: "Arrival Of", required: false, multiple: true
|
||||||
|
input "departurePresence", "capability.presenceSensor", title: "Departure Of", required: false, multiple: true
|
||||||
|
input "smoke", "capability.smokeDetector", title: "Smoke Detected", required: false, multiple: true
|
||||||
|
input "water", "capability.waterSensor", title: "Water Sensor Wet", required: false, multiple: true
|
||||||
|
}
|
||||||
|
section("Beep the presence sensor..") {
|
||||||
|
input "presence", "capability.presenceSensor", title: "Which sensor beep?"
|
||||||
|
}
|
||||||
|
|
||||||
|
section("Minimum time between beeps (optional, defaults to every beep)") {
|
||||||
|
input "frequency", "decimal", title: "Minutes", required: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def installed() {
|
||||||
|
log.debug "Installed with settings: ${settings}"
|
||||||
|
subscribeToEvents()
|
||||||
|
}
|
||||||
|
|
||||||
|
def updated() {
|
||||||
|
log.debug "Updated with settings: ${settings}"
|
||||||
|
unsubscribe()
|
||||||
|
subscribeToEvents()
|
||||||
|
}
|
||||||
|
|
||||||
|
def subscribeToEvents() {
|
||||||
|
subscribe(button, "button.pushed", eventHandler) //tw
|
||||||
|
subscribe(contact, "contact.open", eventHandler)
|
||||||
|
subscribe(contactClosed, "contact.closed", eventHandler)
|
||||||
|
subscribe(acceleration, "acceleration.active", eventHandler)
|
||||||
|
subscribe(motion, "motion.active", eventHandler)
|
||||||
|
subscribe(mySwitch, "switch.on", eventHandler)
|
||||||
|
subscribe(mySwitchOff, "switch.off", eventHandler)
|
||||||
|
subscribe(arrivalPresence, "presence.present", eventHandler)
|
||||||
|
subscribe(departurePresence, "presence.not present", eventHandler)
|
||||||
|
subscribe(smoke, "smoke.detected", eventHandler)
|
||||||
|
subscribe(smoke, "smoke.tested", eventHandler)
|
||||||
|
subscribe(smoke, "carbonMonoxide.detected", eventHandler)
|
||||||
|
subscribe(water, "water.wet", eventHandler)
|
||||||
|
}
|
||||||
|
|
||||||
|
def eventHandler(evt) {
|
||||||
|
log.debug "Notify got evt ${evt}"
|
||||||
|
if (frequency) {
|
||||||
|
def lastTime = state[evt.deviceId]
|
||||||
|
if (lastTime == null || now() - lastTime >= frequency * 60000) {
|
||||||
|
presence.beep() }
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
presence.beep()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,6 +39,7 @@ preferences {
|
|||||||
page(name: "completionPage")
|
page(name: "completionPage")
|
||||||
page(name: "numbersPage")
|
page(name: "numbersPage")
|
||||||
page(name: "controllerExplanationPage")
|
page(name: "controllerExplanationPage")
|
||||||
|
page(name: "unsupportedDevicesPage")
|
||||||
}
|
}
|
||||||
|
|
||||||
def rootPage() {
|
def rootPage() {
|
||||||
@@ -47,6 +48,9 @@ def rootPage() {
|
|||||||
section("What to dim") {
|
section("What to dim") {
|
||||||
input(name: "dimmers", type: "capability.switchLevel", title: "Dimmers", description: null, multiple: true, required: true, submitOnChange: true)
|
input(name: "dimmers", type: "capability.switchLevel", title: "Dimmers", description: null, multiple: true, required: true, submitOnChange: true)
|
||||||
if (dimmers) {
|
if (dimmers) {
|
||||||
|
if (dimmersContainUnsupportedDevices()) {
|
||||||
|
href(name: "toUnsupportedDevicesPage", page: "unsupportedDevicesPage", title: "Some of your selected dimmers don't seem to be supported", description: "Tap here to fix it", required: true)
|
||||||
|
}
|
||||||
href(name: "toNumbersPage", page: "numbersPage", title: "Duration & Direction", description: numbersPageHrefDescription(), state: "complete")
|
href(name: "toNumbersPage", page: "numbersPage", title: "Duration & Direction", description: numbersPageHrefDescription(), state: "complete")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,6 +75,31 @@ def rootPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def unsupportedDevicesPage() {
|
||||||
|
|
||||||
|
def unsupportedDimmers = dimmers.findAll { !hasSetLevelCommand(it) }
|
||||||
|
|
||||||
|
dynamicPage(name: "unsupportedDevicesPage") {
|
||||||
|
if (unsupportedDimmers) {
|
||||||
|
section("These devices do not support the setLevel command") {
|
||||||
|
unsupportedDimmers.each {
|
||||||
|
paragraph deviceLabel(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
section {
|
||||||
|
input(name: "dimmers", type: "capability.sensor", title: "Please remove the above devices from this list.", submitOnChange: true, multiple: true)
|
||||||
|
}
|
||||||
|
section {
|
||||||
|
paragraph "If you think there is a mistake here, please contact support."
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
section {
|
||||||
|
paragraph "You're all set. You can hit the back button, now. Thanks for cleaning up your settings :)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def controllerExplanationPage() {
|
def controllerExplanationPage() {
|
||||||
dynamicPage(name: "controllerExplanationPage", title: "How To Control Gentle Wake Up") {
|
dynamicPage(name: "controllerExplanationPage", title: "How To Control Gentle Wake Up") {
|
||||||
|
|
||||||
@@ -528,14 +557,16 @@ def updateDimmers(percentComplete) {
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
def shouldChangeColors = (colorize && colorize != "false")
|
def shouldChangeColors = (colorize && colorize != "false")
|
||||||
def canChangeColors = hasSetColorCommand(dimmer)
|
|
||||||
|
|
||||||
log.debug "Setting ${deviceLabel(dimmer)} to ${nextLevel}"
|
if (shouldChangeColors && hasSetColorCommand(dimmer)) {
|
||||||
|
def hue = getHue(dimmer, nextLevel)
|
||||||
if (shouldChangeColors && canChangeColors) {
|
log.debug "Setting ${deviceLabel(dimmer)} level to ${nextLevel} and hue to ${hue}"
|
||||||
dimmer.setColor([hue: getHue(dimmer, nextLevel), saturation: 100, level: nextLevel])
|
dimmer.setColor([hue: hue, saturation: 100, level: nextLevel])
|
||||||
} else {
|
} else if (hasSetLevelCommand(dimmer)) {
|
||||||
|
log.debug "Setting ${deviceLabel(dimmer)} level to ${nextLevel}"
|
||||||
dimmer.setLevel(nextLevel)
|
dimmer.setLevel(nextLevel)
|
||||||
|
} else {
|
||||||
|
log.warn "${deviceLabel(dimmer)} does not have setColor or setLevel commands."
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -817,24 +848,21 @@ private getRedHue(level) {
|
|||||||
if (level >= 96) return 17
|
if (level >= 96) return 17
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private dimmersContainUnsupportedDevices() {
|
||||||
|
def found = dimmers.find { hasSetLevelCommand(it) == false }
|
||||||
|
return found != null
|
||||||
|
}
|
||||||
|
|
||||||
private hasSetLevelCommand(device) {
|
private hasSetLevelCommand(device) {
|
||||||
def isDimmer = false
|
return hasCommand(device, "setLevel")
|
||||||
device.supportedCommands.each {
|
|
||||||
if (it.name.contains("setLevel")) {
|
|
||||||
isDimmer = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return isDimmer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private hasSetColorCommand(device) {
|
private hasSetColorCommand(device) {
|
||||||
def hasColor = false
|
return hasCommand(device, "setColor")
|
||||||
device.supportedCommands.each {
|
}
|
||||||
if (it.name.contains("setColor")) {
|
|
||||||
hasColor = true
|
private hasCommand(device, String command) {
|
||||||
}
|
return (device.supportedCommands.find { it.name == command } != null)
|
||||||
}
|
|
||||||
return hasColor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private dimmersWithSetColorCommand() {
|
private dimmersWithSetColorCommand() {
|
||||||
@@ -1073,4 +1101,4 @@ def hasStartLevel() {
|
|||||||
|
|
||||||
def hasEndLevel() {
|
def hasEndLevel() {
|
||||||
return (endLevel != null && endLevel != "")
|
return (endLevel != null && endLevel != "")
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user