Created
March 20, 2016 21:27
-
-
Save sidoh/9e621af33277f3fa450a 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
/** | |
* Copyright 2015 SmartThings | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
* in compliance with the License. You may obtain a copy of the License at: | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed | |
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License | |
* for the specific language governing permissions and limitations under the License. | |
* | |
* Lights Off, When Closed | |
* | |
* Author: SmartThings | |
*/ | |
definition( | |
name: "Enter Photo", | |
namespace: "sidoh", | |
author: "sidoh", | |
description: "Take a picture when a door opens", | |
category: "Convenience", | |
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_contact-outlet.png", | |
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/[email protected]" | |
) | |
preferences { | |
section ("When the door closes...") { | |
input "contact1", "capability.contactSensor", title: "Where?" | |
} | |
section ("Take a picture...") { | |
input "camera1", "capability.imageCapture" | |
} | |
section ("Turn switches...") { | |
input "switches", "capability.switch", required: false, multiple: true | |
} | |
section("When all of these people are away") { | |
input "people", "capability.presenceSensor", multiple: true, required: false | |
} | |
} | |
def installed() | |
{ | |
subscribe(contact1, "contact.open", contactHandler) | |
} | |
def updated() | |
{ | |
unsubscribe() | |
subscribe(contact1, "contact.open", contactHandler) | |
} | |
def contactHandler(evt) { | |
if (everyoneIsAway()) { | |
log.info "Everyone is away. Taking a picture." | |
camera1.take() | |
for (s in switches) { | |
s.on() | |
} | |
sendPush("Security camera triggered. Recording enabled.") | |
} | |
} | |
private everyoneIsAway() { | |
for (person in people) { | |
if (person.currentPresence == "present") { | |
log.info "${person} is present." | |
return false | |
} | |
} | |
log.debug "everyoneIsAway: $result" | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment