homebridge-tasmota-control 1.6.1-beta.2 → 1.6.1-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/sensors.js +291 -194
package/package.json
CHANGED
package/src/sensors.js
CHANGED
|
@@ -94,14 +94,14 @@ class Sensors extends EventEmitter {
|
|
|
94
94
|
return obj;
|
|
95
95
|
}, {});
|
|
96
96
|
|
|
97
|
-
let i = 0;
|
|
98
97
|
for (const [key, value] of Object.entries(sensorData)) {
|
|
99
98
|
const sensorData = value;
|
|
100
99
|
|
|
100
|
+
//sensor
|
|
101
101
|
const obj = {
|
|
102
102
|
name: key,
|
|
103
103
|
time: statusSns.Time,
|
|
104
|
-
tempUnit: statusSns.TempUnit
|
|
104
|
+
tempUnit: statusSns.TempUnit,
|
|
105
105
|
pressureUnit: statusSns.PressureUnit,
|
|
106
106
|
temperature: sensorData.Temperature,
|
|
107
107
|
referenceTemperature: sensorData.ReferenceTemperature,
|
|
@@ -114,9 +114,13 @@ class Sensors extends EventEmitter {
|
|
|
114
114
|
carbonDioxyde: sensorData.CarbonDioxyde,
|
|
115
115
|
ambientLight: sensorData.Ambient,
|
|
116
116
|
motion: sensorData.Motion
|
|
117
|
-
}
|
|
117
|
+
}
|
|
118
|
+
if (obj.tempUnit === 'C') {
|
|
119
|
+
obj.tempUnit = '°C';
|
|
120
|
+
}
|
|
118
121
|
|
|
119
|
-
|
|
122
|
+
//energy
|
|
123
|
+
const obj1 = {
|
|
120
124
|
power: sensorData.Power,
|
|
121
125
|
apparentPower: sensorData.ApparentPower,
|
|
122
126
|
reactivePower: sensorData.ReactivePower,
|
|
@@ -130,67 +134,50 @@ class Sensors extends EventEmitter {
|
|
|
130
134
|
factor: sensorData.Factor,
|
|
131
135
|
frequency: sensorData.Frequency,
|
|
132
136
|
load: sensorData.Load,
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const sensor = key === 'ENERGY' ? { ...obj, ...energy } : obj;
|
|
137
|
+
}
|
|
138
|
+
const sensor = key === 'ENERGY' ? { ...obj, ...obj1 } : obj;
|
|
136
139
|
const debug1 = this.enableDebugMode ? this.emit('debug', `Sensor: ${JSON.stringify(sensor, null, 2)}`) : false;
|
|
137
140
|
|
|
141
|
+
//push to array
|
|
138
142
|
this.sensors.push(sensor);
|
|
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
|
-
{ service: 'sensorEnergyService', char: 'ReactivePower', key: 'reactivePower' },
|
|
175
|
-
{ service: 'sensorEnergyService', char: 'EnergyToday', key: 'energyToday' },
|
|
176
|
-
{ service: 'sensorEnergyService', char: 'EnergyLastDay', key: 'energyLastDay' },
|
|
177
|
-
{ service: 'sensorEnergyService', char: 'EnergyLifetime', key: 'energyLifetime' },
|
|
178
|
-
{ service: 'sensorEnergyService', char: 'Current', key: 'current' },
|
|
179
|
-
{ service: 'sensorEnergyService', char: 'Voltage', key: 'voltage' },
|
|
180
|
-
{ service: 'sensorEnergyService', char: 'Factor', key: 'factor' },
|
|
181
|
-
{ service: 'sensorEnergyService', char: 'Frequency', key: 'frequency' },
|
|
182
|
-
{ service: 'sensorEnergyService', char: 'ReadingTime', key: 'time' },
|
|
183
|
-
];
|
|
184
|
-
|
|
185
|
-
for (const { service, char, key, transform } of updates) {
|
|
186
|
-
const value = transform ? transform(sensor[key]) : sensor[key];
|
|
187
|
-
update(this.sensorServices, `${service}${i}`, char, value);
|
|
143
|
+
}
|
|
144
|
+
this.sensorsCount = this.sensors.length;
|
|
145
|
+
|
|
146
|
+
//update characteristics
|
|
147
|
+
if (this.sensorsCount > 0) {
|
|
148
|
+
for (let i = 0; i < this.sensorsCount; i++) {
|
|
149
|
+
const sensor = this.sensors[i];
|
|
150
|
+
this.sensorTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.temperature);
|
|
151
|
+
this.sensorReferenceTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.referenceTemperature);
|
|
152
|
+
this.sensorObjTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.objTemperature);
|
|
153
|
+
this.sensorAmbTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.ambTemperature);
|
|
154
|
+
this.sensorDewPointTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.dewPointTemperature);
|
|
155
|
+
this.sensorHumidityServices?.[i]?.Characteristic?.CurrentRelativeHumidity?.updateCharacteristic(Characteristic.CurrentRelativeHumidity, sensor.humidity);
|
|
156
|
+
|
|
157
|
+
const co2Service = this.sensorCarbonDioxydeServices?.[i];
|
|
158
|
+
co2Service?.Characteristic?.CarbonDioxideDetected?.updateCharacteristic(Characteristic.CarbonDioxideDetected, sensor.carbonDioxyde > 1000);
|
|
159
|
+
co2Service?.Characteristic?.CarbonDioxideLevel?.updateCharacteristic(Characteristic.CarbonDioxideLevel, sensor.carbonDioxyde);
|
|
160
|
+
co2Service?.Characteristic?.CarbonDioxidePeakLevel?.updateCharacteristic(Characteristic.CarbonDioxidePeakLevel, sensor.carbonDioxyde);
|
|
161
|
+
|
|
162
|
+
this.sensorAmbientLightServices?.[i]?.Characteristic?.CurrentAmbientLightLevel?.updateCharacteristic(Characteristic.CurrentAmbientLightLevel, sensor.ambientLight);
|
|
163
|
+
this.sensorMotionServices?.[i]?.Characteristic?.MotionDetected?.updateCharacteristic(Characteristic.MotionDetected, sensor.motion);
|
|
164
|
+
|
|
165
|
+
//energy
|
|
166
|
+
const characteristic = this.sensorEnergyServices?.[i]?.Characteristic;
|
|
167
|
+
characteristic?.Power?.updateCharacteristic(Characteristic.Power, sensor.power);
|
|
168
|
+
characteristic?.ApparentPower?.updateCharacteristic(Characteristic.ApparentPower, sensor.apparentPower);
|
|
169
|
+
characteristic?.ReactivePower?.updateCharacteristic(Characteristic.ReactivePower, sensor.reactivePower);
|
|
170
|
+
characteristic?.EnergyToday?.updateCharacteristic(Characteristic.EnergyToday, sensor.energyToday);
|
|
171
|
+
characteristic?.EnergyLastDay?.updateCharacteristic(Characteristic.EnergyLastDay, sensor.energyLastDay);
|
|
172
|
+
characteristic?.EnergyLifetime?.updateCharacteristic(Characteristic.EnergyLifetime, sensor.energyLifetime);
|
|
173
|
+
characteristic?.Current?.updateCharacteristic(Characteristic.Current, sensor.current);
|
|
174
|
+
characteristic?.Voltage?.updateCharacteristic(Characteristic.Voltage, sensor.voltage);
|
|
175
|
+
characteristic?.Factor?.updateCharacteristic(Characteristic.Factor, sensor.factor);
|
|
176
|
+
characteristic?.Frequency?.updateCharacteristic(Characteristic.Frequency, sensor.frequency);
|
|
177
|
+
characteristic?.ReadingTime?.updateCharacteristic(Characteristic.ReadingTime, sensor.time);
|
|
188
178
|
}
|
|
189
|
-
|
|
190
|
-
i++;
|
|
191
179
|
}
|
|
192
180
|
}
|
|
193
|
-
this.sensorsCount = this.sensors.length;
|
|
194
181
|
|
|
195
182
|
return true;
|
|
196
183
|
} catch (error) {
|
|
@@ -240,14 +227,6 @@ class Sensors extends EventEmitter {
|
|
|
240
227
|
return;
|
|
241
228
|
}
|
|
242
229
|
|
|
243
|
-
createSensorService({ accessory, serviceType, serviceName, characteristicType, getValue }) {
|
|
244
|
-
const service = accessory.addService(serviceType, serviceName, serviceName);
|
|
245
|
-
service.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
246
|
-
service.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
247
|
-
service.getCharacteristic(characteristicType).onGet(getValue);
|
|
248
|
-
return service;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
230
|
//prepare accessory
|
|
252
231
|
async prepareAccessory() {
|
|
253
232
|
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Accessory`) : false;
|
|
@@ -271,158 +250,276 @@ class Sensors extends EventEmitter {
|
|
|
271
250
|
//Prepare services
|
|
272
251
|
if (this.sensorsCount > 0) {
|
|
273
252
|
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Sensor Services`) : false;
|
|
274
|
-
this.
|
|
275
|
-
|
|
253
|
+
this.sensorTemperatureServices = [];
|
|
254
|
+
this.sensorReferenceTemperatureServices = [];
|
|
255
|
+
this.sensorObjTemperatureServices = [];
|
|
256
|
+
this.sensorAmbTemperatureServices = [];
|
|
257
|
+
this.sensorDewPointTemperatureServices = [];
|
|
258
|
+
this.sensorHumidityServices = [];
|
|
259
|
+
this.sensorCarbonDioxydeServices = [];
|
|
260
|
+
this.sensorAmbientLightServices = [];
|
|
261
|
+
this.sensorMotionServices = [];
|
|
262
|
+
this.sensorEnergyServices = [];
|
|
263
|
+
|
|
264
|
+
//temperature
|
|
276
265
|
let i = 0;
|
|
277
266
|
for (const sensor of this.sensors) {
|
|
278
267
|
const sensorName = sensor.name;
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
{ key: 'dewPointTemperature', label: 'Dew Point' }
|
|
291
|
-
];
|
|
292
|
-
for (const { key, label } of tempTypes) {
|
|
293
|
-
if (sensor[key] !== undefined) {
|
|
294
|
-
if (this.enableDebugMode) this.emit('debug', `Prepare ${label} Sensor Services`);
|
|
295
|
-
const value = sensor[key];
|
|
296
|
-
const name = fullName(label);
|
|
297
|
-
const temperatureService = this.createSensorService({
|
|
298
|
-
accessory,
|
|
299
|
-
serviceType: Service.TemperatureSensor,
|
|
300
|
-
serviceName: name,
|
|
301
|
-
characteristicType: Characteristic.CurrentTemperature,
|
|
302
|
-
getValue: async () => {
|
|
303
|
-
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} ${label.toLowerCase()}: ${value} °${sensor.tempUnit}`);
|
|
304
|
-
return value;
|
|
305
|
-
}
|
|
268
|
+
if (sensor.temperature !== undefined) {
|
|
269
|
+
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Temperature Sensor Services`) : false;
|
|
270
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Temperature` : `${sensorName} Temperature`;
|
|
271
|
+
const sensorTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Temperature Sensor ${i}`);
|
|
272
|
+
sensorTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
273
|
+
sensorTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
274
|
+
sensorTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
275
|
+
.onGet(async () => {
|
|
276
|
+
const value = sensor.temperature;
|
|
277
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} temperature: ${value} °${sensor.tempUnit}`);
|
|
278
|
+
return value;
|
|
306
279
|
});
|
|
307
|
-
|
|
308
|
-
}
|
|
280
|
+
this.sensorTemperatureServices.push(sensorTemperatureService);
|
|
309
281
|
}
|
|
310
282
|
|
|
311
|
-
//
|
|
312
|
-
if (sensor.
|
|
313
|
-
|
|
314
|
-
const
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
283
|
+
//reference temperature
|
|
284
|
+
if (sensor.referenceTemperature) {
|
|
285
|
+
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Reference Temperature Sensor Services`) : false;
|
|
286
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Reference Temperature` : `${sensorName} Reference Temperature`;
|
|
287
|
+
const sensorReferenceTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Reference Temperature Sensor ${i}`);
|
|
288
|
+
sensorReferenceTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
289
|
+
sensorReferenceTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
290
|
+
sensorReferenceTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
291
|
+
.onGet(async () => {
|
|
292
|
+
const value = sensor.referenceTemperature;
|
|
293
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} reference temperature: ${value} °${sensor.tempUnit}`);
|
|
294
|
+
return value;
|
|
295
|
+
});
|
|
296
|
+
this.sensorReferenceTemperatureServices.push(sensorReferenceTemperatureService);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
//object temperature
|
|
300
|
+
if (sensor.objTemperature) {
|
|
301
|
+
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Obj Temperature Sensor Services`) : false;
|
|
302
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Obj Temperature` : `${sensorName} Obj Temperature`;
|
|
303
|
+
const sensorObjTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Obj Temperature Sensor ${i}`);
|
|
304
|
+
sensorObjTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
305
|
+
sensorObjTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
306
|
+
sensorObjTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
307
|
+
.onGet(async () => {
|
|
308
|
+
const value = sensor.objTemperature;
|
|
309
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} obj temperature: ${value} °${sensor.tempUnit}`);
|
|
310
|
+
return value;
|
|
311
|
+
});
|
|
312
|
+
this.sensorObjTemperatureServices.push(sensorObjTemperatureService);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
//ambient temperature
|
|
316
|
+
if (sensor.ambTemperature) {
|
|
317
|
+
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Amb Temperature Sensor Services`) : false;
|
|
318
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Amb Temperature` : `${sensorName} Amb Temperature`;
|
|
319
|
+
const sensorAmbTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Amb Temperature Sensor ${i}`);
|
|
320
|
+
sensorAmbTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
321
|
+
sensorAmbTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
322
|
+
sensorAmbTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
323
|
+
.onGet(async () => {
|
|
324
|
+
const value = sensor.ambTemperature;
|
|
325
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} amb temperature: ${value} °${sensor.tempUnit}`);
|
|
326
|
+
return value;
|
|
327
|
+
});
|
|
328
|
+
this.sensorAmbTemperatureServices.push(sensorAmbTemperatureService);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
//dew point temperature
|
|
332
|
+
if (sensor.dewPointTemperature) {
|
|
333
|
+
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Dew Point Temperature Sensor Services`) : false;
|
|
334
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Dew Point` : `${sensorName} Dew Point`;
|
|
335
|
+
const sensorDewPointTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Dew Point Temperature Sensor ${i}`);
|
|
336
|
+
sensorDewPointTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
337
|
+
sensorDewPointTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
338
|
+
sensorDewPointTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
339
|
+
.onGet(async () => {
|
|
340
|
+
const value = sensor.dewPointTemperature;
|
|
341
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} dew point: ${value} °${sensor.tempUnit}`);
|
|
342
|
+
return value;
|
|
343
|
+
});
|
|
344
|
+
this.sensorDewPointTemperatureServices.push(sensorDewPointTemperatureService);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
//humidity
|
|
348
|
+
if (sensor.humidity) {
|
|
349
|
+
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Humidity Sensor Services`) : false;
|
|
350
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Humidity` : `${sensorName} Humidity`;
|
|
351
|
+
const sensorHumidityService = accessory.addService(Service.HumiditySensor, serviceName, `Humidity Sensor ${i}`);
|
|
352
|
+
sensorHumidityService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
353
|
+
sensorHumidityService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
354
|
+
sensorHumidityService.getCharacteristic(Characteristic.CurrentRelativeHumidity)
|
|
355
|
+
.onGet(async () => {
|
|
321
356
|
const value = sensor.humidity;
|
|
322
|
-
|
|
357
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} humidity: ${value} %`);
|
|
323
358
|
return value;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
service.sensorHumidityService = humidityService;
|
|
359
|
+
});
|
|
360
|
+
this.sensorHumidityServices.push(sensorHumidityService);
|
|
327
361
|
}
|
|
328
362
|
|
|
329
|
-
//
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
363
|
+
//pressure
|
|
364
|
+
|
|
365
|
+
//gas
|
|
366
|
+
|
|
367
|
+
//carbon dioxyde
|
|
368
|
+
if (sensor.carbonDioxyde) {
|
|
369
|
+
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Carbon Dioxyde Sensor Services`) : false;
|
|
370
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Carbon Dioxyde` : `${sensorName} Carbon Dioxyde`;
|
|
371
|
+
const sensorCarbonDioxydeService = accessory.addService(Service.CarbonDioxideSensor, serviceName, `Carbon Dioxyde Sensor ${i}`);
|
|
372
|
+
sensorCarbonDioxydeService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
373
|
+
sensorCarbonDioxydeService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
374
|
+
sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxideDetected)
|
|
375
|
+
.onGet(async () => {
|
|
376
|
+
const state = sensor.carbonDioxyde > 1000;
|
|
377
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} carbon dioxyde detected: ${state ? 'Yes' : 'No'}`);
|
|
378
|
+
return state;
|
|
379
|
+
});
|
|
380
|
+
sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxideLevel)
|
|
381
|
+
.onGet(async () => {
|
|
382
|
+
const value = sensor.carbonDioxyde;
|
|
383
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} carbon dioxyde level: ${value} ppm`);
|
|
384
|
+
return value;
|
|
385
|
+
});
|
|
386
|
+
sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxidePeakLevel)
|
|
387
|
+
.onGet(async () => {
|
|
388
|
+
const value = sensor.carbonDioxyde;
|
|
389
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} carbon dioxyde peak level: ${value} ppm`);
|
|
390
|
+
return value;
|
|
391
|
+
});
|
|
392
|
+
this.sensorCarbonDioxydeServices.push(sensorCarbonDioxydeService);
|
|
353
393
|
}
|
|
354
394
|
|
|
355
|
-
//
|
|
356
|
-
if (sensor.ambientLight
|
|
357
|
-
|
|
358
|
-
const
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
getValue: async () => {
|
|
395
|
+
//ambient light
|
|
396
|
+
if (sensor.ambientLight) {
|
|
397
|
+
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Ambient Light Sensor Services`) : false;
|
|
398
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Ambient Light` : `${sensorName} Ambient Light`;
|
|
399
|
+
const sensorAmbientLightService = accessory.addService(Service.LightSensor, serviceName, `Ambient Light Sensor ${i}`);
|
|
400
|
+
sensorAmbientLightService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
401
|
+
sensorAmbientLightService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
402
|
+
sensorAmbientLightService.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
|
|
403
|
+
.onGet(async () => {
|
|
365
404
|
const value = sensor.ambientLight;
|
|
366
|
-
|
|
405
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} ambient light: ${value} lx`);
|
|
367
406
|
return value;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
service.sensorAmbientLightService = lightService;
|
|
407
|
+
});
|
|
408
|
+
this.sensorAmbientLightServices.push(sensorAmbientLightService);
|
|
371
409
|
}
|
|
372
410
|
|
|
373
|
-
//
|
|
374
|
-
if (sensor.motion
|
|
375
|
-
|
|
376
|
-
const
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
getValue: async () => {
|
|
411
|
+
//motion
|
|
412
|
+
if (sensor.motion) {
|
|
413
|
+
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Motion Sensor Services`) : false;
|
|
414
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Motion` : `${sensorName} Motion`;
|
|
415
|
+
const sensorMotionService = accessory.addService(Service.MotionSensor, serviceName, `Motion Sensor ${i}`);
|
|
416
|
+
sensorMotionService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
417
|
+
sensorMotionService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
418
|
+
sensorMotionService.getCharacteristic(Characteristic.MotionDetected)
|
|
419
|
+
.onGet(async () => {
|
|
383
420
|
const state = sensor.motion;
|
|
384
|
-
|
|
421
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} motion: ${state ? 'ON' : 'OFF'}`);
|
|
385
422
|
return state;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
service.sensorMotionService = motionService;
|
|
423
|
+
});
|
|
424
|
+
this.sensorMotionServices.push(sensorMotionService);
|
|
389
425
|
}
|
|
390
426
|
|
|
391
|
-
//
|
|
427
|
+
//energy
|
|
392
428
|
if (sensor.name === 'ENERGY') {
|
|
393
|
-
|
|
394
|
-
const
|
|
395
|
-
const energyService = accessory.addService(Service.PowerAndEnergyService,
|
|
396
|
-
energyService.setCharacteristic(Characteristic.ConfiguredName,
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
{ key: 'energyToday', type: Characteristic.EnergyToday, label: 'energy today', unit: 'kWh' },
|
|
403
|
-
{ key: 'energyLastDay', type: Characteristic.EnergyLastDay, label: 'energy last day', unit: 'kWh' },
|
|
404
|
-
{ key: 'energyLifetime', type: Characteristic.EnergyLifetime, label: 'energy lifetime', unit: 'kWh' },
|
|
405
|
-
{ key: 'current', type: Characteristic.Current, label: 'current', unit: 'A' },
|
|
406
|
-
{ key: 'voltage', type: Characteristic.Voltage, label: 'voltage', unit: 'V' },
|
|
407
|
-
{ key: 'factor', type: Characteristic.Factor, label: 'power factor', unit: 'cos φ' },
|
|
408
|
-
{ key: 'frequency', type: Characteristic.Freqency, label: 'frequency', unit: 'Hz' },
|
|
409
|
-
{ key: 'time', type: Characteristic.ReadingTime, label: 'last report', unit: '' }
|
|
410
|
-
];
|
|
411
|
-
|
|
412
|
-
for (const { key, type, label, unit } of energyFields) {
|
|
413
|
-
if (sensor[key] !== undefined) {
|
|
414
|
-
energyService.getCharacteristic(type).onGet(async () => {
|
|
415
|
-
const value = sensor[key];
|
|
416
|
-
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} ${label}: ${value} ${unit}`);
|
|
429
|
+
const debug4 = this.enableDebugMode ? this.emit('debug', `Prepare Power And Energy Service`) : false;
|
|
430
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName}` : `${sensorName}`;
|
|
431
|
+
const energyService = accessory.addService(Service.PowerAndEnergyService, serviceName, `Energy Sensor ${i}`);
|
|
432
|
+
energyService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
433
|
+
if (sensor.power) {
|
|
434
|
+
energyService.getCharacteristic(Characteristic.Power)
|
|
435
|
+
.onGet(async () => {
|
|
436
|
+
const value = sensor.power;
|
|
437
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} power: ${value} W`);
|
|
417
438
|
return value;
|
|
418
439
|
});
|
|
419
|
-
}
|
|
420
440
|
}
|
|
421
|
-
|
|
422
|
-
|
|
441
|
+
if (sensor.apparentPower) {
|
|
442
|
+
energyService.getCharacteristic(Characteristic.ApparentPower)
|
|
443
|
+
.onGet(async () => {
|
|
444
|
+
const value = sensor.apparentPower;
|
|
445
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} apparent power: ${value} VA`);
|
|
446
|
+
return value;
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
if (sensor.reactivePower) {
|
|
450
|
+
energyService.getCharacteristic(Characteristic.ReactivePower)
|
|
451
|
+
.onGet(async () => {
|
|
452
|
+
const value = sensor.reactivePower;
|
|
453
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} reactive power: ${value} VAr`);
|
|
454
|
+
return value;
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
if (sensor.energyToday) {
|
|
458
|
+
energyService.getCharacteristic(Characteristic.EnergyToday)
|
|
459
|
+
.onGet(async () => {
|
|
460
|
+
const value = sensor.energyToday;
|
|
461
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} energy today: ${value} kWh`);
|
|
462
|
+
return value;
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
if (sensor.energyLastDay) {
|
|
466
|
+
energyService.getCharacteristic(Characteristic.EnergyLastDay)
|
|
467
|
+
.onGet(async () => {
|
|
468
|
+
const value = sensor.energyLastDay;
|
|
469
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} energy last day: ${value} kWh`);
|
|
470
|
+
return value;
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
if (sensor.energyLifetime) {
|
|
474
|
+
energyService.getCharacteristic(Characteristic.EnergyLifetime)
|
|
475
|
+
.onGet(async () => {
|
|
476
|
+
const value = sensor.energyLifetime;
|
|
477
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} energy lifetime: ${value} kWh`);
|
|
478
|
+
return value;
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
if (sensor.current) {
|
|
482
|
+
energyService.getCharacteristic(Characteristic.Current)
|
|
483
|
+
.onGet(async () => {
|
|
484
|
+
const value = sensor.current;
|
|
485
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} current: ${value} A`);
|
|
486
|
+
return value;
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
if (sensor.voltage) {
|
|
490
|
+
energyService.getCharacteristic(Characteristic.Voltage)
|
|
491
|
+
.onGet(async () => {
|
|
492
|
+
const value = sensor.voltage;
|
|
493
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} voltage: ${value} V`);
|
|
494
|
+
return value;
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
if (sensor.factor) {
|
|
498
|
+
energyService.getCharacteristic(Characteristic.Factor)
|
|
499
|
+
.onGet(async () => {
|
|
500
|
+
const value = sensor.factor;
|
|
501
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} power factor: ${value} cos φ`);
|
|
502
|
+
return value;
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
if (sensor.frequency) {
|
|
506
|
+
energyService.getCharacteristic(Characteristic.Freqency)
|
|
507
|
+
.onGet(async () => {
|
|
508
|
+
const value = sensor.frequency;
|
|
509
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} frequency: ${value} Hz`);
|
|
510
|
+
return value;
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
if (sensor.time) {
|
|
514
|
+
energyService.getCharacteristic(Characteristic.ReadingTime)
|
|
515
|
+
.onGet(async () => {
|
|
516
|
+
const value = sensor.time;
|
|
517
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} last report: ${value}`);
|
|
518
|
+
return value;
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
this.sensorEnergyServices.push(energyService);
|
|
423
522
|
}
|
|
424
|
-
|
|
425
|
-
this.sensorServices.push(service);
|
|
426
523
|
i++;
|
|
427
524
|
}
|
|
428
525
|
}
|