Created
June 23, 2015 00:35
-
-
Save bkeifer/7298a67fb766e7530c10 to your computer and use it in GitHub Desktop.
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
mappings { | |
path("/stamp") { | |
action: [ | |
GET: "checkStamp", | |
] | |
} | |
path("/reschedule") { | |
action: [ | |
GET: "reschedule", | |
] | |
} | |
} | |
def updateState() { | |
log.debug("State updated!") | |
state.timestamp = now() | |
} | |
def createSchedule() { | |
unschedule() | |
updateState() | |
schedule("0 * * * * ?", "updateState") | |
} | |
def logURLs() { | |
if (!state.accessToken) { | |
try { | |
createAccessToken() | |
log.debug "Token: $state.accessToken" | |
} catch (e) { | |
log.debug("Error. Is OAuth enabled?") | |
} | |
} | |
def baseURL = "https://graph.api.smartthings.com/api/smartapps/installations" | |
log.debug "Stamp URL: ${baseURL}/${app.id}/stamp?access_token=${state.accessToken}" | |
log.debug "Reset URL: ${baseURL}/${app.id}/reschedule?access_token=${state.accessToken}" | |
} | |
def checkStamp() { | |
def result | |
# 300000 = 5 minutes in milliseconds. Replace with a value of at least | |
# 2x the frequency at which your scheduled function should run. | |
if (now() - state.timestamp < 300000) { | |
result = "FIRING" | |
} else { | |
result = "FAIL" | |
} | |
render contentType: "text/html", data: "<!DOCTYPE html><html><head></head><body>${result}<br><hr><br>App: ${app.name}<br>Last timestamp: ${new Date(state.timestamp)}</body></html>" | |
} | |
def reschedule() { | |
createSchedule() | |
log.trace("Rescheduled via web API call!") | |
render contentType: "text/html", data: "<!DOCTYPE html><html><head></head><body>Rescheduled ${app.name}</body></html>" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment