Last active
August 29, 2015 14:21
-
-
Save jimmyjames/f78eb7313bc0dd53e1d3 to your computer and use it in GitHub Desktop.
check if light is on
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check Lights at Night | |
* | |
* Copyright 2015 james anderson | |
* | |
* 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: "Check Lights at Night", | |
namespace: "jimmyjames", | |
author: "james anderson", | |
description: "Check if a light is on at a specified time, and send a notification if they are.", | |
category: "", | |
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("Which Lights?") { | |
input "theLight", "capability.switch" | |
} | |
section("At what time?") { | |
input "theTime", "time" | |
} | |
section( "Notifications" ) { | |
input "sendPushMessage", "bool", title: "Push notification", | |
required: false, defaultValue: "true" | |
input "phone", "phone", title: "Send a Text Message?", | |
required: false | |
} | |
} | |
def installed() { | |
log.debug "Installed with settings: ${settings}" | |
initialize() | |
} | |
def updated() { | |
log.debug "Updated with settings: ${settings}" | |
unsubscribe() | |
initialize() | |
} | |
def initialize() { | |
// call checkLights method at time specified in setup | |
schedule(theTime, checkLights) | |
} | |
def checkLights() { | |
log.debug "checking switches at: ${new Date()}" | |
// switches have a "switch" attribute. To get the current value | |
// use <device>.current<capitalized attribute> | |
if (theLight.currentSwitch == "on") { | |
def message = "Your ${theLight.displayName} is on!" | |
// send a push notification in the SmartThings app if configured | |
if (sendPushMessage) { | |
sendPush(message) | |
} | |
// send a text message to the number specified, if configured | |
if (phone) { | |
sendSms(phone, message) | |
} | |
} else { | |
log.debug "${theLight.displayName} is off!" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment