Update gidjit-hub.groovy
[smartapps.git] / official / photo-burst-when.groovy
1 /**
2  *  Copyright 2015 SmartThings
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  *  in compliance with the License. You may obtain a copy of the License at:
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
10  *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
11  *  for the specific language governing permissions and limitations under the License.
12  *
13  *  Photo Burst When...
14  *
15  *  Author: SmartThings
16  *
17  *  Date: 2013-09-30
18  */
19
20 definition(
21     name: "Photo Burst When...",
22     namespace: "smartthings",
23     author: "SmartThings",
24     description: "Take a burst of photos and send a push notification when...",
25     category: "SmartThings Labs",
26     iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/photo-burst-when.png",
27     iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/photo-burst-when@2x.png"
28 )
29
30 preferences {
31         section("Choose one or more, when..."){
32                 input "motion", "capability.motionSensor", title: "Motion Here", required: false, multiple: true
33                 input "contact", "capability.contactSensor", title: "Contact Opens", required: false, multiple: true
34                 input "acceleration", "capability.accelerationSensor", title: "Acceleration Detected", required: false, multiple: true
35                 input "mySwitch", "capability.switch", title: "Switch Turned On", required: false, multiple: true
36                 input "arrivalPresence", "capability.presenceSensor", title: "Arrival Of", required: false, multiple: true
37                 input "departurePresence", "capability.presenceSensor", title: "Departure Of", required: false, multiple: true
38         }
39         section("Take a burst of pictures") {
40                 input "camera", "capability.imageCapture"
41                 input "burstCount", "number", title: "How many? (default 5)", defaultValue:5
42         }
43         section("Then send this message in a push notification"){
44                 input "messageText", "text", title: "Message Text"
45         }
46         section("And as text message to this number (optional)"){
47         input("recipients", "contact", title: "Send notifications to") {
48             input "phone", "phone", title: "Phone Number", required: false
49         }
50         }
51
52 }
53
54 def installed() {
55         log.debug "Installed with settings: ${settings}"
56         subscribeToEvents()
57 }
58
59 def updated() {
60         log.debug "Updated with settings: ${settings}"
61         unsubscribe()
62         subscribeToEvents()
63 }
64
65 def subscribeToEvents() {
66         subscribe(contact, "contact.open", sendMessage)
67         subscribe(acceleration, "acceleration.active", sendMessage)
68         subscribe(motion, "motion.active", sendMessage)
69         subscribe(mySwitch, "switch.on", sendMessage)
70         subscribe(arrivalPresence, "presence.present", sendMessage)
71         subscribe(departurePresence, "presence.not present", sendMessage)
72 }
73
74 def sendMessage(evt) {
75         log.debug "$evt.name: $evt.value, $messageText"
76
77     camera.take()
78         (1..((burstCount ?: 5) - 1)).each {
79                 camera.take(delay: (500 * it))
80         }
81
82     if (location.contactBookEnabled) {
83         sendNotificationToContacts(messageText, recipients)
84     }
85     else {
86         sendPush(messageText)
87         if (phone) {
88             sendSms(phone, messageText)
89         }
90     }
91 }