-
Notifications
You must be signed in to change notification settings - Fork 90.1k
/
aeon-minimote.groovy
160 lines (143 loc) · 5.94 KB
/
aeon-minimote.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import groovy.json.JsonOutput
/**
* Copyright 2015 SmartThings
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
*/
metadata {
definition (name: "Aeon Minimote", namespace: "smartthings", author: "SmartThings", runLocally: true, minHubCoreVersion: '000.017.0012', executeCommandsLocally: false, mcdSync: true, ocfDeviceType: "x.com.st.d.remotecontroller") {
capability "Actuator"
capability "Button"
capability "Holdable Button"
capability "Configuration"
capability "Sensor"
capability "Health Check"
fingerprint mfr: "0086", prod: "0001", model:"0003", deviceJoinName: "Aeon Remote Control"
}
simulator {
status "button 1 pushed": "command: 2001, payload: 01"
status "button 1 held": "command: 2001, payload: 15"
status "button 2 pushed": "command: 2001, payload: 29"
status "button 2 held": "command: 2001, payload: 3D"
status "button 3 pushed": "command: 2001, payload: 51"
status "button 3 held": "command: 2001, payload: 65"
status "button 4 pushed": "command: 2001, payload: 79"
status "button 4 held": "command: 2001, payload: 8D"
status "wakeup": "command: 8407, payload: "
}
tiles(scale: 2) {
multiAttributeTile(name: "rich-control", type: "generic", width: 6, height: 4, canChangeIcon: true) {
tileAttribute("device.button", key: "PRIMARY_CONTROL") {
attributeState "default", label: ' ', action: "", icon: "st.unknown.zwave.remote-controller", backgroundColor: "#ffffff"
}
}
childDeviceTiles("outlets")
}
}
def parse(String description) {
def results = []
if (description.startsWith("Err")) {
results = createEvent(descriptionText:description, displayed:true)
} else {
def cmd = zwave.parse(description, [0x2B: 1, 0x80: 1, 0x84: 1])
if(cmd) results += zwaveEvent(cmd)
if(!results) results = [ descriptionText: cmd, displayed: false ]
}
return results
}
def zwaveEvent(physicalgraph.zwave.commands.wakeupv1.WakeUpNotification cmd) {
def results = [createEvent(descriptionText: "$device.displayName woke up", isStateChange: false)]
results += configurationCmds().collect{ response(it) }
results << response(zwave.wakeUpV1.wakeUpNoMoreInformation().format())
return results
}
def buttonEvent(button, held) {
button = button as Integer
String childDni = "${device.deviceNetworkId}/${button}"
def child = childDevices.find{it.deviceNetworkId == childDni}
if (!child) {
log.error "Child device $childDni not found"
}
if (held) {
if (child) child.sendEvent(name: "button", value: "held", data: [buttonNumber: 1], descriptionText: "$child.displayName was held", isStateChange: true)
createEvent(name: "button", value: "held", data: [buttonNumber: button], descriptionText: "$device.displayName button $button was held", isStateChange: true)
} else {
if (child) child.sendEvent(name: "button", value: "pushed", data: [buttonNumber: 1], descriptionText: "$child.displayName was pushed", isStateChange: true)
createEvent(name: "button", value: "pushed", data: [buttonNumber: button], descriptionText: "$device.displayName button $button was pushed", isStateChange: true)
}
}
def zwaveEvent(physicalgraph.zwave.commands.sceneactivationv1.SceneActivationSet cmd) {
Integer button = ((cmd.sceneId + 1) / 2) as Integer
Boolean held = !(cmd.sceneId % 2)
buttonEvent(button, held)
}
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) {
Integer button = (cmd.value / 40 + 1) as Integer
Boolean held = (button * 40 - cmd.value) <= 20
buttonEvent(button, held)
}
def zwaveEvent(physicalgraph.zwave.Command cmd) {
[ descriptionText: "$device.displayName: $cmd", linkText:device.displayName, displayed: false ]
}
def configurationCmds() {
def cmds = []
def hubId = zwaveHubNodeId
(1..4).each { button ->
cmds << zwave.configurationV1.configurationSet(parameterNumber: 240+button, scaledConfigurationValue: 1).format()
}
(1..4).each { button ->
cmds << zwave.configurationV1.configurationSet(parameterNumber: (button-1)*40, configurationValue: [hubId, (button-1)*40 + 1, 0, 0]).format()
cmds << zwave.configurationV1.configurationSet(parameterNumber: (button-1)*40 + 20, configurationValue: [hubId, (button-1)*40 + 21, 0, 0]).format()
}
cmds
}
def configure() {
def cmds = configurationCmds()
log.debug("Sending configuration: $cmds")
return cmds
}
def installed() {
initialize()
if (!childDevices) {
createChildDevices()
}
}
def updated() {
initialize()
if (!childDevices) {
createChildDevices()
} else if (device.label != state.oldLabel) {
childDevices.each {
def segs = it.deviceNetworkId.split("/")
def newLabel = "${device.displayName} button ${segs[-1]}"
it.setLabel(newLabel)
}
state.oldLabel = device.label
} else {
childDevices.each {
it.sendEvent(name: "supportedButtonValues", value: ["pushed","held"].encodeAsJson(), displayed: false)
}
}
}
def initialize() {
sendEvent(name: "numberOfButtons", value: 4)
sendEvent(name: "DeviceWatch-Enroll", value: JsonOutput.toJson([protocol: "zwave", scheme:"untracked"]), displayed: false)
sendEvent(name: "supportedButtonValues", value: ["pushed","held"].encodeAsJson(), displayed: false)
}
private void createChildDevices() {
state.oldLabel = device.label
for (i in 1..4) {
def child = addChildDevice("Child Button", "${device.deviceNetworkId}/${i}", device.hubId,
[completedSetup: true, label: "${device.displayName} button ${i}",
isComponent: true, componentName: "button$i", componentLabel: "Button $i"])
child.sendEvent(name: "supportedButtonValues", value: ["pushed","held"].encodeAsJson(), displayed: false)
}
}