forked from SANdood/smartthings-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuperStateSwitch.groovy
77 lines (74 loc) · 2.68 KB
/
superStateSwitch.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
metadata {
definition (name: "superState switch", namespace: "mmaxwell", author: "Mike Maxwell") {
capability "Switch"
command "snap"
command "overrideScene"
command "warn"
}
//preferences {
// input name: "stateRestore", type: "bool", title: "Restore device states when scene is turned off?"
//}
simulator {
}
tiles {
standardTile("button", "device.switch", width: 2, height: 2, canChangeIcon: true, canChangeBackground: true) {
state "off", label: 'Off', action: "switch.on", icon: "st.illuminance.illuminance.dark", backgroundColor: "#ffffff" //, nextState: "on"
state "warn", label: "Warn", action: "switch.off", icon: "st.illuminance.illuminance.dark", backgroundColor: "#f1d801"
state "on", label: 'On', action: "switch.off", icon: "st.illuminance.illuminance.dark", backgroundColor: "#79b821" //, nextState: "off"
}
standardTile("snap", "device.switch", width: 1, height: 1, canChangeIcon: false,decoration: "flat") {
state "default", label: 'Snap', action: "snap", icon: "st.camera.take-photo", backgroundColor: "#ffffff"
}
main "button"
details "button","snap"
}
}
def parse(String description) {
}
def warn(){
return sendEvent(name: "switch", value: "warn", data: "~warn~")
}
def snap(){
//log.debug "snap request"
on("snap")
}
def on(action) {
if (!action) {
//log.debug "superState ${device.displayName}:on"
return sendEvent(name: "switch", value: "on", data: "~on~")
} else {
//log.debug "superState ${device.displayName}:on-${action}"
return sendEvent(name: "switch", isStateChange: true, value: "on", data: "~${action}~")
//return sendEvent(name: "switch", value: "on", data: "~${action}~")
}
}
def off(action) {
if (!action) {
if ((settings.stateRestore ?: "false") == "true") {
//log.debug "superState ${device.displayName}:off-restore"
return sendEvent(name: "switch", value: "off", data: "~restore~")
} else {
//log.debug "superState ${device.displayName}:off"
return sendEvent(name: "switch", value: "off", data: "~off~")
}
} else {
//log.debug "superState ${device.displayName}:off-${action}"
return sendEvent(name: "switch", value: "off", data: "~${action}~")
}
}
def overrideScene(){
off("override")
}
/*
need to test these out on the other end
sendEvent
isStateChange: true|false
isPhysical: true|false
description: raw event text
descriptionText: user display text
name: event display name
source: APP, APP_COMMAND, COMMAND, DEVICE, HUB, or LOCATION (no idea how this works)
value: event value (string)
displayed: true|false hide from activity panel or not
data: arbitrary data string
*/