Checking in all the SmartThings apps; both official and third-party.
[smartapps.git] / third-party / AlarmThing-AlertMotion.groovy
1 /**
2  *  AlarmThing AlertMotion
3  *
4  *  Copyright 2014 ObyCode
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 definition(
17     name: "AlarmThing AlertMotion",
18     namespace: "com.obycode",
19     author: "ObyCode",
20     description: "Alert me when a specific motion sensor on my alarm is activated.",
21     category: "Safety & Security",
22     iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
23     iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png"
24 )
25
26
27 preferences {
28     section("When there is motion on this alarm...") {
29         input "theAlarm", "capability.alarm", multiple: false, required: true
30     }
31     section("for this sensor...") {
32         input "theSensor", "string", multiple: false, required: true
33     }
34     section("push me this message...") {
35         input "theMessage", "string", multiple: false, required: true
36     }
37 }
38
39 def installed() {
40     log.debug "Installed with settings: ${settings}"
41
42     initialize()
43 }
44
45 def updated() {
46     log.debug "Updated with settings: ${settings}"
47
48     unsubscribe()
49     initialize()
50 }
51
52 def initialize() {
53     log.debug "in initialize"
54     subscribe(theAlarm, theSensor + ".active", sensorTriggered)
55 }
56
57 def sensorTriggered(evt) {
58     sendPush(theMessage)
59 }