Created
August 21, 2013 20:53
-
-
Save danlieberman/6300134 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Scheduled Mode Change - Presence Optional | |
* | |
* Author: SmartThings | |
* | |
*/ | |
preferences { | |
section("At this time every day") { | |
input "time", "time", title: "Time of Day" | |
} | |
section("Change to this mode") { | |
input "newMode", "mode", title: "Mode?" | |
} | |
section( "Notifications" ) { | |
input "sendPushMessage", "enum", title: "Send a push notification?", metadata:[values:["Yes", "No"]] | |
input "phoneNumber", "phone", title: "Send a text message?", required: false | |
} | |
} | |
def installed() { | |
initialize() | |
} | |
def updated() { | |
unschedule() | |
initialize() | |
} | |
def initialize() { | |
schedule(time, changeMode) | |
} | |
def changeMode() { | |
if (location.mode != newMode) { | |
if (location.modes?.find{it.name == newMode}) { | |
setLocationMode(newMode) | |
send "${label} has changed the mode to '${newMode}'" | |
} | |
else { | |
send "${label} tried to change to undefined mode '${newMode}'" | |
} | |
} | |
} | |
private send(msg) { | |
if ( sendPushMessage == "Yes" ) { | |
log.debug( "sending push message" ) | |
sendPush( msg ) | |
} | |
if ( phoneNumber ) { | |
log.debug( "sending text message" ) | |
sendSms( phoneNumber, msg ) | |
} | |
log.debug msg | |
} | |
private getLabel() { | |
app.label ?: "SmartThings" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment