Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danlieberman/6300134 to your computer and use it in GitHub Desktop.
Save danlieberman/6300134 to your computer and use it in GitHub Desktop.
/**
* 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