-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathDIYRuZ_Zintercom.js
210 lines (187 loc) · 7.48 KB
/
DIYRuZ_Zintercom.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
const zigbeeHerdsmanConverters = require('zigbee-herdsman-converters');
const exposes = zigbeeHerdsmanConverters['exposes'] || require("zigbee-herdsman-converters/lib/exposes");
const ep = exposes.presets;
const ea = exposes.access;
const fromZigbeeConverters = zigbeeHerdsmanConverters.fromZigbeeConverters || zigbeeHerdsmanConverters.fromZigbee;
const toZigbeeConverters = zigbeeHerdsmanConverters.toZigbeeConverters || zigbeeHerdsmanConverters.toZigbee;
const bind = async (endpoint, target, clusters) => {
for (const cluster of clusters) {
await endpoint.bind(cluster, target);
}
};
const configureReporting = {
currentPositionLiftPercentage: async (endpoint, overrides) => {
const payload = configureReportingPayload('currentPositionLiftPercentage', 1, repInterval.MAX, 1, overrides);
await endpoint.configureReporting('closuresWindowCovering', payload);
},
batteryPercentageRemaining: async (endpoint, overrides) => {
const payload = configureReportingPayload(
'batteryPercentageRemaining', repInterval.HOUR, repInterval.MAX, 0, overrides,
);
await endpoint.configureReporting('genPowerCfg', payload);
},
batteryVoltage: async (endpoint, overrides) => {
const payload = configureReportingPayload('batteryVoltage', repInterval.HOUR, repInterval.MAX, 0, overrides);
await endpoint.configureReporting('genPowerCfg', payload);
},
}
const configureReportingPayload = (attribute, min, max, change, overrides) => {
const payload = {
attribute: attribute,
minimumReportInterval: min,
maximumReportInterval: max,
reportableChange: change,
};
if (overrides) {
if (overrides.hasOwnProperty('min')) payload.minimumReportInterval = overrides.min;
if (overrides.hasOwnProperty('max')) payload.maximumReportInterval = overrides.max;
if (overrides.hasOwnProperty('change')) payload.reportableChange = overrides.change;
}
return [payload];
};
const repInterval = {
MAX: 62000,
HOUR: 3600,
MINUTES_30: 1800,
MINUTES_15: 900,
MINUTES_10: 600,
MINUTES_5: 300,
MINUTE: 60,
};
const fz = {
diy_zintercom_config: {
cluster: 'closuresDoorLock',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const result = {};
if (msg.data.hasOwnProperty(0x0050)) {
result.state = ['Idle', 'Ring', 'Talk', 'Open', 'Drop'][msg.data[0x0050]];
}
if (msg.data.hasOwnProperty(0x0051)) {
result.mode = ['Never', 'Once', 'Always', 'Drop'][msg.data[0x0051]];
}
if (msg.data.hasOwnProperty(0x0052)) {
result.sound = ['OFF', 'ON'][msg.data[0x0052]];
}
if (msg.data.hasOwnProperty(0x0053)) {
result.time_ring = msg.data[0x0053];
}
if (msg.data.hasOwnProperty(0x0054)) {
result.time_talk = msg.data[0x0054];
}
if (msg.data.hasOwnProperty(0x0055)) {
result.time_open = msg.data[0x0055];
}
if (msg.data.hasOwnProperty(0x0057)) {
result.time_bell = msg.data[0x0057];
}
if (msg.data.hasOwnProperty(0x0056)) {
result.time_report = msg.data[0x0056];
}
return result;
},
},
}
const tz = {
diy_zintercom_config: {
key: ['state', 'mode', 'sound', 'time_ring', 'time_talk', 'time_open', 'time_bell', 'time_report'],
convertSet: async (entity, key, rawValue, meta) => {
const lookup = {
'OFF': 0x00,
'ON': 0x01,
};
const modeOpenLookup = {
'Never': '0',
'Once': '1',
'Always': '2',
'Drop': '3',
};
let value = lookup.hasOwnProperty(rawValue) ? lookup[rawValue] : parseInt(rawValue, 10);
if (key == 'mode') {
value = modeOpenLookup.hasOwnProperty(rawValue) ? modeOpenLookup[rawValue] : parseInt(rawValue, 10);
}
const payloads = {
mode: {0x0051: {value, type: 0x30}},
sound: {0x0052: {value, type: 0x10}},
time_ring: {0x0053: {value, type: 0x20}},
time_talk: {0x0054: {value, type: 0x20}},
time_open: {0x0055: {value, type: 0x20}},
time_bell: {0x0057: {value, type: 0x20}},
time_report: {0x0056: {value, type: 0x20}},
};
await entity.write('closuresDoorLock', payloads[key]);
return {
state: {[key]: rawValue},
};
},
convertGet: async (entity, key, meta) => {
const payloads = {
state: ['closuresDoorLock', 0x0050],
mode: ['closuresDoorLock', 0x0051],
sound: ['closuresDoorLock', 0x0052],
time_ring: ['closuresDoorLock', 0x0053],
time_talk: ['closuresDoorLock', 0x0054],
time_open: ['closuresDoorLock', 0x0055],
time_bell: ['closuresDoorLock', 0x0057],
time_report: ['closuresDoorLock', 0x0056],
};
await entity.read(payloads[key][0], [payloads[key][1]]);
},
},
}
const device = {
zigbeeModel: ['DIY_Zintercom'],
model: 'DIYRuZ_Zintercom',
vendor: 'DIYRuZ',
description: '[Matrix intercom auto opener](https://diyruz.github.io/posts/zintercom/)',
icon: 'https://raw.githubusercontent.com/diyruz/Zintercom/master/images/z2m.png',
fromZigbee: [
fromZigbeeConverters.battery,
fz.diy_zintercom_config,
],
toZigbee: [
toZigbeeConverters.factory_reset,
tz.diy_zintercom_config,
],
meta: {
configureKey: 1,
},
configure: async (device, coordinatorEndpoint) => {
const firstEndpoint = device.getEndpoint(1);
await bind(firstEndpoint, coordinatorEndpoint, ['closuresDoorLock', 'genPowerCfg']);
const overides = {min: 0, max: 3600, change: 0};
await configureReporting.batteryVoltage(firstEndpoint, overides);
await configureReporting.batteryPercentageRemaining(firstEndpoint, overides);
const payload = [{
attribute: {
ID: 0x0050,
type: 0x30,
},
minimumReportInterval: 0,
maximumReportInterval: 3600,
reportableChange: 0,
},
];
await firstEndpoint.configureReporting('closuresDoorLock', payload);
},
exposes: [
exposes.enum('state', ea.STATE_GET, ['Idle', 'Ring', 'Talk', 'Open', 'Drop'])
.withDescription('Current state'),
exposes.enum('mode', ea.ALL, ['Never', 'Once', 'Always', 'Drop'])
.withDescription('Select open mode'),
exposes.binary('sound', ea.ALL, 'ON', 'OFF').withProperty('sound')
.withDescription('Enable or disable sound'),
exposes.numeric('time_ring', ea.ALL).withUnit('sec')
.withDescription('Time to ring before answer'),
exposes.numeric('time_talk', ea.ALL).withUnit('sec')
.withDescription('Time to hold before open'),
exposes.numeric('time_open', ea.ALL).withUnit('sec')
.withDescription('Time to open before end'),
exposes.numeric('time_bell', ea.ALL).withUnit('sec')
.withDescription('Time after last bell to finish ring'),
exposes.numeric('time_report', ea.ALL).withUnit('min')
.withDescription('Reporting interval'),
ep.battery(),
],
};
module.exports = device;