-
Notifications
You must be signed in to change notification settings - Fork 1
/
amina_s.js
376 lines (329 loc) · 12.8 KB
/
amina_s.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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
const {deviceAddCustomCluster, onOff, binary, numeric, electricityMeter} = require('zigbee-herdsman-converters/lib/modernExtend');
const reporting = require('zigbee-herdsman-converters/lib/reporting');
const constants = require('zigbee-herdsman-converters/lib/constants');
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const utils = require('zigbee-herdsman-converters/lib/utils');
const ota = require('zigbee-herdsman-converters/lib/ota');
const e = exposes.presets;
const ea = exposes.access;
const manufacturerOptions = {manufacturerCode: 0x143B};
const aminaControlAttributes = {
cluster: 0xFEE7,
alarms: 0x02,
ev_status: 0x03,
connect_status: 0x04,
single_phase: 0x05,
offline_current: 0x06,
offline_single_phase: 0x07,
time_to_offline: 0x08,
enable_offline: 0x09,
total_active_energy: 0x10,
last_session_energy: 0x11,
}
const aminaAlarms = ['Welded relay(s)', 'Wrong voltage balance', 'RDC-DD DC Leakage', 'RDC-DD AC Leakage',
'Temperature error', 'Overvoltage alarm', 'Overcurrent alarm', 'Car communication error',
'Charger processing error', 'Critical overcurrent alarm', 'Critical powerloss',];
const DataType = {
UINT32: 35,
UINT16: 33,
UINT8: 0x20,
ENUM8: 0x30,
BITMAP16: 25,
}
const fzLocal = {
ev_status: {
cluster: 'aminaControlCluster',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const result = {};
if (msg.data.evStatus !== undefined) {
let statusText = 'Not Connected';
const evStatus = msg.data['evStatus'];
result.ev_connected = (evStatus & (1 << 0)) !== 0;
result.charging = (evStatus & (1 << 2)) !== 0;
result.derated = (evStatus & (1 << 15)) !== 0;
if (result.ev_connected === true) statusText = 'EV Connected';
if ((evStatus & (1 << 1)) !== 0) statusText = 'Ready to charge';
if (result.charging === true) statusText = 'Charging';
if ((evStatus & (1 << 3)) !== 0) statusText = 'Charging Paused';
if (result.derated === true) statusText += ', Derated';
result.ev_status = statusText;
return result;
}
},
},
alarms: {
cluster: 'aminaControlCluster',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const result = {};
if (msg.data.alarms !== undefined) {
result.alarms = [];
result.alarm_active = false;
for (let i = 0; i < 16; i++) {
if ((msg.data['alarms'] >> i) & 0x01) {
let alarm = aminaAlarms[i];
if (alarm === undefined) {
alarm = `Unknown Alarm bit #${i}`;
}
result.alarms.push(alarm);
result.alarm_active = true;
}
}
if (result.alarm_active === false) {
result.alarms = 'No Alarm';
}
return result;
}
},
}
};
const tzLocal = {
charge_limit: {
key: ['charge_limit'],
convertSet: async (entity, key, value, meta) => {
const payload = {level: value, transtime: 0};
await entity.command('genLevelCtrl', 'moveToLevel', payload, utils.getOptions(meta.mapped, entity));
},
convertGet: async (entity, key, meta) => {
await entity.read('genLevelCtrl', ['currentLevel'], manufacturerOptions);
},
},
ev_status: {
key: ['ev_status'],
convertGet: async (entity, key, meta) => {
await entity.read('aminaControlCluster', ['evStatus'], manufacturerOptions);
},
},
alarms: {
key: ['alarms'],
convertGet: async (entity, key, meta) => {
await entity.read('aminaControlCluster', ['alarms'], manufacturerOptions);
},
},
};
const definition = {
zigbeeModel: ['amina S'],
model: 'amina S',
vendor: 'Amina Distribution AS',
description: 'Amina S EV Charger CUSTOM',
ota: ota.zigbeeOTA,
fromZigbee: [fzLocal.ev_status, fzLocal.alarms],
toZigbee: [tzLocal.ev_status, tzLocal.alarms, tzLocal.charge_limit],
exposes: [
e.text('ev_status', ea.STATE_GET).withDescription('Current charging status'),
e.text('alarms', ea.STATE_GET).withDescription('Alarms reported by EV Charger'),
],
extend: [
deviceAddCustomCluster('aminaControlCluster', {
ID: aminaControlAttributes.cluster,
manufacturerCode: manufacturerOptions.manufacturerCode,
attributes: {
alarms: {ID: aminaControlAttributes.alarms, type: DataType.BITMAP16},
evStatus: {ID: aminaControlAttributes.ev_status, type: DataType.BITMAP16},
connectStatus: {ID: aminaControlAttributes.connect_status, type: DataType.BITMAP16},
singlePhase: {ID: aminaControlAttributes.single_phase, type: DataType.UINT8},
offlineCurrent: {ID: aminaControlAttributes.offline_current, type: DataType.UINT8},
offlineSinglePhase: {ID: aminaControlAttributes.offline_single_phase, type: DataType.UINT8},
timeToOffline: {ID: aminaControlAttributes.time_to_offline, type: DataType.UINT16},
enableOffline: {ID: aminaControlAttributes.enable_offline, type: DataType.UINT8},
totalActiveEnergy: {ID: aminaControlAttributes.total_active_energy, type: DataType.UINT32},
lastSessionEnergy: {ID: aminaControlAttributes.last_session_energy, type: DataType.UINT32},
},
commands: {},
commandsResponse: {},
}),
onOff({
powerOnBehavior: false,
}),
numeric({
name: 'charge_limit',
cluster: 'genLevelCtrl',
attribute: 'currentLevel',
description: 'Maximum allowed amperage draw',
reporting: {min: 0, max: 'MAX', change: 1},
unit: 'A',
valueMin: 6,
valueMax: 32,
valueStep: 1,
access: 'ALL',
}),
numeric({
name: 'total_active_power',
cluster: 'haElectricalMeasurement',
attribute: 'totalActivePower',
description: 'Instantaneous measured total active power',
reporting: {min: '10_SECONDS', max: 'MAX', change: 10},
unit: 'kW',
scale: 1000,
precision: 2,
access: 'STATE_GET',
}),
numeric({
name: 'total_active_energy',
cluster: 'aminaControlCluster',
attribute: 'totalActiveEnergy',
description: 'Sum of consumed energy',
//reporting: {min: '10_SECONDS', max: 'MAX', change: 5}, // Not Reportable atm
unit: 'kWh',
scale: 1000,
precision: 2,
access: 'STATE_GET',
}),
numeric({
name: 'last_session_energy',
cluster: 'aminaControlCluster',
attribute: 'lastSessionEnergy',
description: 'Sum of consumed energy last session',
//reporting: {min: '10_SECONDS', max: 'MAX', change: 5}, // Not Reportable atm
unit: 'kWh',
scale: 1000,
precision: 2,
access: 'STATE_GET',
}),
binary({
name: 'ev_connected',
cluster: 'aminaControlCluster',
attribute: 'evConnected',
description: 'An EV is connected to the charger',
valueOn: ['true', 1],
valueOff: ['false', 0],
access: 'STATE',
}),
binary({
name: 'charging',
cluster: 'aminaControlCluster',
attribute: 'charging',
description: 'Power is being delivered to the EV',
valueOn: ['true', 1],
valueOff: ['false', 0],
access: 'STATE',
}),
binary({
name: 'derated',
cluster: 'aminaControlCluster',
attribute: 'derated',
description: 'Charging derated due to high temperature',
valueOn: ['true', 1],
valueOff: ['false', 0],
access: 'STATE',
}),
binary({
name: 'alarm_active',
cluster: 'aminaControlCluster',
attribute: 'alarmActive',
description: 'An active alarm is present',
valueOn: ['true', 1],
valueOff: ['false', 0],
access: 'STATE',
}),
electricityMeter({
cluster: 'electrical',
acFrequency: true,
threePhase: true,
}),
binary({
name: 'single_phase',
cluster: 'aminaControlCluster',
attribute: 'singlePhase',
description: 'Enable single phase charging. A restart of charging is required for the change to take effect.',
valueOn: ['enable', 1],
valueOff: ['disable', 0],
entityCategory: 'config',
}),
binary({
name: 'enable_offline',
cluster: 'aminaControlCluster',
attribute: 'enableOffline',
description: 'Enable offline mode when connection to the network is lost',
valueOn: ['enable', 1],
valueOff: ['disable', 0],
entityCategory: 'config',
}),
numeric({
name: 'time_to_offline',
cluster: 'aminaControlCluster',
attribute: 'timeToOffline',
description: 'Time until charger will behave as offline after connection has been lost',
valueMin: 0,
valueMax: 60,
valueStep: 1,
unit: 's',
entityCategory: 'config',
}),
numeric({
name: 'offline_current',
cluster: 'aminaControlCluster',
attribute: 'offlineCurrent',
description: 'Maximum allowed amperage draw when device is offline',
valueMin: 6,
valueMax: 32,
valueStep: 1,
unit: 'A',
entityCategory: 'config',
}),
binary({
name: 'offline_single_phase',
cluster: 'aminaControlCluster',
attribute: 'offlineSinglePhase',
description: 'Use single phase charging when device is offline',
valueOn: ['enable', 1],
valueOff: ['disable', 0],
entityCategory: 'config',
}),
],
endpoint: (device) => {
return {default: 10};
},
configure: async (device, coordinatorEndpoint) => {
const endpoint = device.getEndpoint(10);
const binds = ['genBasic', 'genOnOff', 'aminaControlCluster'];
await reporting.bind(endpoint, coordinatorEndpoint, binds);
await endpoint.configureReporting('aminaControlCluster', [
{
attribute: 'evStatus',
minimumReportInterval: 0,
maximumReportInterval: constants.repInterval.MAX,
reportableChange: 1,
},
]);
await endpoint.configureReporting('aminaControlCluster', [
{
attribute: 'alarms',
minimumReportInterval: 0,
maximumReportInterval: constants.repInterval.MAX,
reportableChange: 1,
},
]);
await endpoint.read('aminaControlCluster', [
'alarms',
'evStatus',
'connectStatus',
'singlePhase',
'offlineCurrent',
'offlineSinglePhase',
'timeToOffline',
'enableOffline',
'totalActiveEnergy',
'lastSessionEnergy',
]);
},
onEvent: async (type, data, device) => {
if (
type === 'message' &&
data.type === 'attributeReport' &&
data.cluster === 'haElectricalMeasurement' &&
data.data['totalActivePower']
) {
// Device does not support reporting of energy attributes, so we poll them manually when power is updated
await data.endpoint.read('aminaControlCluster', ['totalActiveEnergy']);
}
if (type === 'message' && data.type === 'attributeReport' && data.cluster === 'aminaControlCluster' && data.data['evStatus']) {
// Device does not support reporting of energy attributes, so we poll them manually when charging is stopped
if ((data.data['evStatus'] & (1 << 2)) === 0) {
await data.endpoint.read('aminaControlCluster', ['totalActiveEnergy', 'lastSessionEnergy']);
}
}
},
};
module.exports = definition;