homebridge-tasmota-control 1.5.1-beta.17 → 1.5.1-beta.19

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/index.js CHANGED
@@ -8,6 +8,7 @@ import Fans from './src/fans.js';
8
8
  import Sensors from './src/sensors.js';
9
9
  import ImpulseGenerator from './src/impulsegenerator.js';
10
10
  import { PluginName, PlatformName } from './src/constants.js';
11
+ import CustomCharacteristics from './src/customcharacteristics.js';
11
12
 
12
13
  class tasmotaPlatform {
13
14
  constructor(log, config, api) {
@@ -89,9 +90,6 @@ class tasmotaPlatform {
89
90
  let i = 0;
90
91
  for (const type of info.deviceTypes) {
91
92
  const serialNumber = i === 0 ? info.serialNumber : `${info.serialNumber}${i}`;
92
- if (type === 4 && info.sensorName === 'ENERGY') {
93
- continue;
94
- }
95
93
 
96
94
  let deviceType;
97
95
  switch (type) {
@@ -192,5 +190,6 @@ class tasmotaPlatform {
192
190
  }
193
191
 
194
192
  export default (api) => {
193
+ CustomCharacteristics(api);
195
194
  api.registerPlatform(PluginName, PlatformName, tasmotaPlatform);
196
195
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Tasmota Control",
3
3
  "name": "homebridge-tasmota-control",
4
- "version": "1.5.1-beta.17",
4
+ "version": "1.5.1-beta.19",
5
5
  "description": "Homebridge plugin to control Tasmota flashed devices.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -0,0 +1,198 @@
1
+ export default (api) => {
2
+ const { Service, Characteristic, Units, Formats, Perms } = api.hap;
3
+
4
+ //Envoy production/consumption characteristics
5
+ class Power extends Characteristic {
6
+ constructor() {
7
+ super('Power', '00000071-000B-1000-8000-0026BB765291');
8
+ this.setProps({
9
+ format: Formats.FLOAT,
10
+ unit: 'W',
11
+ maxValue: 10000,
12
+ minValue: -10000,
13
+ minStep: 0.001,
14
+ perms: [Perms.PAIRED_READ, Perms.NOTIFY]
15
+ });
16
+ this.value = this.getDefaultValue();
17
+ }
18
+ }
19
+ Characteristic.Power = Power;
20
+
21
+ class ApparentPower extends Characteristic {
22
+ constructor() {
23
+ super('Apparent power', '00000072-000B-1000-8000-0026BB765291');
24
+ this.setProps({
25
+ format: Formats.FLOAT,
26
+ unit: 'VA',
27
+ maxValue: 10000,
28
+ minValue: -10000,
29
+ minStep: 0.001,
30
+ perms: [Perms.PAIRED_READ, Perms.NOTIFY]
31
+ });
32
+ this.value = this.getDefaultValue();
33
+ }
34
+ }
35
+ Characteristic.ApparentPower = ApparentPower;
36
+
37
+ class ReactivePower extends Characteristic {
38
+ constructor() {
39
+ super('Reactive power', '00000073-000B-1000-8000-0026BB765291');
40
+ this.setProps({
41
+ format: Formats.FLOAT,
42
+ unit: 'VAr',
43
+ maxValue: 10000,
44
+ minValue: -10000,
45
+ minStep: 0.001,
46
+ perms: [Perms.PAIRED_READ, Perms.NOTIFY]
47
+ });
48
+ this.value = this.getDefaultValue();
49
+ }
50
+ }
51
+ Characteristic.ReactivePower = ReactivePower;
52
+
53
+ class EnergyToday extends Characteristic {
54
+ constructor() {
55
+ super('Energy today', '00000074-000B-1000-8000-0026BB765291');
56
+ this.setProps({
57
+ format: Formats.FLOAT,
58
+ unit: 'kWh',
59
+ maxValue: 1000,
60
+ minValue: -1000,
61
+ minStep: 0.001,
62
+ perms: [Perms.PAIRED_READ, Perms.NOTIFY]
63
+ });
64
+ this.value = this.getDefaultValue();
65
+ }
66
+ }
67
+ Characteristic.EnergyToday = EnergyToday;
68
+
69
+ class EnergyLastDay extends Characteristic {
70
+ constructor() {
71
+ super('Energy last day', '00000075-000B-1000-8000-0026BB765291');
72
+ this.setProps({
73
+ format: Formats.FLOAT,
74
+ unit: 'kWh',
75
+ maxValue: 1000,
76
+ minValue: -1000,
77
+ minStep: 0.001,
78
+ perms: [Perms.PAIRED_READ, Perms.NOTIFY]
79
+ });
80
+ this.value = this.getDefaultValue();
81
+ }
82
+ }
83
+ Characteristic.EnergyLastDay = EnergyLastDay;
84
+
85
+ class EnergyLifetime extends Characteristic {
86
+ constructor() {
87
+ super('Energy lifetime', '00000076-000B-1000-8000-0026BB765291');
88
+ this.setProps({
89
+ format: Formats.FLOAT,
90
+ unit: 'kWh',
91
+ maxValue: 100000000,
92
+ minValue: -100000000,
93
+ minStep: 0.001,
94
+ perms: [Perms.PAIRED_READ, Perms.NOTIFY]
95
+ });
96
+ this.value = this.getDefaultValue();
97
+ }
98
+ }
99
+ Characteristic.EnergyLifetime = EnergyLifetime;
100
+
101
+ class Current extends Characteristic {
102
+ constructor() {
103
+ super('Current', '00000077-000B-1000-8000-0026BB765291');
104
+ this.setProps({
105
+ format: Formats.FLOAT,
106
+ unit: 'A',
107
+ maxValue: 1000,
108
+ minValue: -1000,
109
+ minStep: 0.001,
110
+ perms: [Perms.PAIRED_READ, Perms.NOTIFY]
111
+ });
112
+ this.value = this.getDefaultValue();
113
+ }
114
+ }
115
+ Characteristic.Current = Current;
116
+
117
+ class Voltage extends Characteristic {
118
+ constructor() {
119
+ super('Voltage', '00000078-000B-1000-8000-0026BB765291');
120
+ this.setProps({
121
+ format: Formats.FLOAT,
122
+ unit: 'V',
123
+ maxValue: 1000,
124
+ minValue: 0,
125
+ minStep: 0.1,
126
+ perms: [Perms.PAIRED_READ, Perms.NOTIFY]
127
+ });
128
+ this.value = this.getDefaultValue();
129
+ }
130
+ }
131
+ Characteristic.Voltage = Voltage;
132
+
133
+ class Factor extends Characteristic {
134
+ constructor() {
135
+ super('Power factor', '00000079-000B-1000-8000-0026BB765291');
136
+ this.setProps({
137
+ format: Formats.FLOAT,
138
+ unit: 'cos φ',
139
+ maxValue: 1,
140
+ minValue: -1,
141
+ minStep: 0.01,
142
+ perms: [Perms.PAIRED_READ, Perms.NOTIFY]
143
+ });
144
+ this.value = this.getDefaultValue();
145
+ }
146
+ }
147
+ Characteristic.Factor = Factor;
148
+
149
+ class Freqency extends Characteristic {
150
+ constructor() {
151
+ super('Frequency', '00000080-000B-1000-8000-0026BB765291');
152
+ this.setProps({
153
+ format: Formats.FLOAT,
154
+ unit: 'Hz',
155
+ maxValue: 100,
156
+ minValue: 0,
157
+ minStep: 0.01,
158
+ perms: [Perms.PAIRED_READ, Perms.NOTIFY]
159
+ });
160
+ this.value = this.getDefaultValue();
161
+ }
162
+ }
163
+ Characteristic.Freqency = Freqency;
164
+
165
+ class ReadingTime extends Characteristic {
166
+ constructor() {
167
+ super('Reading time', '00000081-000B-1000-8000-0026BB765291');
168
+ this.setProps({
169
+ format: Formats.STRING,
170
+ perms: [Perms.PAIRED_READ, Perms.NOTIFY]
171
+ });
172
+ this.value = this.getDefaultValue();
173
+ }
174
+ }
175
+ Characteristic.ReadingTime = ReadingTime;
176
+
177
+ //power production service
178
+ class PowerAndEnergyService extends Service {
179
+ constructor(displayName, subtype) {
180
+ super(displayName, '00000004-000A-1000-8000-0026BB765291', subtype);
181
+ // Mandatory Characteristics
182
+ this.addCharacteristic(Characteristic.Power)
183
+ // Optional Characteristics
184
+ this.addOptionalCharacteristic(Characteristic.ApparentPower);
185
+ this.addOptionalCharacteristic(Characteristic.ReactivePower);
186
+ this.addOptionalCharacteristic(Characteristic.EnergyToday);
187
+ this.addOptionalCharacteristic(Characteristic.EnergyLastDay);
188
+ this.addOptionalCharacteristic(Characteristic.EnergyLifetime);
189
+ this.addOptionalCharacteristic(Characteristic.Current);
190
+ this.addOptionalCharacteristic(Characteristic.Voltage);
191
+ this.addOptionalCharacteristic(Characteristic.Factor);
192
+ this.addOptionalCharacteristic(Characteristic.Freqency);
193
+ this.addOptionalCharacteristic(Characteristic.ReadingTime);
194
+ this.addOptionalCharacteristic(Characteristic.ConfiguredName);
195
+ }
196
+ }
197
+ Service.PowerAndEnergyService = PowerAndEnergyService;
198
+ };
package/src/sensors.js CHANGED
@@ -121,17 +121,18 @@ class Sensors extends EventEmitter {
121
121
 
122
122
  //energy
123
123
  const obj1 = {
124
- energyTotalStartTime: sensorData.TotalStartTime,
125
- energyTotal: sensorData.Total,
126
- energyPeriod: sensorData.Period,
127
- energyYesterday: sensorData.Yesterday,
128
- energyToday: sensorData.Today,
129
124
  power: sensorData.Power,
130
125
  apparentPower: sensorData.ApparentPower,
131
126
  reactivePower: sensorData.ReactivePower,
132
- factor: sensorData.Factor,
133
- voltage: sensorData.Voltage,
127
+ energyToday: sensorData.Today,
128
+ energyLastDay: sensorData.Yesterday,
129
+ energyLifetime: sensorData.Total,
130
+ energyLifeTimeStartTime: sensorData.TotalStartTime,
131
+ energyPeriod: sensorData.Period,
134
132
  current: sensorData.Current,
133
+ voltage: sensorData.Voltage,
134
+ factor: sensorData.Factor,
135
+ frequency: sensorData.Frequency,
135
136
  load: sensorData.Load,
136
137
  }
137
138
  const sensor = key === 'ENERGY' ? { ...obj, ...obj1 } : obj;
@@ -146,18 +147,33 @@ class Sensors extends EventEmitter {
146
147
  if (this.sensorsCount > 0) {
147
148
  for (let i = 0; i < this.sensorsCount; i++) {
148
149
  const sensor = this.sensors[i];
150
+
149
151
  this.sensorTemperatureServices?.[i]?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.temperature);
150
152
  this.sensorReferenceTemperatureServices?.[i]?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.referenceTemperature);
151
153
  this.sensorObjTemperatureServices?.[i]?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.objTemperature);
152
154
  this.sensorAmbTemperatureServices?.[i]?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.ambTemperature);
153
155
  this.sensorDewPointTemperatureServices?.[i]?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.dewPointTemperature);
154
156
  this.sensorHumidityServices?.[i]?.updateCharacteristic(Characteristic.CurrentRelativeHumidity, sensor.humidity);
155
- this.sensorCarbonDioxydeServices?.[i]
156
- ?.updateCharacteristic(Characteristic.CarbonDioxideDetected, sensor.carbonDioxyde > 1000)
157
- .updateCharacteristic(Characteristic.CarbonDioxideLevel, sensor.carbonDioxyde)
158
- .updateCharacteristic(Characteristic.CarbonDioxidePeakLevel, sensor.carbonDioxyde);
157
+
158
+ const co2Service = this.sensorCarbonDioxydeServices?.[i];
159
+ co2Service?.updateCharacteristic(Characteristic.CarbonDioxideDetected, sensor.carbonDioxyde > 1000);
160
+ co2Service?.updateCharacteristic(Characteristic.CarbonDioxideLevel, sensor.carbonDioxyde);
161
+ co2Service?.updateCharacteristic(Characteristic.CarbonDioxidePeakLevel, sensor.carbonDioxyde);
162
+
159
163
  this.sensorAmbientLightServices?.[i]?.updateCharacteristic(Characteristic.CurrentAmbientLightLevel, sensor.ambientLight);
160
164
  this.sensorMotionServices?.[i]?.updateCharacteristic(Characteristic.MotionDetected, sensor.motion);
165
+
166
+
167
+ //energy
168
+ const fields = [
169
+ 'Power', 'ApparentPower', 'ReactivePower', 'EnergyToday', 'EnergyLastDay',
170
+ 'EnergyLifetime', 'Current', 'Voltage', 'Factor', 'Frequency', 'ReadingTime'
171
+ ];
172
+ const characteristic = this.sensorEnergyServices?.[i]?.Characteristic;
173
+ for (const key of fields) {
174
+ characteristic?.[key]?.updateCharacteristic(Characteristic[key], sensor[key.toLowerCase()]);
175
+ }
176
+
161
177
  }
162
178
  }
163
179
  }
@@ -405,6 +421,103 @@ class Sensors extends EventEmitter {
405
421
  });
406
422
  this.sensorMotionServices.push(sensorMotionService);
407
423
  }
424
+
425
+ //energy
426
+ if (sensor.name === 'ENERGY') {
427
+ const debug4 = this.enableDebugMode ? this.emit('debug', `Prepare Power And Energy Service`) : false;
428
+ this.sensorEnergyServices = [];
429
+ const energyService = accessory.addService(Service.PowerAndEnergyService, `Power And Energy`, 'energyService');
430
+ energyService.setCharacteristic(Characteristic.ConfiguredName, `Power And Energy `);
431
+ if (sensor.power) {
432
+ energyService.getCharacteristic(Characteristic.Power)
433
+ .onGet(async () => {
434
+ const value = sensor.power;
435
+ const info = this.disableLogInfo ? false : this.emit('info', ` power: ${value} W`);
436
+ return value;
437
+ });
438
+ }
439
+ if (sensor.apparentPower) {
440
+ energyService.getCharacteristic(Characteristic.ApparentPower)
441
+ .onGet(async () => {
442
+ const value = sensor.apparentPower;
443
+ const info = this.disableLogInfo ? false : this.emit('info', ` apparent power: ${value} VA`);
444
+ return value;
445
+ });
446
+ }
447
+ if (sensor.reactivePower) {
448
+ energyService.getCharacteristic(Characteristic.ReactivePower)
449
+ .onGet(async () => {
450
+ const value = sensor.reactivePower;
451
+ const info = this.disableLogInfo ? false : this.emit('info', ` reactive power: ${value} VAr`);
452
+ return value;
453
+ });
454
+ }
455
+ if (sensor.energyToday) {
456
+ energyService.getCharacteristic(Characteristic.EnergyToday)
457
+ .onGet(async () => {
458
+ const value = sensor.energyToday;
459
+ const info = this.disableLogInfo ? false : this.emit('info', ` energy today: ${value} kWh`);
460
+ return value;
461
+ });
462
+ }
463
+ if (sensor.energyLastDay) {
464
+ energyService.getCharacteristic(Characteristic.EnergyLastDay)
465
+ .onGet(async () => {
466
+ const value = sensor.energyLastDay;
467
+ const info = this.disableLogInfo ? false : this.emit('info', ` energy last seven days: ${value} kWh`);
468
+ return value;
469
+ });
470
+ }
471
+ if (sensor.energyLifetime) {
472
+ energyService.getCharacteristic(Characteristic.EnergyLifetime)
473
+ .onGet(async () => {
474
+ const value = sensor.energyLifetime;
475
+ const info = this.disableLogInfo ? false : this.emit('info', ` energy lifetime: ${value} kWh`);
476
+ return value;
477
+ });
478
+ }
479
+ if (sensor.current) {
480
+ energyService.getCharacteristic(Characteristic.Current)
481
+ .onGet(async () => {
482
+ const value = sensor.current;
483
+ const info = this.disableLogInfo ? false : this.emit('info', ` current: ${value} A`);
484
+ return value;
485
+ });
486
+ }
487
+ if (sensor.voltage) {
488
+ energyService.getCharacteristic(Characteristic.Voltage)
489
+ .onGet(async () => {
490
+ const value = sensor.voltage;
491
+ const info = this.disableLogInfo ? false : this.emit('info', ` voltage: ${value} V`);
492
+ return value;
493
+ });
494
+ }
495
+ if (sensor.factor) {
496
+ energyService.getCharacteristic(Characteristic.Factor)
497
+ .onGet(async () => {
498
+ const value = sensor.factor;
499
+ const info = this.disableLogInfo ? false : this.emit('info', ` power factor: ${value} cos φ`);
500
+ return value;
501
+ });
502
+ }
503
+ if (sensor.frequency) {
504
+ energyService.getCharacteristic(Characteristic.Freqency)
505
+ .onGet(async () => {
506
+ const value = sensor.frequency;
507
+ const info = this.disableLogInfo ? false : this.emit('info', ` frequency: ${value} Hz`);
508
+ return value;
509
+ });
510
+ }
511
+ if (sensor.time) {
512
+ energyService.getCharacteristic(Characteristic.ReadingTime)
513
+ .onGet(async () => {
514
+ const value = sensor.time;
515
+ const info = this.disableLogInfo ? false : this.emit('info', ` last report: ${value}`);
516
+ return value;
517
+ });
518
+ }
519
+ this.sensorEnergyServices.push(energyService);
520
+ }
408
521
  i++;
409
522
  }
410
523
  }