homebridge-tasmota-control 0.7.2 → 0.8.0

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/README.md CHANGED
@@ -33,6 +33,8 @@ Homebridge plugin for Tasmota flashed devices.
33
33
  * Temperature
34
34
  * Humidity
35
35
  * Dew Point
36
+ * Carbon Dioxyde
37
+ * Ambient Light
36
38
 
37
39
  ### Configuration
38
40
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Tasmota Control",
3
3
  "name": "homebridge-tasmota-control",
4
- "version": "0.7.2",
4
+ "version": "0.8.0",
5
5
  "description": "Homebridge plugin to control Tasmota flashed devices.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -44,6 +44,8 @@ class TasmotaDevice {
44
44
  this.sensorsDewPointCount = 0;
45
45
  this.sensorsPressureCount = 0;
46
46
  this.sensorsGasCount = 0;
47
+ this.sensorsCarbonDioxydeCount = 0;
48
+ this.sensorsAmbientLightCount = 0;
47
49
 
48
50
  //variable
49
51
  this.startPrepareAccessory = true;
@@ -205,6 +207,8 @@ class TasmotaDevice {
205
207
  this.sensorsDewPoint = [];
206
208
  this.sensorsPressure = [];
207
209
  this.sensorsGas = [];
210
+ this.sensorsCarbonDioxyde = [];
211
+ this.sensorsAmbientLight = [];
208
212
 
209
213
  const sensorsStatusData = await this.axiosInstance(CONSTANS.ApiCommands.Status);
210
214
  const sensorsStatus = sensorsStatusData.data.StatusSNS;
@@ -227,6 +231,8 @@ class TasmotaDevice {
227
231
  const push3 = dewPoint !== false && dewPoint !== undefined && dewPoint !== null ? this.sensorsDewPoint.push(dewPoint) : false;
228
232
  const push4 = pressure !== false && pressure !== undefined && pressure !== null ? this.sensorsPressure.push(pressure) : false;
229
233
  const push5 = gas !== false && gas !== undefined && gas !== null ? this.sensorsGas.push(gas) : false;
234
+ const push6 = carbonDioxyde !== false && carbonDioxyde !== undefined && carbonDioxyde !== null ? this.sensorsCarbonDioxyde.push(carbonDioxyde) : false;
235
+ const push7 = ambientLight !== false && ambientLight !== undefined && ambientLight !== null ? this.sensorsAmbientLight.push(ambientLight) : false;
230
236
  };
231
237
 
232
238
  this.sensorsTemperatureCount = this.sensorsTemperature.length;
@@ -234,6 +240,8 @@ class TasmotaDevice {
234
240
  this.sensorsDewPointCount = this.sensorsDewPoint.length;
235
241
  this.sensorsPressureCount = this.sensorsPressure.length;
236
242
  this.sensorsGasCount = this.sensorsGas.length;
243
+ this.sensorsCarbonDioxydeCount = this.sensorsCarbonDioxyde.length;
244
+ this.sensorsAmbientLightCount = this.sensorsAmbientLight.length;
237
245
  this.tempUnit = sensorsStatus.TempUnit ?? 'C';
238
246
  this.pressureUnit = sensorsStatus.PressureUnit ?? 'hPa';
239
247
 
@@ -262,6 +270,25 @@ class TasmotaDevice {
262
270
  .updateCharacteristic(Characteristic.CurrentTemperature, dewPoint);
263
271
  };
264
272
  };
273
+
274
+ if (this.sensorCarbonDioxydeServices && this.sensorsCarbonDioxydeCount > 0) {
275
+ for (let i = 0; i < this.sensorsCarbonDioxydeCount; i++) {
276
+ const carbonDioxydeDetected = this.sensorsCarbonDioxyde[i] > 1000;
277
+ const carbonDioxydeLevel = this.sensorsCarbonDioxyde[i];
278
+ this.sensorCarbonDioxydeServices[i]
279
+ .updateCharacteristic(Characteristic.CarbonDioxideDetected, carbonDioxydeDetected)
280
+ .updateCharacteristic(Characteristic.CarbonDioxideLevel, carbonDioxydeLevel)
281
+ .updateCharacteristic(Characteristic.CarbonDioxidePeakLevel, carbonDioxydeLevel);
282
+ };
283
+ };
284
+
285
+ if (this.sensorAmbientLightServices && this.sensorsAmbientLightCount > 0) {
286
+ for (let i = 0; i < this.sensorsAmbientLightCount; i++) {
287
+ const ambientLight = this.sensorsAmbientLight[i];
288
+ this.sensorAmbientLightServices[i]
289
+ .updateCharacteristic(Characteristic.CurrentAmbientLightLevel, ambientLight);
290
+ };
291
+ };
265
292
  };
266
293
 
267
294
  resolve();
@@ -403,7 +430,60 @@ class TasmotaDevice {
403
430
  //gas
404
431
 
405
432
  //carbon dioxyde
433
+ const sensorsCarbonDioxydeCount = this.sensorsCarbonDioxydeCount;
434
+ if (sensorsCarbonDioxydeCount > 0) {
435
+ const debug = this.enableDebugMode ? this.log('Prepare Carbon Dioxyde Sensor Services') : false;
436
+ this.sensorCarbonDioxydeServices = [];
437
+ for (let i = 0; i < sensorsCarbonDioxydeCount; i++) {
438
+ const sensorName = this.sensorsName[i];
439
+ const serviceName = `${accessoryName} ${sensorName} Carbon Dioxyde`;
440
+ const sensorCarbonDioxydeService = new Service.CarbonDioxideSensor(serviceName, `Carbon Dioxyde Sensor${i}`);
441
+ sensorCarbonDioxydeService.addOptionalCharacteristic(Characteristic.ConfiguredName);
442
+ sensorCarbonDioxydeService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
443
+ sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxideDetected)
444
+ .onGet(async () => {
445
+ const state = this.sensorsCarbonDioxyde[i] > 1000;
446
+ const logInfo = this.disableLogInfo ? false : this.log(`Device: ${this.host}, ${accessoryName}, sensor: ${sensorName} carbon dioxyde detected: ${state ? 'Yes' : 'No'}`);
447
+ return state;
448
+ });
449
+ sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxideLevel)
450
+ .onGet(async () => {
451
+ const value = this.sensorsCarbonDioxyde[i];
452
+ const logInfo = this.disableLogInfo ? false : this.log(`Device: ${this.host}, ${accessoryName}, sensor: ${sensorName} carbon dioxyde level: ${value} ppm`);
453
+ return value;
454
+ });
455
+ sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxidePeakLevel)
456
+ .onGet(async () => {
457
+ const value = this.sensorsCarbonDioxyde[i];
458
+ const logInfo = this.disableLogInfo ? false : this.log(`Device: ${this.host}, ${accessoryName}, sensor: ${sensorName} carbon dioxyde peak level: ${value} ppm`);
459
+ return value;
460
+ });
461
+ this.sensorCarbonDioxydeServices.push(sensorCarbonDioxydeService);
462
+ accessory.addService(sensorCarbonDioxydeService);
463
+ };
464
+ }
406
465
 
466
+ //ambient light
467
+ const sensorsAmbientLightCount = this.sensorsAmbientLightCount;
468
+ if (sensorsAmbientLightCount > 0) {
469
+ const debug = this.enableDebugMode ? this.log('Prepare Ambient Light Sensor Services') : false;
470
+ this.sensorAmbientLightServices = [];
471
+ for (let i = 0; i < sensorsAmbientLightCount; i++) {
472
+ const sensorName = this.sensorsName[i];
473
+ const serviceName = `${accessoryName} ${sensorName} Ambient Light`;
474
+ const sensorAmbientLightService = new Service.LightSensor(serviceName, `Ambient Light Sensor${i}`);
475
+ sensorAmbientLightService.addOptionalCharacteristic(Characteristic.ConfiguredName);
476
+ sensorAmbientLightService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
477
+ sensorAmbientLightService.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
478
+ .onGet(async () => {
479
+ const value = this.sensorsAmbientLight[i];
480
+ const logInfo = this.disableLogInfo ? false : this.log(`Device: ${this.host}, ${accessoryName}, sensor: ${sensorName} ambient light: ${value} lx`);
481
+ return value;
482
+ });
483
+ this.sensorAmbientLightServices.push(sensorAmbientLightService);
484
+ accessory.addService(sensorAmbientLightService);
485
+ };
486
+ }
407
487
  };
408
488
 
409
489
  resolve(accessory);