-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCentral Scene.js
244 lines (234 loc) · 6.96 KB
/
Central Scene.js
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
/*
* Homey CommandClass
* Central Scene
* Version 1 - 3
* Flow trigger only
*
* JUST FOR REFERENCE!
* Basic knowledge still needed.
*/
/*
* ============================================ APP.JSON SEPARATE ============================================
* TRIGGER_ID = Unique id (for the app) of the flow card
* DRIVER_ID = The unique id of the driver
*/
{
"id": "TRIGGER_ID",
"title": {
"en": "FLOW_CARD_TITLE"
},
"hint": {
"en": "FLOW_CARD_HINT" // OPTIONAL
},
"args": [
{
"name": "device",
"type": "device",
"filter": "driver_id=DRIVER_ID"
}
]
}
/*
* ============================================ DRIVER.JS SEPARATE ============================================
* TRIGGER_ID = Unique id (for the app) of the flow card
* ACTIVATION_ID = The supported activation spot, this is optional if there is only 1 activation spot
* ATTRIBUTE = The attribute of the button press, IE: 1x click, hold, release, supported types displayed below
*/
module.exports.on('initNode', (token) => {
const node = module.exports.nodes[token];
if (node && typeof node.instance.CommandClass.COMMAND_CLASS_CENTRAL_SCENE !== 'undefined') {
node.instance.CommandClass.COMMAND_CLASS_CENTRAL_SCENE.on('report', (command, report) => {
if (command &&
command.name === 'CENTRAL_SCENE_NOTIFICATION' &&
report &&
report.hasOwnProperty('Scene Number') && // Optional for 1 activation spot
report['Scene Number'] === ACTIVATION_ID && // Optional for 1 activation spot
report.hasOwnProperty('Properties1') &&
report.Properties1.hasOwnProperty('Key Attributes') &&
report.Properties1['Key Attributes'] === ATTRIBUTE) {
Homey.manager('flow').triggerDevice('TRIGGER_ID', null, data, node.device_data);
}
});
}
});
/*
* ============================================ APP.JSON SINGLE DROPDOWN ============================================
* TRIGGER_ID = Unique id (for the app) of the flow card
* DRIVER_ID = The unique id of the driver
* ATTRIBUTE = The attribute of the button press, IE: 1x click, hold, release, supported types displayed below
*/
{
"id": "TRIGGER_ID",
"title": {
"en": "FLOW_CARD_TITLE"
},
"hint": {
"en": "FLOW_CARD_HINT" // OPTIONAL
},
"args": [
{
"name": "device",
"type": "device",
"filter": "driver_id=DRIVER_ID"
},
{
"name": "attribute",
"type": "dropdown",
"values": [
{
"id": "ATTRIBUTE_1",
"label": {
"en": "ATTRIBUTE_1_LABEL"
}
},
{
"id": "ATTRIBUTE_2",
"label": {
"en": "ATTRIBUTE_2_LABEL"
}
}
]
}
]
}
/*
* ============================================ DRIVER.JS SINGLE DROPDOWN ============================================
* TRIGGER_ID = Unique id (for the app) of the flow card
* ACTIVATION_ID = The supported activation spot, this is optional if there is only 1 activation spot
*/
module.exports.on('initNode', (token) => {
const node = module.exports.nodes[token];
if (node && typeof node.instance.CommandClass.COMMAND_CLASS_CENTRAL_SCENE !== 'undefined') {
node.instance.CommandClass.COMMAND_CLASS_CENTRAL_SCENE.on('report', (command, report) => {
if (command &&
command.name === 'CENTRAL_SCENE_NOTIFICATION' &&
report &&
report.hasOwnProperty('Scene Number') && // Optional for 1 activation spot
report['Scene Number'] === ACTIVATION_ID && // Optional for 1 activation spot
report.hasOwnProperty('Properties1') &&
report.Properties1.hasOwnProperty('Key Attributes')) {
const data = {
attribute: report.Properties1['Key Attributes'] // This will be the attribute of the press (amount/hold/release)
}
Homey.manager('flow').triggerDevice('TRIGGER_ID', null, data, node.device_data);
}
});
}
});
// This part will make sure the send data is the same as te data selected in the flow card(s)
Homey.manager('flow').on('trigger.TRIGGER_ID', (callback, args, state) => {
if(args &&
state &&
args.hasOwnProperty('attribute') &&
state.hasOwnProperty('attribute') &&
args.attribute === state.attribute) {
return callback(null, true);
} else return callback('unknown_error', false);
});
/*
* ============================================ APP.JSON COMBINATION DROPDOWN ============================================
* TRIGGER_ID = Unique id (for the app) of the flow card
* DRIVER_ID = The unique id of the driver
* ACTIVATION_ID = The supported activation spot
* ATTRIBUTE = The attribute of the button press, IE: 1x click, hold, release, supported types displayed below
*/
{
"id": "TRIGGER_ID",
"title": {
"en": "FLOW_CARD_TITLE"
},
"hint": {
"en": "FLOW_CARD_HINT" // OPTIONAL
},
"args": [
{
"name": "device",
"type": "device",
"filter": "driver_id=DRIVER_ID"
},
{
"name": "activation",
"type": "dropdown",
"values": [
{
"id": "ACTIVATION_ID_1",
"label": {
"en": "ACTIVATION_ID_1_LABEL"
}
},
{
"id": "ACTIVATION_ID_2",
"label": {
"en": "ACTIVATION_ID_2_LABEL"
}
}
]
},
{
"name": "attribute",
"type": "dropdown",
"values": [
{
"id": "ATTRIBUTE_1",
"label": {
"en": "ATTRIBUTE_1_LABEL"
}
},
{
"id": "ATTRIBUTE_2",
"label": {
"en": "ATTRIBUTE_2_LABEL"
}
}
]
}
]
}
/*
* ============================================ DRIVER.JS COMBINATION DROPDOWN ============================================
* TRIGGER_ID = Unique id (for the app) of the flow card
*/
module.exports.on('initNode', (token) => {
const node = module.exports.nodes[token];
if (node && typeof node.instance.CommandClass.COMMAND_CLASS_CENTRAL_SCENE !== 'undefined') {
node.instance.CommandClass.COMMAND_CLASS_CENTRAL_SCENE.on('report', (command, report) => {
if (command &&
command.name === 'CENTRAL_SCENE_NOTIFICATION' &&
report &&
report.hasOwnProperty('Scene Number') && // Optional for 1 activation spot
report.hasOwnProperty('Properties1') &&
report.Properties1.hasOwnProperty('Key Attributes')) {
const data = {
activation: report['Scene Number'].toString(), // This will be the id of the activation spot
attribute: report.Properties1['Key Attributes'] // This will be the attribute of the press (amount/hold/release)
}
Homey.manager('flow').triggerDevice('TRIGGER_ID', null, data, node.device_data);
}
});
}
});
// This part will make sure the send data is the same as te data selected in the flow card(s)
Homey.manager('flow').on('trigger.TRIGGER_ID', (callback, args, state) => {
if(args &&
state &&
args.hasOwnProperty('activation') &&
args.hasOwnProperty('attribute') &&
state.hasOwnProperty('activation') &&
state.hasOwnProperty('attribute') &&
args.activation === state.activation &&
args.attribute === state.attribute) {
return callback(null, true);
} else return callback('unknown_error', false);
});
/*
* SUPPORTED CENTRAL SCENE ATTRIBUTES:
* ---------- FROM VERSION 1 ----------
* Key Pressed 1 time
* Key Released
* Key Held Down
*
* ---------- FROM VERSION 2----------
* Key Pressed 2 times
* Key Pressed 3 times
* Key Pressed 4 times
* Key Pressed 5 times