Update keep-me-cozy-ii.groovy
[smartapps.git] / official / monitor-on-sense.groovy
1 /**
2  *  Monitor on Sense
3  *
4  *  Copyright 2014 Rachel Steele
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: "Monitor on Sense",
18     namespace: "resteele",
19     author: "Rachel Steele",
20     description: "Turn on switch when vibration is sensed",
21     category: "My Apps",
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     oauth: [displayName: "Monitor on Vibrate", displayLink: ""])
25
26
27 preferences {
28         section("When vibration is sensed...") {
29                 input "accelerationSensor", "capability.accelerationSensor", title: "Which Sensor?"
30         }
31 section("Turn on switch...") {
32                 input "switch1", "capability.switch"
33         }
34 }
35
36
37 def installed() {
38         subscribe(accelerationSensor, "acceleration.active", accelerationActiveHandler)
39 }
40
41 def updated() {
42         unsubscribe()
43         subscribe(accelerationSensor, "acceleration.active", accelerationActiveHandler)
44 }
45
46
47 def accelerationActiveHandler(evt) {
48                 switch1.on()
49         }