homebridge-tasmota-control 1.6.1-beta.2 → 1.6.1-beta.21
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 +287 -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,46 @@ 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
|
-
// Energy
|
|
172
|
-
{ service: 'sensorEnergyService', char: 'Power', key: 'power' },
|
|
173
|
-
{ service: 'sensorEnergyService', char: 'ApparentPower', key: 'apparentPower' },
|
|
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
|
+
this.sensorCarbonDioxydeServices?.[i]?.Characteristic?.CarbonDioxideDetected?.updateCharacteristic(Characteristic.CarbonDioxideDetected, sensor.carbonDioxyde > 1000);
|
|
157
|
+
this.sensorCarbonDioxydeServices?.[i]?.Characteristic?.CarbonDioxideLevel?.updateCharacteristic(Characteristic.CarbonDioxideLevel, sensor.carbonDioxyde);
|
|
158
|
+
this.sensorCarbonDioxydeServices?.[i]?.Characteristic?.CarbonDioxidePeakLevel?.updateCharacteristic(Characteristic.CarbonDioxidePeakLevel, sensor.carbonDioxyde);
|
|
159
|
+
this.sensorAmbientLightServices?.[i]?.Characteristic?.CurrentAmbientLightLevel?.updateCharacteristic(Characteristic.CurrentAmbientLightLevel, sensor.ambientLight);
|
|
160
|
+
this.sensorMotionServices?.[i]?.Characteristic?.MotionDetected?.updateCharacteristic(Characteristic.MotionDetected, sensor.motion);
|
|
161
|
+
|
|
162
|
+
//energy
|
|
163
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.Power?.updateCharacteristic(Characteristic.Power, sensor.power);
|
|
164
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.ApparentPower?.updateCharacteristic(Characteristic.ApparentPower, sensor.apparentPower);
|
|
165
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.ReactivePower?.updateCharacteristic(Characteristic.ReactivePower, sensor.reactivePower);
|
|
166
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.EnergyToday?.updateCharacteristic(Characteristic.EnergyToday, sensor.energyToday);
|
|
167
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.EnergyLastDay?.updateCharacteristic(Characteristic.EnergyLastDay, sensor.energyLastDay);
|
|
168
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.EnergyLifetime?.updateCharacteristic(Characteristic.EnergyLifetime, sensor.energyLifetime);
|
|
169
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.Current?.updateCharacteristic(Characteristic.Current, sensor.current);
|
|
170
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.Voltage?.updateCharacteristic(Characteristic.Voltage, sensor.voltage);
|
|
171
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.Factor?.updateCharacteristic(Characteristic.Factor, sensor.factor);
|
|
172
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.Frequency?.updateCharacteristic(Characteristic.Frequency, sensor.frequency);
|
|
173
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.ReadingTime?.updateCharacteristic(Characteristic.ReadingTime, sensor.time);
|
|
188
174
|
}
|
|
189
|
-
|
|
190
|
-
i++;
|
|
191
175
|
}
|
|
192
176
|
}
|
|
193
|
-
this.sensorsCount = this.sensors.length;
|
|
194
177
|
|
|
195
178
|
return true;
|
|
196
179
|
} catch (error) {
|
|
@@ -240,14 +223,6 @@ class Sensors extends EventEmitter {
|
|
|
240
223
|
return;
|
|
241
224
|
}
|
|
242
225
|
|
|
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
226
|
//prepare accessory
|
|
252
227
|
async prepareAccessory() {
|
|
253
228
|
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Accessory`) : false;
|
|
@@ -271,158 +246,276 @@ class Sensors extends EventEmitter {
|
|
|
271
246
|
//Prepare services
|
|
272
247
|
if (this.sensorsCount > 0) {
|
|
273
248
|
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Sensor Services`) : false;
|
|
274
|
-
this.
|
|
275
|
-
|
|
249
|
+
this.sensorTemperatureServices = [];
|
|
250
|
+
this.sensorReferenceTemperatureServices = [];
|
|
251
|
+
this.sensorObjTemperatureServices = [];
|
|
252
|
+
this.sensorAmbTemperatureServices = [];
|
|
253
|
+
this.sensorDewPointTemperatureServices = [];
|
|
254
|
+
this.sensorHumidityServices = [];
|
|
255
|
+
this.sensorCarbonDioxydeServices = [];
|
|
256
|
+
this.sensorAmbientLightServices = [];
|
|
257
|
+
this.sensorMotionServices = [];
|
|
258
|
+
this.sensorEnergyServices = [];
|
|
259
|
+
|
|
260
|
+
//temperature
|
|
276
261
|
let i = 0;
|
|
277
262
|
for (const sensor of this.sensors) {
|
|
278
263
|
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
|
-
}
|
|
264
|
+
if (sensor.temperature !== undefined) {
|
|
265
|
+
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Temperature Sensor Services`) : false;
|
|
266
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Temperature` : `${sensorName} Temperature`;
|
|
267
|
+
const sensorTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Temperature Sensor ${i}`);
|
|
268
|
+
sensorTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
269
|
+
sensorTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
270
|
+
sensorTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
271
|
+
.onGet(async () => {
|
|
272
|
+
const value = sensor.temperature;
|
|
273
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} temperature: ${value} °${sensor.tempUnit}`);
|
|
274
|
+
return value;
|
|
306
275
|
});
|
|
307
|
-
|
|
308
|
-
}
|
|
276
|
+
this.sensorTemperatureServices.push(sensorTemperatureService);
|
|
309
277
|
}
|
|
310
278
|
|
|
311
|
-
//
|
|
312
|
-
if (sensor.
|
|
313
|
-
|
|
314
|
-
const
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
279
|
+
//reference temperature
|
|
280
|
+
if (sensor.referenceTemperature) {
|
|
281
|
+
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Reference Temperature Sensor Services`) : false;
|
|
282
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Reference Temperature` : `${sensorName} Reference Temperature`;
|
|
283
|
+
const sensorReferenceTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Reference Temperature Sensor ${i}`);
|
|
284
|
+
sensorReferenceTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
285
|
+
sensorReferenceTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
286
|
+
sensorReferenceTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
287
|
+
.onGet(async () => {
|
|
288
|
+
const value = sensor.referenceTemperature;
|
|
289
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} reference temperature: ${value} °${sensor.tempUnit}`);
|
|
290
|
+
return value;
|
|
291
|
+
});
|
|
292
|
+
this.sensorReferenceTemperatureServices.push(sensorReferenceTemperatureService);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
//object temperature
|
|
296
|
+
if (sensor.objTemperature) {
|
|
297
|
+
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Obj Temperature Sensor Services`) : false;
|
|
298
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Obj Temperature` : `${sensorName} Obj Temperature`;
|
|
299
|
+
const sensorObjTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Obj Temperature Sensor ${i}`);
|
|
300
|
+
sensorObjTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
301
|
+
sensorObjTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
302
|
+
sensorObjTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
303
|
+
.onGet(async () => {
|
|
304
|
+
const value = sensor.objTemperature;
|
|
305
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} obj temperature: ${value} °${sensor.tempUnit}`);
|
|
306
|
+
return value;
|
|
307
|
+
});
|
|
308
|
+
this.sensorObjTemperatureServices.push(sensorObjTemperatureService);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
//ambient temperature
|
|
312
|
+
if (sensor.ambTemperature) {
|
|
313
|
+
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Amb Temperature Sensor Services`) : false;
|
|
314
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Amb Temperature` : `${sensorName} Amb Temperature`;
|
|
315
|
+
const sensorAmbTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Amb Temperature Sensor ${i}`);
|
|
316
|
+
sensorAmbTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
317
|
+
sensorAmbTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
318
|
+
sensorAmbTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
319
|
+
.onGet(async () => {
|
|
320
|
+
const value = sensor.ambTemperature;
|
|
321
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} amb temperature: ${value} °${sensor.tempUnit}`);
|
|
322
|
+
return value;
|
|
323
|
+
});
|
|
324
|
+
this.sensorAmbTemperatureServices.push(sensorAmbTemperatureService);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
//dew point temperature
|
|
328
|
+
if (sensor.dewPointTemperature) {
|
|
329
|
+
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Dew Point Temperature Sensor Services`) : false;
|
|
330
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Dew Point` : `${sensorName} Dew Point`;
|
|
331
|
+
const sensorDewPointTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Dew Point Temperature Sensor ${i}`);
|
|
332
|
+
sensorDewPointTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
333
|
+
sensorDewPointTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
334
|
+
sensorDewPointTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
335
|
+
.onGet(async () => {
|
|
336
|
+
const value = sensor.dewPointTemperature;
|
|
337
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} dew point: ${value} °${sensor.tempUnit}`);
|
|
338
|
+
return value;
|
|
339
|
+
});
|
|
340
|
+
this.sensorDewPointTemperatureServices.push(sensorDewPointTemperatureService);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
//humidity
|
|
344
|
+
if (sensor.humidity) {
|
|
345
|
+
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Humidity Sensor Services`) : false;
|
|
346
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Humidity` : `${sensorName} Humidity`;
|
|
347
|
+
const sensorHumidityService = accessory.addService(Service.HumiditySensor, serviceName, `Humidity Sensor ${i}`);
|
|
348
|
+
sensorHumidityService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
349
|
+
sensorHumidityService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
350
|
+
sensorHumidityService.getCharacteristic(Characteristic.CurrentRelativeHumidity)
|
|
351
|
+
.onGet(async () => {
|
|
321
352
|
const value = sensor.humidity;
|
|
322
|
-
|
|
353
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} humidity: ${value} %`);
|
|
323
354
|
return value;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
service.sensorHumidityService = humidityService;
|
|
355
|
+
});
|
|
356
|
+
this.sensorHumidityServices.push(sensorHumidityService);
|
|
327
357
|
}
|
|
328
358
|
|
|
329
|
-
//
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
359
|
+
//pressure
|
|
360
|
+
|
|
361
|
+
//gas
|
|
362
|
+
|
|
363
|
+
//carbon dioxyde
|
|
364
|
+
if (sensor.carbonDioxyde) {
|
|
365
|
+
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Carbon Dioxyde Sensor Services`) : false;
|
|
366
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Carbon Dioxyde` : `${sensorName} Carbon Dioxyde`;
|
|
367
|
+
const sensorCarbonDioxydeService = accessory.addService(Service.CarbonDioxideSensor, serviceName, `Carbon Dioxyde Sensor ${i}`);
|
|
368
|
+
sensorCarbonDioxydeService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
369
|
+
sensorCarbonDioxydeService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
370
|
+
sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxideDetected)
|
|
371
|
+
.onGet(async () => {
|
|
372
|
+
const state = sensor.carbonDioxyde > 1000;
|
|
373
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} carbon dioxyde detected: ${state ? 'Yes' : 'No'}`);
|
|
374
|
+
return state;
|
|
375
|
+
});
|
|
376
|
+
sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxideLevel)
|
|
377
|
+
.onGet(async () => {
|
|
378
|
+
const value = sensor.carbonDioxyde;
|
|
379
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} carbon dioxyde level: ${value} ppm`);
|
|
380
|
+
return value;
|
|
381
|
+
});
|
|
382
|
+
sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxidePeakLevel)
|
|
383
|
+
.onGet(async () => {
|
|
384
|
+
const value = sensor.carbonDioxyde;
|
|
385
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} carbon dioxyde peak level: ${value} ppm`);
|
|
386
|
+
return value;
|
|
387
|
+
});
|
|
388
|
+
this.sensorCarbonDioxydeServices.push(sensorCarbonDioxydeService);
|
|
353
389
|
}
|
|
354
390
|
|
|
355
|
-
//
|
|
356
|
-
if (sensor.ambientLight
|
|
357
|
-
|
|
358
|
-
const
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
getValue: async () => {
|
|
391
|
+
//ambient light
|
|
392
|
+
if (sensor.ambientLight) {
|
|
393
|
+
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Ambient Light Sensor Services`) : false;
|
|
394
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Ambient Light` : `${sensorName} Ambient Light`;
|
|
395
|
+
const sensorAmbientLightService = accessory.addService(Service.LightSensor, serviceName, `Ambient Light Sensor ${i}`);
|
|
396
|
+
sensorAmbientLightService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
397
|
+
sensorAmbientLightService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
398
|
+
sensorAmbientLightService.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
|
|
399
|
+
.onGet(async () => {
|
|
365
400
|
const value = sensor.ambientLight;
|
|
366
|
-
|
|
401
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} ambient light: ${value} lx`);
|
|
367
402
|
return value;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
service.sensorAmbientLightService = lightService;
|
|
403
|
+
});
|
|
404
|
+
this.sensorAmbientLightServices.push(sensorAmbientLightService);
|
|
371
405
|
}
|
|
372
406
|
|
|
373
|
-
//
|
|
374
|
-
if (sensor.motion
|
|
375
|
-
|
|
376
|
-
const
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
getValue: async () => {
|
|
407
|
+
//motion
|
|
408
|
+
if (sensor.motion) {
|
|
409
|
+
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Motion Sensor Services`) : false;
|
|
410
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Motion` : `${sensorName} Motion`;
|
|
411
|
+
const sensorMotionService = accessory.addService(Service.MotionSensor, serviceName, `Motion Sensor ${i}`);
|
|
412
|
+
sensorMotionService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
413
|
+
sensorMotionService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
414
|
+
sensorMotionService.getCharacteristic(Characteristic.MotionDetected)
|
|
415
|
+
.onGet(async () => {
|
|
383
416
|
const state = sensor.motion;
|
|
384
|
-
|
|
417
|
+
const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} motion: ${state ? 'ON' : 'OFF'}`);
|
|
385
418
|
return state;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
service.sensorMotionService = motionService;
|
|
419
|
+
});
|
|
420
|
+
this.sensorMotionServices.push(sensorMotionService);
|
|
389
421
|
}
|
|
390
422
|
|
|
391
|
-
//
|
|
423
|
+
//energy
|
|
392
424
|
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}`);
|
|
425
|
+
const debug4 = this.enableDebugMode ? this.emit('debug', `Prepare Power And Energy Service`) : false;
|
|
426
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName}` : `${sensorName}`;
|
|
427
|
+
const energyService = accessory.addService(Service.PowerAndEnergyService, serviceName, `Energy Sensor ${i}`);
|
|
428
|
+
energyService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
429
|
+
if (sensor.power) {
|
|
430
|
+
energyService.getCharacteristic(Characteristic.Power)
|
|
431
|
+
.onGet(async () => {
|
|
432
|
+
const value = sensor.power;
|
|
433
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} power: ${value} W`);
|
|
417
434
|
return value;
|
|
418
435
|
});
|
|
419
|
-
}
|
|
420
436
|
}
|
|
421
|
-
|
|
422
|
-
|
|
437
|
+
if (sensor.apparentPower) {
|
|
438
|
+
energyService.getCharacteristic(Characteristic.ApparentPower)
|
|
439
|
+
.onGet(async () => {
|
|
440
|
+
const value = sensor.apparentPower;
|
|
441
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} apparent power: ${value} VA`);
|
|
442
|
+
return value;
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
if (sensor.reactivePower) {
|
|
446
|
+
energyService.getCharacteristic(Characteristic.ReactivePower)
|
|
447
|
+
.onGet(async () => {
|
|
448
|
+
const value = sensor.reactivePower;
|
|
449
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} reactive power: ${value} VAr`);
|
|
450
|
+
return value;
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
if (sensor.energyToday) {
|
|
454
|
+
energyService.getCharacteristic(Characteristic.EnergyToday)
|
|
455
|
+
.onGet(async () => {
|
|
456
|
+
const value = sensor.energyToday;
|
|
457
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} energy today: ${value} kWh`);
|
|
458
|
+
return value;
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
if (sensor.energyLastDay) {
|
|
462
|
+
energyService.getCharacteristic(Characteristic.EnergyLastDay)
|
|
463
|
+
.onGet(async () => {
|
|
464
|
+
const value = sensor.energyLastDay;
|
|
465
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} energy last day: ${value} kWh`);
|
|
466
|
+
return value;
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
if (sensor.energyLifetime) {
|
|
470
|
+
energyService.getCharacteristic(Characteristic.EnergyLifetime)
|
|
471
|
+
.onGet(async () => {
|
|
472
|
+
const value = sensor.energyLifetime;
|
|
473
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} energy lifetime: ${value} kWh`);
|
|
474
|
+
return value;
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
if (sensor.current) {
|
|
478
|
+
energyService.getCharacteristic(Characteristic.Current)
|
|
479
|
+
.onGet(async () => {
|
|
480
|
+
const value = sensor.current;
|
|
481
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} current: ${value} A`);
|
|
482
|
+
return value;
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
if (sensor.voltage) {
|
|
486
|
+
energyService.getCharacteristic(Characteristic.Voltage)
|
|
487
|
+
.onGet(async () => {
|
|
488
|
+
const value = sensor.voltage;
|
|
489
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} voltage: ${value} V`);
|
|
490
|
+
return value;
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
if (sensor.factor) {
|
|
494
|
+
energyService.getCharacteristic(Characteristic.Factor)
|
|
495
|
+
.onGet(async () => {
|
|
496
|
+
const value = sensor.factor;
|
|
497
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} power factor: ${value} cos φ`);
|
|
498
|
+
return value;
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
if (sensor.frequency) {
|
|
502
|
+
energyService.getCharacteristic(Characteristic.Freqency)
|
|
503
|
+
.onGet(async () => {
|
|
504
|
+
const value = sensor.frequency;
|
|
505
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} frequency: ${value} Hz`);
|
|
506
|
+
return value;
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
if (sensor.time) {
|
|
510
|
+
energyService.getCharacteristic(Characteristic.ReadingTime)
|
|
511
|
+
.onGet(async () => {
|
|
512
|
+
const value = sensor.time;
|
|
513
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} last report: ${value}`);
|
|
514
|
+
return value;
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
this.sensorEnergyServices.push(energyService);
|
|
423
518
|
}
|
|
424
|
-
|
|
425
|
-
this.sensorServices.push(service);
|
|
426
519
|
i++;
|
|
427
520
|
}
|
|
428
521
|
}
|