forked from KristopherKubicki/smartapp-camera-motion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera-motion.groovy
83 lines (65 loc) · 2.13 KB
/
camera-motion.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* Camera Motion
*
* Copyright 2015 Kristopher Kubicki
*
*/
definition(
name: "Camera Motion",
namespace: "KristopherKubicki",
author: "[email protected]",
description: "Creates an endpoint for your camera ",
category: "Convenience",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/[email protected]",
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/[email protected]")
preferences {
page(name: "selectDevices", install: false, uninstall: true, nextPage: "viewURL") {
section("Allow endpoint to control this thing...") {
input "motions", "capability.motionSensor", title: "Which simulated motion sensor?"
label title: "Assign a name", required: false
mode title: "Set for specific mode(s)", required: false
}
}
page(name: "viewURL", title: "viewURL", install: true)
}
def installed() {
log.debug "Installed with settings: ${settings}"
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
}
mappings {
path("/active") {
action: [
GET: "activeMotion"
]
}
path("/inactive") {
action: [
GET: "inactiveMotion"
]
}
}
void activeMotion() {
log.debug "Updated2 with settings: ${settings}"
motions?.active()
}
void inactiveMotion() {
log.debug "Updated2 with settings: ${settings}"
motions?.inactive()
}
def generateURL() {
createAccessToken()
["https://graph.api.smartthings.com/api/smartapps/installations/${app.id}/active", "?access_token=${state.accessToken}"]
}
def viewURL() {
dynamicPage(name: "viewURL", title: "HTTP Motion Endpoint", install:!resetOauth, nextPage: resetOauth ? "viewURL" : null) {
section() {
generateURL()
paragraph "Activate: https://graph.api.smartthings.com/api/smartapps/installations/${app.id}/active?access_token=${state.accessToken}"
paragraph "Deactivate: https://graph.api.smartthings.com/api/smartapps/installations/${app.id}/inactive?access_token=${state.accessToken}"
}
}
}