Update double-tap.groovy
[smartapps.git] / official / jawbone-button-notifier.groovy
1 /**
2  *  Jawbone Panic Button
3  *
4  *  Copyright 2014 Juan Risso
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7  *  in compliance with the License. You may obtain a copy of the License at:
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
12  *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
13  *  for the specific language governing permissions and limitations under the License.
14  *
15  */
16
17 // Automatically generated. Make future change here.
18 definition(
19     name: "Jawbone Button Notifier",
20     namespace: "juano2310",
21     author: "Juan Risso",
22     category: "SmartThings Labs",
23     description: "Send push notifications or text messages with your Jawbone Up when you hold the button.",
24         iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/jawbone-up.png",
25         iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/jawbone-up@2x.png",
26 )
27
28 preferences {
29         section("Use this Jawbone as a notification button and...") {
30                 input "jawbone", "device.jawboneUser", multiple: true
31         }
32     section("Send a message when you press and hold the button...") {
33         input "warnMessage", "text", title: "Warning Message"
34     }
35     section("Or text message to these numbers (optional)") {
36         input ("phone1", "contact", required: false) {
37                 input "phone1", "phone", required: false
38         }
39         input ("phone2", "contact", required: false) {
40                 input "phone2", "phone", required: false
41         }
42         input ("phone3", "contact", required: false) {
43                 input "phone3", "phone", required: false
44         }
45     }
46 }
47
48 def installed() {
49         log.debug "Installed with settings: ${settings}"
50         initialize()
51 }
52
53 def updated() {
54         log.debug "Updated with settings: ${settings}"
55
56         unsubscribe()
57         initialize()
58 }
59
60 def initialize() {
61         subscribe(jawbone, "sleeping", sendit)
62 }
63
64 def sendit(evt) {
65         log.debug "$evt.value: $evt"
66         sendMessage()
67 }
68
69 def sendMessage() {
70         log.debug "Sending Message"
71         def msg = warnMessage
72     log.info msg
73     if (phone1) {
74         sendSms phone1, msg
75     }
76     if (phone2) {
77         sendSms phone2, msg
78     }
79     if (phone3) {
80         sendSms phone3, msg
81     }
82     if (!phone1 && !phone2 && !phone3) {
83         sendPush msg
84     }
85 }