Skip to content

Instantly share code, notes, and snippets.

@bkeifer
Created June 23, 2015 00:35
Show Gist options
  • Save bkeifer/7298a67fb766e7530c10 to your computer and use it in GitHub Desktop.
Save bkeifer/7298a67fb766e7530c10 to your computer and use it in GitHub Desktop.
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