Compare commits

..

3 Commits

Author SHA1 Message Date
Vinay Rao
90e6dc91eb Merge pull request #1018 from SmartThingsCommunity/staging
Rolling up staging to production
2016-06-28 14:16:10 -07:00
Vinay Rao
3ee8f86aa3 Merge pull request #1004 from SmartThingsCommunity/staging
Rolling up staging to prod
2016-06-21 13:19:59 -07:00
Vinay Rao
d1a910f11f Merge pull request #992 from SmartThingsCommunity/staging
Rolling up staging to prod
2016-06-14 13:11:06 -07:00
2 changed files with 21 additions and 227 deletions

View File

@@ -1,178 +0,0 @@
/**
* Timer Light
*
* Copyright 2016 Kevin Hill
*
* 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.
*
*/
import groovy.time.*
definition(
name: "Timer Light",
namespace: "gr8gitsby",
author: "Kevin Hill",
description: "This puts outside lights on a timer",
category: "Convenience",
iconUrl: "https://source.unsplash.com/category/nature/60x60",
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 {
// Use a light swtich
section("Light Switch") {
// Capabilities link: http://docs.smartthings.com/en/latest/capabilities-reference.html
// Input data types: http://docs.smartthings.com/en/latest/device-type-developers-guide/device-preferences.html?highlight=input#supported-input-types
input "theSwitch", "capability.switch", title: "Pick your light switch"
input "confirmationSwitch", "capability.switch", title: "Pick the notification switch"
input "minutes", "number", title: "Enter the number of minutes you'd like the lights on"
input "person", "capability.presenceSensor", title: "When who arrives?"
// When arrival is detected, if it is dark, turn on the outside lights
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
subscribe(theSwitch, "switch", switchHandler)
subscribe(confirmationSwitch, "switch", confirmationSwitchHandler)
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize() {
// This method sets up the app
subscribe(person, "presence", presenceChange)
state.Flashes = 4
initialSunPosition()
}
def presenceChange(evt){
log.debug("presenceChange")
// if someone arrives at night the lights will turn on
if("present" == evt.value){
timerLight()
}
}
// Function to set lights on timer for person arriving
def timerLight() {
log.debug(state.sunPosition)
if(state.sunPosition == "down"){
light.on()
runIn(60 * minutes, turnOff)
}
}
def turnOff(){
// This method turns off the ligt
theSwitch.off()
confirmationSwitch.off()
}
def initialSunPosition() {
// This method determines if sun is down at time of initializtion and run sunsetHandler() if so
def s = getSunriseAndSunset(zipCode: "98052")
def now = new Date()
def riseTime = s.sunrise
def setTime = s.sunset
if(setTime.before(now)) {
sunsetHandler()
log.info "Sun is already down, run sunsetHandler"
}
else
{ if (riseTime.after(now)) {
sunriseHandler()
log.info "Sun is up, run sunriseHandler"
}
}
}
def sunriseHandler() {
// method to set the sun position when the sun rises
state.sunPosition = "up"
}
def sunsetHandler() {
// method to set the sun position when the sunsets
state.sunPosition = "down"
}
/*
def switchHandler(evt) {
log.debug("switch Handler Fired")
}
*/
def confirmationSwitchHandler(evt) {
state.Flashes = state.Flashes - 1
log.debug("Flashes: ${state.Flashes}")
log.debug("Event State: ${evt.value}")
if(evt.value == "on" && state.Flashes > 0) {
runIn(2, turnOffConfirmationSwitch)
} else if(evt.value == "off" && state.Flashes > 0) {
runIn(2, turnOnConfirmationSwitch)
}
if(state.Flashes == 0){
state.Flashes = 4
}
}
def turnOnConfirmationSwitch(){
confirmationSwitch.on()
}
def turnOffConfirmationSwitch(){
confirmationSwitch.off()
}
def switchHandler(evt){
log.debug("light Event handler fired")
// use Event rather than DeviceState because we may be changing DeviceState to only store changed values
def recentStates = theSwitch.eventsSince(new Date(now() - 4000), [all:true, max: 10]).findAll{it.name == "switch"}
log.debug "${recentStates?.size()} STATES FOUND, LAST AT ${recentStates ? recentStates[0].dateCreated : ''}"
//sendPush("Attempting to check light presses")
if (evt.value == "on") {
log.debug("==== ON ====")
}
log.debug(recentStates.size())
//if (evt.isPhysical()) {
if (recentStates.size() >= 2) {
log.debug "Outside light timer mode engaged"
def switchattr = confirmationSwitch.currentValue("switch")
log.debug "confirmationSwitch: $switchattr"
confirmationSwitch.on()
//alternativeSwitch.off()
//def message = "${location.name} executed ${settings.onPhrase} because ${evt.title} was tapped twice."
runIn(60 * minutes, turnOff)
} else {
log.trace "Skipping digital on/off event"
}
//log.debug("switch is on, turn off in $minutes")
//runIn(60*minutes, turnOff)
//}
}

View File

@@ -39,7 +39,6 @@ preferences {
page(name: "completionPage")
page(name: "numbersPage")
page(name: "controllerExplanationPage")
page(name: "unsupportedDevicesPage")
}
def rootPage() {
@@ -48,9 +47,6 @@ def rootPage() {
section("What to dim") {
input(name: "dimmers", type: "capability.switchLevel", title: "Dimmers", description: null, multiple: true, required: true, submitOnChange: true)
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")
}
}
@@ -75,31 +71,6 @@ 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() {
dynamicPage(name: "controllerExplanationPage", title: "How To Control Gentle Wake Up") {
@@ -557,16 +528,14 @@ def updateDimmers(percentComplete) {
} else {
def shouldChangeColors = (colorize && colorize != "false")
def canChangeColors = hasSetColorCommand(dimmer)
if (shouldChangeColors && hasSetColorCommand(dimmer)) {
def hue = getHue(dimmer, nextLevel)
log.debug "Setting ${deviceLabel(dimmer)} level to ${nextLevel} and hue to ${hue}"
dimmer.setColor([hue: hue, saturation: 100, level: nextLevel])
} else if (hasSetLevelCommand(dimmer)) {
log.debug "Setting ${deviceLabel(dimmer)} level to ${nextLevel}"
dimmer.setLevel(nextLevel)
log.debug "Setting ${deviceLabel(dimmer)} to ${nextLevel}"
if (shouldChangeColors && canChangeColors) {
dimmer.setColor([hue: getHue(dimmer, nextLevel), saturation: 100, level: nextLevel])
} else {
log.warn "${deviceLabel(dimmer)} does not have setColor or setLevel commands."
dimmer.setLevel(nextLevel)
}
}
@@ -848,21 +817,24 @@ private getRedHue(level) {
if (level >= 96) return 17
}
private dimmersContainUnsupportedDevices() {
def found = dimmers.find { hasSetLevelCommand(it) == false }
return found != null
}
private hasSetLevelCommand(device) {
return hasCommand(device, "setLevel")
def isDimmer = false
device.supportedCommands.each {
if (it.name.contains("setLevel")) {
isDimmer = true
}
}
return isDimmer
}
private hasSetColorCommand(device) {
return hasCommand(device, "setColor")
}
private hasCommand(device, String command) {
return (device.supportedCommands.find { it.name == command } != null)
def hasColor = false
device.supportedCommands.each {
if (it.name.contains("setColor")) {
hasColor = true
}
}
return hasColor
}
private dimmersWithSetColorCommand() {
@@ -1101,4 +1073,4 @@ def hasStartLevel() {
def hasEndLevel() {
return (endLevel != null && endLevel != "")
}
}