-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMoes-2-gang-dimmer.groovy
307 lines (257 loc) · 10.6 KB
/
Moes-2-gang-dimmer.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/*
* Moes ZigBee Switch
*
* Copyright 2020 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.
*
*/
public static String version() { return "v0.0.1.20210727" }
private getMODEL_MAP() {
[
'TS0601' : 3
]
}
metadata {
definition(name: "Moes ZigBee Switch", namespace: "Moes", author: "Pumba", ocfDeviceType: "oic.d.light", vid: "Light") {
capability "Actuator"
capability "Configuration"
capability "Refresh"
capability "Health Check"
capability "Switch"
capability "Switch Level"
command "childOn", ["string"]
command "childOff", ["string"]
command "childSetLevel", ["string", "string"]
//Moeshouse Switch
// 1 gang
fingerprint profileId: "0104", model: "TS0601", manufacturer: "_TZE200_amp6tsvy", endpointId: "01", inClusters: "0000,0004,0005,EF00", outClusters: "0019,000A", application: "42", deviceJoinName: "Moes Multi Switch 1"
// 2 gang dimmer
fingerprint profileId: "0104", model: "TS0601", manufacturer: "_TZE200_e3oitdyu", endpointId: "01", inClusters: "0000,0004,0005,EF00", outClusters: "0019,000A", application: "44", deviceJoinName: "Moes Multi Switch 1"
// 3 gang
fingerprint profileId: "0104", model: "TS0601", manufacturer: "_TZE200_tz32mtza", endpointId: "01", inClusters: "0000,0004,0005,EF00", outClusters: "0019,000A", application: "42", deviceJoinName: "Moes Multi Switch 1"
}
}
// Tile
tiles(scale: 2) {
multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true){
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
attributeState "on", label:'${name}', action:"switch.off", icon:"st.switches.light.on", backgroundColor:"#00A0DC", nextState:"turningOff"
attributeState "off", label:'${name}', action:"switch.on", icon:"st.switches.light.off", backgroundColor:"#ffffff", nextState:"turningOn"
attributeState "turningOn", label:'${name}', action:"switch.off", icon:"st.switches.light.on", backgroundColor:"#00A0DC", nextState:"turningOff"
attributeState "turningOff", label:'${name}', action:"switch.on", icon:"st.switches.light.off", backgroundColor:"#ffffff", nextState:"turningOn"
}
tileAttribute ("device.level", key: "SLIDER_CONTROL") {
attributeState "level", action:"switch level.setLevel"
}
}
standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
}
main "switch"
// details(["switch", "refresh"])
details(["switch", "refresh", "level"])
}
def installed() {
//createChildDevices()
updateDataValue("onOff", "catchall")
refresh()
}
// Parse incoming device messages to generate events
def parse(String description) {
Map map = [:]
//def event = zigbee.getEvent(description)
if (description?.startsWith('catchall:')) {
log.debug description
// call parseCatchAllMessage to parse the catchall message received
map = parseCatchAllMessage(description)
if (map != [:]) {
log.debug "ok send event: $map.name $map.value"
sendEvent(name: map.name, value: map.value)
}
}
else {
log.warn "DID NOT PARSE MESSAGE for description : $description"
}
}
private getChildEndpoint(String dni) {
dni.split(":")[-1] as Integer
}
def off() {
log.debug "called off"
zigbee.command(0xEF00, 0x0, "00010101000100") //kanaal 1
}
def on() {
log.debug "called on"
zigbee.command(0xEF00, 0x0, "00010101000101") //kanaal 1
}
def setLevel(value) {
log.debug "called setLevel with value $value"
if (value >= 0 && value <= 100) {
Map commandParams = [:]
String commandPayload = "0001020200040000" + zigbee.convertToHexString((value * 10) as Integer, 4) //kanaal 1
zigbee.command(0xEF00, 0x0, commandPayload)
}
}
def refresh() {
log.debug "called refresh"
zigbee.command(0xEF00, 0x0, "00020100")
//pauseExecution(1000)
//zigbee.command(0xEF00, 0x0, "0002020200")
}
def childOn(String dni) {
def childEndpoint = getChildEndpoint(dni)
def name = dni.split("-")[-1]
def cmd = zigbee.smartShield(text: "${name} on").format()
sendHubCommand(new physicalgraph.device.HubAction(cmd))
log.debug(" child on ${dni} ${childEndpoint} ")
zigbee.command(0xEF00, 0x0, "00000701000101") //kanaal 2
}
def childOff(String dni) {
def childEndpoint = getChildEndpoint(dni)
def name = dni.split("-")[-1]
def cmd = zigbee.smartShield(text: "${name} off").format()
sendHubCommand(new physicalgraph.device.HubAction(cmd))
log.debug " child off ${dni} ${childEndpoint} "
zigbee.command(0xEF00, 0x0, "00000701000100") //kanaal 2
}
def childSetLevel (String dni, Integer value) {
log.debug "called setLevel with value $value"
if (value >= 0 && value <= 100) {
Map commandParams = [:]
String commandPayload = "0000080200040000" + zigbee.convertToHexString((value * 10) as Integer, 4) //kanaal 2 ?
zigbee.command(0xEF00, 0x0, commandPayload)
}
}
def configure() {
log.debug "Configuring Reporting and Bindings."
zigbee.onOffConfig() + zigbee.levelConfig() + zigbee.onOffRefresh() + zigbee.levelRefresh()
}
private Map parseCatchAllMessage(String description) {
// Create a map from the raw zigbee message to make parsing more intuitive
def msg = zigbee.parse(description)
Map result = [:]
switch(msg.clusterId) {
case 0xEF00:
def attribute = getAttribute(msg.data)
def value = getAttributeValue(msg.data)
log.debug "173 Atribute ${attribute} AttributeValue ${value}"
switch (attribute) {
case "switch":
switch(value) {
case 0:
result = [
name: 'switch',
value: 'off',
data: [buttonNumber: 1],
descriptionText: "${device.displayName} button was pressed",
isStateChange: true
]
log.debug "185 ${device.displayName} button was pressed"
break;
case 1:
result = [
name: 'switch',
value: 'on',
data: [buttonNumber: 1],
descriptionText: "${device.displayName} button was pressed",
isStateChange: true
]
log.debug "${device.displayName} button was pressed"
log.debug "297 ${result}"
break;
}
break;
case "switch2":
switch(value) {
case 0:
result = [
name: 'switch2',
value: 'off',
data: [buttonNumber: 7],
descriptionText: "${device.displayName} button was pressed",
isStateChange: true
]
log.debug "214 ${device.displayName} button was pressed"
break;
case 1:
result = [
name: 'switch2',
value: 'on',
data: [buttonNumber: 7],
descriptionText: "${device.displayName} button was pressed",
isStateChange: true
]
log.debug "${device.displayName} button was pressed"
log.debug "227 ${result}"
break;
}
case "level":
int levelValue = value / 10
result = [
name: 'level',
value: levelValue,
data: [buttonNumber: 1],
descriptionText: "${device.displayName} level was modified",
isStateChange: true
]
log.debug "241 result ${result}"
break;
case "level2":
int levelValue = value / 10
result = [
name: 'level2',
value: levelValue,
data: [buttonNumber: 7],
descriptionText: "${device.displayName} level was modified",
isStateChange: true
]
log.debug "254 result ${result}"
break;
}
break;
}
return result
}
private String getAttribute(ArrayList _data) {
log.debug "282 data:${_data}"
String retValue = ""
if (_data[1] >0) {
if (_data[2] == 2 && _data[3] == 2 && _data[4] == 0) {
retValue = "level"
}
if (_data[2] == 1 && _data[3] == 1 && _data[4] == 0) {
retValue = "switch"
}
if (_data[2] == 8 && _data[3] == 2 && _data[4] == 0) {
retValue = "level2"
}
if (_data[2] == 7 && _data[3] == 1 && _data[4] == 0) {
retValue = "switch2"
}
}
log.debug "301 return ${retValue}"
return retValue
}
private int getAttributeValue(ArrayList _data) {
int retValue = 0
if (_data.size() >= 6) {
int dataLength = _data[5] as Integer
int power = 1;
for (i in dataLength..1) {
retValue = retValue + power * _data[i+5]
power = power * 256
}
}
return retValue
}