-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMeter.js
322 lines (294 loc) · 8.11 KB
/
Meter.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
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*
* Homey CommandClass
* Meter
* Versions 1 - 4
*
* JUST FOR REFERENCE!
* Basic knowledge still needed.
*/
/*
* =========== GENERAL CODE: VERSION 1 ===========
* [#CAPABILITY#] = the used capability
* [#TYPESCALE#] = a supported meter scale, displayed below
* Scale = Just the Number (0 - 3)
*
* !! Opional !!
* with Meter Types:
* 'Electric meter'
* 'Gas meter'
* Since there is only 1 Scale, you can have the report parser like this:
* 'command_report_parser': report => report['Meter Value (Parsed)']
*/
[#CAPABILITY#]: {
command_class: 'COMMAND_CLASS_METER',
command_get: 'METER_GET',
command_report: 'METER_REPORT',
command_report_parser: report => {
if (report.hasOwnProperty('Properties1') &&
report.Properties1.hasOwnProperty('Scale') &&
report.Properties1.Scale === [#TYPESCALE#]) {
return report['Meter Value (Parsed)'];
}
return null;
}
}
/*
* =========== GENERAL CODE: VERSION 2 ===========
* [#CAPABILITY#] = the used capability
* [#TYPESCALE#] = a supported scale type, displayed below
* Scale = Just the Number (0 - 3)
*/
[#CAPABILITY#]: {
command_class: 'COMMAND_CLASS_METER',
command_get: 'METER_GET',
command_get_parser: () => ({
Properties1: {
Scale: [#TYPESCALE#],
}
}),
command_report: 'METER_REPORT',
command_report_parser: report => {
if (report.hasOwnProperty('Properties2') &&
report.Properties2.hasOwnProperty('Scale') &&
report.Properties2.Scale === [#TYPESCALE#]) {
return report['Meter Value (Parsed)'];
}
return null;
}
}
/*
* =========== GENERAL CODE: VERSION 3 ===========
* [#CAPABILITY#] = the used capability
* [#TYPESCALE#] = a supported scale type, displayed below
* Scale = Just the Number (0 - 6)
*/
[#CAPABILITY#]: {
command_class: 'COMMAND_CLASS_METER',
command_get: 'METER_GET',
command_get_parser: () => ({
Properties1: {
Scale: [#TYPESCALE#],
}
}),
command_report: 'METER_REPORT',
command_report_parser: report => {
if (report.hasOwnProperty('Properties2') &&
report.Properties2.hasOwnProperty('Scale bits 10') &&
report.Properties2['Scale bits 10'] === [#TYPESCALE#]) {
return report['Meter Value (Parsed)'];
}
return null;
}
}
/*
* =========== GENERAL CODE: VERSION 4 (NO kVar/kVarh Support)===========
* To see if your module has kVar and kVarh support,
* you need to use the "GET SUPPORTED" displayed below
* or look for "'Scale bit 2': false" in DEBUG REPORT
* [#CAPABILITY#] = the used capability
* [#TYPERATE#] = a supported rate type, displayed below
* Rate = Full name
* [#TYPESCALE-1#] = a supported scale type, displayed below
* [#TYPESCALE-2#] = a supported scale type, displayed below
* Scale = Just the Number (0 - 7)
*/
[#CAPABILITY#]: {
command_class: 'COMMAND_CLASS_METER',
command_get: 'METER_GET',
command_get_parser: () => ({
Properties1: {
'Rate Type': '[#TYPERATE#]',
Scale: [#TYPESCALE-2#],
},
'Scale 2': 0,
}),
command_report: 'METER_REPORT',
command_report_parser: report => {
if (report.hasOwnProperty('Properties2') &&
report.Properties2.hasOwnProperty('Scale bits 10') &&
report.Properties2['Scale bits 10'] === [#TYPESCALE-2#]) {
return report['Meter Value (Parsed)'];
}
return null;
}
}
/*
* =========== GENERAL CODE: VERSION 4 (kVar/kVarh Support)===========
* To see if your module has kVar and kVarh support,
* you need to use the "GET SUPPORTED" displayed below
* or look for "'Scale bit 2': true" in DEBUG REPORT
* [#CAPABILITY#] = the used capability
* [#TYPERATE#] = a supported rate type, displayed below
* Rate = Full name
* [#TYPESCALE-1#] = a supported scale type, displayed below
* [#TYPESCALE-2#] = a supported scale type, displayed below
* [#TYPESCALE-3#] = a supported scale type, displayed below
* Scale = Just the Number
*/
[#CAPABILITY#]: {
command_class: 'COMMAND_CLASS_METER',
command_get: 'METER_GET',
command_get_parser: () => ({
Properties1: {
'Rate Type': '[#TYPERATE#]',
Scale: [#TYPESCALE-1#],
},
'Scale 2': [#TYPESCALE-2#],
}),
command_report: 'METER_REPORT',
command_report_parser: report => {
if (report.hasOwnProperty('Properties2') &&
report.Properties2.hasOwnProperty('Scale bits 10') &&
report.Properties2['Scale bits 10'] === [#TYPESCALE-1#] &&
report.hasOwnProperty('Scale 2') &&
report['Scale 2'] === [#TYPESCALE-3#]) {
return report['Meter Value (Parsed)'];
}
return null;
}
}
/*
* =========== GENERAL CODE: GET SUPPORTED TYPES AND SCALES FROM SENSOR ===========
* This will give you all sensor types that are supported by the device in CLI Debug
* !!!!! ONLY SUPPORTED FROM VERSION 2 AND UP !!!!!
*
* [#CAPABILITY#] = the used (temporary) capability
*/
[#CAPABILITY#]: {
command_class: 'COMMAND_CLASS_METER',
command_get: 'METER_SUPPORTED_GET',
command_report: 'METER_SUPPORTED_REPORT'
}
/*
* =========== GENERAL CODE: RESET METER [GET] ===========
* !!!!! THIS WILL RESET ALL ACCUMULATED METER VALUES !!!!!!
* !! ONLY FROM VERSION 2 AND UP !!
* It will activate as soon as the capability is being GET
*
* [#CAPABILITY#] = the used (temporary) capability
*/
[#CAPABILITY#]: {
command_class: 'COMMAND_CLASS_METER',
command_get: 'METER_RESET'
}
/*
* =========== GENERAL CODE: RESET METER [SET] ===========
* !!!!! THIS WILL RESET ALL ACCUMULATED METER VALUES !!!!!!
* !! ONLY FROM VERSION 2 AND UP !!
* It will activate as soon as the capability used is being SET
*
* Make sure the user knows this action can't be reversed
*
* [#CAPABILITY#] = the used (temporary) capability
*/
[#CAPABILITY#]: {
command_class: 'COMMAND_CLASS_METER',
command_set: 'METER_RESET',
command_set_parser: {
return null;
}
}
/*
* =========== GENERAL CODE: RESET METER [FLOW] ===========
* !!!!! THIS WILL RESET ALL ACCUMULATED METER VALUES !!!!!!
* !! ONLY FROM VERSION 2 AND UP !!
*
* Make sure the user knows this action can't be reversed!
*/
// ========== APP.JSON .actions[]: ==========
{
"id": "reset_meter",
"title": {
"en": "Reset power meter (kWh)"
},
"hint": {
"en": "WARNING: This action can't be undone."
},
"args": [
{
"name": "device",
"type": "device",
"filter": "driver_id=DRIVER_ID"
}
]
}
// =========== DRIVER.JS: ==========
Homey.manager('flow').on('action.reset_meter', (callback, args) => {
const node = module.exports.nodes[args.device.token];
if (typeof node.instance.CommandClass.COMMAND_CLASS_METER !== 'undefined') {
node.instance.CommandClass.COMMAND_CLASS_METER.METER_RESET({}, (err, result) => {
if (err) return callback(err, false);
if (result === 'TRANSMIT_COMPLETE_OK') return callback(null, true);
return callback(result, false);
});
} else return callback('device_not_available', false);
});
/*
============ VERSION 1 - 3 =============
* SUPPORTED SENSOR TYPES (*) AND SCALES:
* SCALES FROM VERSION 1 = **---
* SCALES FROM VERSION 2 = ***--
* SCALES FROM VERSION 3 = ****-
* --------------------------------------
* Electric meter
**--- 0 - kilo Watt hours (kWh)
***-- 1 - kiloVolt-Ampere hour (kVAh)
***-- 2 - Wattage (W)
***-- 3 - Pulse Count
****- 4 - Voltage (V)
****- 5 - Amperage (A)
****- 6 - Power Factor
* Gas meter
**--- 0 - Cubic Meters (M³)
***-- 1 - Cubic Feet
***-- 3 - Pulse Count
* Water meter
**--- 0 - Cubic Meters (M³)
**--- 1 - Cubic Feet
**--- 2 - US Gallon
***-- 3 - Pulse Count
============= VERSION 4 ==============
* RATE TYPES (*):
* !! ONLY FROM VERSION 4 !!
* Import
* = Consumed
* Export
* = Produced
* SCALES FROM VERSION 4
- kilo Watt hours (kWh)
[#TYPESCALE-1#]: 0
[#TYPESCALE-2#]: 0
[#TYPESCALE-3#]: 0
- kiloVolt-Ampere hour (kVAh)
[#TYPESCALE-1#]: 0
[#TYPESCALE-2#]: 1
[#TYPESCALE-3#]: 16
- Wattage (W)
[#TYPESCALE-1#]: 0
[#TYPESCALE-2#]: 2
[#TYPESCALE-3#]: 32
- Pulse Count
[#TYPESCALE-1#]: 0
[#TYPESCALE-2#]: 3
[#TYPESCALE-3#]: 48
- Voltage (V)
[#TYPESCALE-1#]: 0
[#TYPESCALE-2#]: 4
[#TYPESCALE-3#]: 64
- Amperage (A)
[#TYPESCALE-1#]: 0
[#TYPESCALE-2#]: 5
[#TYPESCALE-3#]: 80
- Power Factor
[#TYPESCALE-1#]: 0
[#TYPESCALE-2#]: 6
[#TYPESCALE-3#]: 96
- kiloVolt-Ampere reactive (kVar)
[#TYPESCALE-1#]: 0
[#TYPESCALE-2#]: 7
[#TYPESCALE-3#]: 112
- kiloVolt-Ampere reactive/hour (kVarh)
[#TYPESCALE-1#]: 1
[#TYPESCALE-2#]: 7
[#TYPESCALE-3#]: 113
*/