Skip to content

Instantly share code, notes, and snippets.

@rappleg
Created June 26, 2013 04:07
Show Gist options
  • Save rappleg/5864700 to your computer and use it in GitHub Desktop.
Save rappleg/5864700 to your computer and use it in GitHub Desktop.
/**
* Text Me A Picture When There's Motion
*
* Author: SmartThings
*/
preferences {
section("When there's movement..."){
input "motion1", "capability.motionSensor", title: "Front Door"
}
section("Take a picture..."){
input "camera1", "capability.imageCapture", title: "Camera"
}
section("Text me the picture at..."){
input "phone1", "phone", title: "Phone number?"
}
}
def installed()
{
subscribe(motion1, "motion.active", motionActiveHandler)
subscribe(camera1, "image", imageTakeHandler)
}
def updated()
{
unsubscribe()
subscribe(motion1, "motion.active", motionActiveHandler)
subscribe(camera1, "image", imageTakeHandler)
}
def motionActiveHandler(evt) {
log.debug "MOTION ACTIVE - $evt.value: $evt, $settings"
log.debug "$motion1 detected motion, taking picture from $camera1"
camera1.take()
}
def imageTakeHandler(evt) {
def awsPath = evt.value.split(":")
def bucketName = awsPath[0].trim()
def imageName = awsPath[1].trim()
log.debug "Image $imageName captured, texting $phone1"
textShortenedUrl("https://s3.amazonaws.com/" + bucketName + "/" + imageName)
}
def textShortenedUrl(longUrl) {
def response = httpPostJson(uri: 'https://www.googleapis.com', path: '/urlshortener/v1/url', body: [longUrl: longUrl]) { resp ->
def shortUrl = resp.data.id
log.debug "Image url successfully shortened to $shortUrl"
sendSms(phone1, "Image captured: $shortUrl")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment