homebridge-tasmota-control 1.4.1-beta.1 → 1.4.1-beta.10

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
@@ -83,10 +83,13 @@ class tasmotaPlatform {
83
83
  return;
84
84
  }
85
85
 
86
+ let i = 0;
86
87
  for (const type of info.deviceTypes) {
88
+ const serialNumber = i === 0 ? info.serialNumber : `${info.serialNumber}${i}`;
89
+
87
90
  let deviceType;
88
91
  switch (type) {
89
- case 0://mielhvac
92
+ case 0: //mielhvac
90
93
  //check files exists, if not then create it
91
94
  try {
92
95
  const postFix = device.host.split('.').join('');
@@ -108,22 +111,22 @@ class tasmotaPlatform {
108
111
  return;
109
112
  }
110
113
 
111
- deviceType = new MiElHvac(api, device, info, refreshInterval);
114
+ deviceType = new MiElHvac(api, device, info, serialNumber, refreshInterval);
112
115
  break;
113
116
  case 1: //switches
114
- deviceType = new Switches(api, device, info, refreshInterval);
117
+ deviceType = new Switches(api, device, info, serialNumber, refreshInterval);
115
118
  break;
116
119
  case 2: //lights
117
- deviceType = new Lights(api, device, info, refreshInterval);
120
+ deviceType = new Lights(api, device, info, serialNumber, refreshInterval);
118
121
  break;
119
122
  case 3: //fans
120
- deviceType = new Fans(api, device, info, refreshInterval);
123
+ deviceType = new Fans(api, device, info, serialNumber, refreshInterval);
121
124
  break;
122
125
  case 4: //sensors
123
- deviceType = new Sensors(api, device, info, refreshInterval);
126
+ deviceType = new Sensors(api, device, info, serialNumber, refreshInterval);
124
127
  break;
125
128
  default:
126
- const emitLog = disableLogWarn ? false : log.warn(`Device: ${host} ${deviceName}, unknown device: ${info.deviceType}.`);
129
+ const emitLog = disableLogWarn ? false : log.warn(`Device: ${host} ${deviceName}, unknown device: ${info.deviceTypes}.`);
127
130
  return;
128
131
  }
129
132
 
@@ -168,6 +171,7 @@ class tasmotaPlatform {
168
171
 
169
172
  //start impulse generator
170
173
  await impulseGenerator.start([{ name: 'start', sampling: 45000 }]);
174
+ i++;
171
175
  }
172
176
  } catch (error) {
173
177
  const emitLog = disableLogError ? false : log.error(`Device: ${host} ${deviceName}, Did finish launching error: ${error}.`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Tasmota Control",
3
3
  "name": "homebridge-tasmota-control",
4
- "version": "1.4.1-beta.1",
4
+ "version": "1.4.1-beta.10",
5
5
  "description": "Homebridge plugin to control Tasmota flashed devices.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/deviceinfo.js CHANGED
@@ -64,16 +64,15 @@ class DeviceInfo extends EventEmitter {
64
64
  const mielhvac = statusSnsKeys.includes('MiElHVAC') ? types.push(0) : false;
65
65
  const lights = statusStsKeys.some(key => LightKeys.includes(key)) ? types.push(2) : false;
66
66
  const fans = statusStsKeys.includes('FanSpeed') ? types.push(3) : false;
67
+ const switches = !mielhvac && !lights && !fans ? types.push(1) : false
67
68
  const sensors = statusSnsKeys.some(key => SensorKeys.includes(key)) ? types.push(4) : false;
68
- const switches = !mielhvac && !lights && !fans && !sensors ? types.push(1) : false
69
69
  const obj = {
70
70
  deviceTypes: types,
71
71
  deviceName: deviceName,
72
72
  friendlyNames: friendlyNames,
73
73
  modelName: modelName,
74
74
  serialNumber: addressMac,
75
- firmwareRevision: firmwareRevision,
76
- relaysCount: friendlyNames.length
75
+ firmwareRevision: firmwareRevision
77
76
  };
78
77
  return obj;
79
78
  } catch (error) {
package/src/fans.js CHANGED
@@ -6,7 +6,7 @@ import { ApiCommands } from './constants.js';
6
6
  let Accessory, Characteristic, Service, Categories, AccessoryUUID;
7
7
 
8
8
  class Fans extends EventEmitter {
9
- constructor(api, config, info, refreshInterval) {
9
+ constructor(api, config, info, serialNumber, refreshInterval) {
10
10
  super();
11
11
 
12
12
  Accessory = api.platformAccessory;
@@ -17,6 +17,8 @@ class Fans extends EventEmitter {
17
17
 
18
18
  //info
19
19
  this.info = info;
20
+ this.serialNumber = serialNumber;
21
+ this.relaysCount = info.friendlyNames.length;
20
22
 
21
23
  //other config
22
24
  this.lightsNamePrefix = config.lightsNamePrefix || false;
@@ -77,7 +79,7 @@ class Fans extends EventEmitter {
77
79
  const statusSts = statusStsSupported ? sensorStatus.StatusSTS : {};
78
80
 
79
81
  //relays
80
- const relaysCount = this.info.relaysCount;
82
+ const relaysCount = this.relaysCount;
81
83
  if (relaysCount > 0) {
82
84
  this.lights = [];
83
85
  this.fans = [];
@@ -174,10 +176,9 @@ class Fans extends EventEmitter {
174
176
  this.emit('devInfo', `----- ${this.info.deviceName} -----`);
175
177
  this.emit('devInfo', `Manufacturer: Tasmota`);
176
178
  this.emit('devInfo', `Hardware: ${this.info.modelName}`);
177
- this.emit('devInfo', `Serialnr: ${this.info.serialNumber}`)
179
+ this.emit('devInfo', `Serialnr: ${this.serialNumber}`)
178
180
  this.emit('devInfo', `Firmware: ${this.info.firmwareRevision}`);
179
- this.emit('devInfo', `Relays: ${this.info.relaysCount}`);
180
- this.emit('devInfo', `Sensors: ${this.sensorsCount}`);
181
+ this.emit('devInfo', `Relays: ${this.relaysCount}`);
181
182
  this.emit('devInfo', `----------------------------------`);
182
183
  return;
183
184
  }
@@ -189,7 +190,7 @@ class Fans extends EventEmitter {
189
190
  try {
190
191
  //accessory
191
192
  const accessoryName = this.info.deviceName;
192
- const accessoryUUID = AccessoryUUID.generate(this.info.serialNumber);
193
+ const accessoryUUID = AccessoryUUID.generate(this.serialNumber);
193
194
  const accessoryCategory = Categories.FAN;
194
195
  const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
195
196
 
@@ -198,7 +199,7 @@ class Fans extends EventEmitter {
198
199
  accessory.getService(Service.AccessoryInformation)
199
200
  .setCharacteristic(Characteristic.Manufacturer, 'Tasmota')
200
201
  .setCharacteristic(Characteristic.Model, this.info.modelName ?? 'Model Name')
201
- .setCharacteristic(Characteristic.SerialNumber, this.info.serialNumber ?? 'Serial Number')
202
+ .setCharacteristic(Characteristic.SerialNumber, this.serialNumber ?? 'Serial Number')
202
203
  .setCharacteristic(Characteristic.FirmwareRevision, this.info.firmwareRevision.replace(/[a-zA-Z]/g, '') ?? '0')
203
204
  .setCharacteristic(Characteristic.ConfiguredName, accessoryName);
204
205
 
package/src/lights.js CHANGED
@@ -6,7 +6,7 @@ import { ApiCommands } from './constants.js';
6
6
  let Accessory, Characteristic, Service, Categories, AccessoryUUID;
7
7
 
8
8
  class Lights extends EventEmitter {
9
- constructor(api, config, info, refreshInterval) {
9
+ constructor(api, config, info, serialNumber, refreshInterval) {
10
10
  super();
11
11
 
12
12
  Accessory = api.platformAccessory;
@@ -17,6 +17,8 @@ class Lights extends EventEmitter {
17
17
 
18
18
  //info
19
19
  this.info = info;
20
+ this.serialNumber = serialNumber;
21
+ this.relaysCount = info.friendlyNames.length;
20
22
 
21
23
  //other config
22
24
  this.lightsNamePrefix = config.lightsNamePrefix || false;
@@ -77,7 +79,7 @@ class Lights extends EventEmitter {
77
79
  const statusSts = statusStsSupported ? sensorStatus.StatusSTS : {};
78
80
 
79
81
  //relays
80
- const relaysCount = this.info.relaysCount;
82
+ const relaysCount = this.relaysCount;
81
83
  if (relaysCount > 0) {
82
84
  this.lights = [];
83
85
 
@@ -191,9 +193,9 @@ class Lights extends EventEmitter {
191
193
  this.emit('devInfo', `----- ${this.info.deviceName} -----`);
192
194
  this.emit('devInfo', `Manufacturer: Tasmota`);
193
195
  this.emit('devInfo', `Hardware: ${this.info.modelName}`);
194
- this.emit('devInfo', `Serialnr: ${this.info.serialNumber}`)
196
+ this.emit('devInfo', `Serialnr: ${this.serialNumber}`)
195
197
  this.emit('devInfo', `Firmware: ${this.info.firmwareRevision}`);
196
- this.emit('devInfo', `Relays: ${this.info.relaysCount}`);
198
+ this.emit('devInfo', `Relays: ${this.relaysCount}`);
197
199
  this.emit('devInfo', `----------------------------------`);
198
200
  return;
199
201
  }
@@ -205,7 +207,7 @@ class Lights extends EventEmitter {
205
207
  try {
206
208
  //accessory
207
209
  const accessoryName = this.info.deviceName;
208
- const accessoryUUID = AccessoryUUID.generate(this.info.serialNumber);
210
+ const accessoryUUID = AccessoryUUID.generate(this.serialNumber);
209
211
  const accessoryCategory = Categories.LIGHTBULB
210
212
  const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
211
213
 
@@ -214,7 +216,7 @@ class Lights extends EventEmitter {
214
216
  accessory.getService(Service.AccessoryInformation)
215
217
  .setCharacteristic(Characteristic.Manufacturer, 'Tasmota')
216
218
  .setCharacteristic(Characteristic.Model, this.info.modelName ?? 'Model Name')
217
- .setCharacteristic(Characteristic.SerialNumber, this.info.serialNumber ?? 'Serial Number')
219
+ .setCharacteristic(Characteristic.SerialNumber, this.serialNumber ?? 'Serial Number')
218
220
  .setCharacteristic(Characteristic.FirmwareRevision, this.info.firmwareRevision.replace(/[a-zA-Z]/g, '') ?? '0')
219
221
  .setCharacteristic(Characteristic.ConfiguredName, accessoryName);
220
222
 
package/src/mielhvac.js CHANGED
@@ -6,7 +6,7 @@ import { ApiCommands, MiElHVAC, TemperatureDisplayUnits } from './constants.js';
6
6
  let Accessory, Characteristic, Service, Categories, AccessoryUUID;
7
7
 
8
8
  class MiElHvac extends EventEmitter {
9
- constructor(api, config, info, refreshInterval) {
9
+ constructor(api, config, info, serialNumber, refreshInterval) {
10
10
  super();
11
11
 
12
12
  Accessory = api.platformAccessory;
@@ -17,6 +17,7 @@ class MiElHvac extends EventEmitter {
17
17
 
18
18
  //info
19
19
  this.info = info;
20
+ this.serialNumber = serialNumber;
20
21
 
21
22
  //mitsubishi ac
22
23
  const miElHvac = config.miElHvac ?? {};
@@ -811,7 +812,7 @@ class MiElHvac extends EventEmitter {
811
812
  this.emit('devInfo', `----- ${this.info.deviceName} -----`);
812
813
  this.emit('devInfo', `Manufacturer: Tasmota`);
813
814
  this.emit('devInfo', `Hardware: ${this.info.modelName}`);
814
- this.emit('devInfo', `Serialnr: ${this.info.serialNumber}`)
815
+ this.emit('devInfo', `Serialnr: ${this.serialNumber}`)
815
816
  this.emit('devInfo', `Firmware: ${this.info.firmwareRevision}`);
816
817
  this.emit('devInfo', `Sensor: MiELHVAC`);
817
818
  this.emit('devInfo', `----------------------------------`);
@@ -825,7 +826,7 @@ class MiElHvac extends EventEmitter {
825
826
  try {
826
827
  //accessory
827
828
  const accessoryName = this.info.deviceName;
828
- const accessoryUUID = AccessoryUUID.generate(this.info.serialNumber);
829
+ const accessoryUUID = AccessoryUUID.generate(this.serialNumber);
829
830
  const accessoryCategory = Categories.AIR_CONDITIONER
830
831
  const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
831
832
 
@@ -834,7 +835,7 @@ class MiElHvac extends EventEmitter {
834
835
  accessory.getService(Service.AccessoryInformation)
835
836
  .setCharacteristic(Characteristic.Manufacturer, 'Tasmota')
836
837
  .setCharacteristic(Characteristic.Model, this.info.modelName ?? 'Model Name')
837
- .setCharacteristic(Characteristic.SerialNumber, this.info.serialNumber ?? 'Serial Number')
838
+ .setCharacteristic(Characteristic.SerialNumber, this.serialNumber ?? 'Serial Number')
838
839
  .setCharacteristic(Characteristic.FirmwareRevision, this.info.firmwareRevision.replace(/[a-zA-Z]/g, '') ?? '0')
839
840
  .setCharacteristic(Characteristic.ConfiguredName, accessoryName);
840
841
 
@@ -846,7 +847,7 @@ class MiElHvac extends EventEmitter {
846
847
  const coolDryFanMode = [MiElHVAC.SetMode.cool, MiElHVAC.SetMode.cool, MiElHVAC.SetMode.dry, MiElHVAC.SetMode.fan][this.coolDryFanMode]; //NONE, COOL, DRY, FAN
847
848
 
848
849
  //services
849
- this.miElHvacService = new Service.HeaterCooler(accessoryName, `HeaterCooler ${this.info.serialNumber}`);
850
+ this.miElHvacService = new Service.HeaterCooler(accessoryName, `HeaterCooler ${this.serialNumber}`);
850
851
  this.miElHvacService.setPrimaryService(true);
851
852
  this.miElHvacService.getCharacteristic(Characteristic.Active)
852
853
  .onGet(async () => {
package/src/sensors.js CHANGED
@@ -6,7 +6,7 @@ import { ApiCommands, SensorKeys } from './constants.js';
6
6
  let Accessory, Characteristic, Service, Categories, AccessoryUUID;
7
7
 
8
8
  class Sensors extends EventEmitter {
9
- constructor(api, config, info, refreshInterval) {
9
+ constructor(api, config, info, serialNumber, refreshInterval) {
10
10
  super();
11
11
 
12
12
  Accessory = api.platformAccessory;
@@ -17,6 +17,7 @@ class Sensors extends EventEmitter {
17
17
 
18
18
  //info
19
19
  this.info = info;
20
+ this.serialNumber = serialNumber;
20
21
 
21
22
  //other config
22
23
  this.sensorsNamePrefix = config.sensorsNamePrefix || false;
@@ -85,19 +86,7 @@ class Sensors extends EventEmitter {
85
86
 
86
87
  //status SNS
87
88
  if (statusSnsSupported) {
88
- this.sensorsName = [];
89
- this.sensorsTemperature = [];
90
- this.sensorsReferenceTemperature = [];
91
- this.sensorsObjTemperature = [];
92
- this.sensorsAmbTemperature = [];
93
- this.sensorsDewPointTemperature = [];
94
- this.sensorsHumidity = [];
95
- this.sensorsPressure = [];
96
- this.sensorsGas = [];
97
- this.sensorsCarbonDioxyde = [];
98
- this.sensorsAmbientLight = [];
99
- this.sensorsMotion = [];
100
-
89
+ this.sensors = [];
101
90
  const sensor = Object.entries(statusSns)
102
91
  .filter(([key]) => SensorKeys.some(type => key.includes(type)))
103
92
  .reduce((obj, [key, value]) => {
@@ -106,133 +95,63 @@ class Sensors extends EventEmitter {
106
95
  }, {});
107
96
 
108
97
  for (const [key, value] of Object.entries(sensor)) {
109
- const sensorName = key ?? `Sensor`;
110
98
  const sensorData = value;
111
99
 
112
100
  //sensors
113
- const temperature = sensorData.Temperature ?? false;
114
- const referenceTemperature = sensorData.ReferenceTemperature ?? false;
115
- const objTemperature = sensorData.OBJTMP ?? false;
116
- const ambTemperature = sensorData.AMBTMP ?? false;
117
- const dewPointTemperature = sensorData.DewPoint ?? false;
118
- const humidity = sensorData.Humidity ?? false;
119
- const pressure = sensorData.Pressure ?? false;
120
- const gas = sensorData.Gas ?? false;
121
- const carbonDioxyde = sensorData.CarbonDioxyde ?? false;
122
- const ambientLight = sensorData.Ambient ?? false;
123
- const motion = sensorData === 'ON';
124
-
125
- //energy
126
- const energyTotalStartTime = sensorData.TotalStartTime ?? '';
127
- const energyTotal = sensorData.Total ?? 0;
128
- const energyPeriod = sensorData.Period ?? 0;
129
- const energyYesterday = sensorData.Yesterday ?? 0;
130
- const energyToday = sensorData.Today ?? 0;
131
- const power = sensorData.Power ?? 0;
132
- const apparentPower = sensorData.ApparentPower ?? 0;
133
- const reactivePower = sensorData.ReactivePower ?? 0;
134
- const factor = sensorData.Factor ?? 0;
135
- const voltage = sensorData.Voltage ?? 0;
136
- const current = sensorData.Current ?? 0;
137
- const load = sensorData.Load ?? 0;
101
+ const obj = {
102
+ name: key ?? `Sensor`,
103
+ temperature: sensorData.Temperature,
104
+ referenceTemperature: sensorData.ReferenceTemperature,
105
+ objTemperature: sensorData.OBJTMP,
106
+ ambTemperature: sensorData.AMBTMP,
107
+ dewPointTemperature: sensorData.DewPoint,
108
+ humidity: sensorData.Humidity,
109
+ pressure: sensorData.Pressure,
110
+ gas: sensorData.Gas,
111
+ carbonDioxyde: sensorData.CarbonDioxyde,
112
+ ambientLight: sensorData.Ambient,
113
+ motion: sensorData === 'ON',
114
+
115
+ //energy
116
+ energyTotalStartTime: sensorData.TotalStartTime ?? '',
117
+ energyTotal: sensorData.Total ?? 0,
118
+ energyPeriod: sensorData.Period ?? 0,
119
+ energyYesterday: sensorData.Yesterday ?? 0,
120
+ energyToday: sensorData.Today ?? 0,
121
+ power: sensorData.Power ?? 0,
122
+ apparentPower: sensorData.ApparentPower ?? 0,
123
+ reactivePower: sensorData.ReactivePower ?? 0,
124
+ factor: sensorData.Factor ?? 0,
125
+ voltage: sensorData.Voltage ?? 0,
126
+ current: sensorData.Current ?? 0,
127
+ load: sensorData.Load ?? 0
128
+ }
138
129
 
139
130
  //push to array
140
- this.sensorsName.push(sensorName);
141
- const push1 = temperature ? this.sensorsTemperature.push(temperature) : false;
142
- const push2 = referenceTemperature ? this.sensorsReferenceTemperature.push(referenceTemperature) : false;
143
- const push3 = objTemperature ? this.sensorsAmbTemperature.push(objTemperature) : false;
144
- const push4 = ambTemperature ? this.sensorsAmbTemperature.push(ambTemperature) : false;
145
- const push5 = dewPointTemperature ? this.sensorsDewPointTemperature.push(dewPointTemperature) : false;
146
- const push6 = humidity ? this.sensorsHumidity.push(humidity) : false;
147
- const push7 = pressure ? this.sensorsPressure.push(pressure) : false;
148
- const push8 = gas ? this.sensorsGas.push(gas) : false;
149
- const push9 = carbonDioxyde ? this.sensorsCarbonDioxyde.push(carbonDioxyde) : false;
150
- const push10 = ambientLight ? this.sensorsAmbientLight.push(ambientLight) : false;
151
- const push11 = motion ? this.sensorsMotion.push(motion) : false;
131
+ this.sensors.push(obj);
152
132
  }
153
133
 
154
134
  this.time = sensorStatus.Time ?? '';
155
135
  this.tempUnit = sensorStatus.TempUnit === 'C' ? '°C' : 'F';
156
136
  this.pressureUnit = sensorStatus.PressureUnit ?? 'hPa';
157
- this.sensorsTemperatureCount = this.sensorsTemperature.length;
158
- this.sensorsReferenceTemperatureCount = this.sensorsReferenceTemperature.length;
159
- this.sensorsObjTemperatureCount = this.sensorsObjTemperature.length;
160
- this.sensorsAmbTemperatureCount = this.sensorsAmbTemperature.length;
161
- this.sensorsDewPointTemperatureCount = this.sensorsDewPointTemperature.length;
162
- this.sensorsHumidityCount = this.sensorsHumidity.length;
163
- this.sensorsPressureCount = this.sensorsPressure.length;
164
- this.sensorsGasCount = this.sensorsGas.length;
165
- this.sensorsCarbonDioxydeCount = this.sensorsCarbonDioxyde.length;
166
- this.sensorsAmbientLightCount = this.sensorsAmbientLight.length;
167
- this.sensorsMotionCount = this.sensorsMotion.length;
168
- this.sensorsCount = this.sensorsName.length;
169
-
137
+ this.sensorsCount = this.sensors.length;
170
138
 
171
139
  //update characteristics
172
- if (this.sensorTemperatureServices) {
173
- for (let i = 0; i < this.sensorsTemperatureCount; i++) {
174
- const value = this.sensorsTemperature[i];
175
- this.sensorTemperatureServices[i].updateCharacteristic(Characteristic.CurrentTemperature, value);
176
- }
177
- }
178
-
179
- if (this.sensorReferenceTemperatureServices) {
180
- for (let i = 0; i < this.sensorsReferenceTemperatureCount; i++) {
181
- const value = this.sensorsReferenceTemperature[i];
182
- this.sensorReferenceTemperatureServices[i].updateCharacteristic(Characteristic.CurrentTemperature, value);
183
- }
184
- }
185
-
186
- if (this.sensorObjTemperatureServices) {
187
- for (let i = 0; i < this.sensorsObjTemperatureCount; i++) {
188
- const value = this.sensorsObjTemperature[i];
189
- this.sensorObjTemperatureServices[i].updateCharacteristic(Characteristic.CurrentTemperature, value);
190
- }
191
- }
192
-
193
- if (this.sensorAmbTemperatureServices) {
194
- for (let i = 0; i < this.sensorsAmbTemperatureCount; i++) {
195
- const value = this.sensorsAmbTemperature[i];
196
- this.sensorAmbTemperatureServices[i].updateCharacteristic(Characteristic.CurrentTemperature, value);
197
- }
198
- }
199
-
200
- if (this.sensorDewPointTemperatureServices) {
201
- for (let i = 0; i < this.sensorsDewPointTemperatureCount; i++) {
202
- const value = this.sensorsDewPointTemperature[i];
203
- this.sensorDewPointTemperatureServices[i].updateCharacteristic(Characteristic.CurrentTemperature, value);
204
- }
205
- }
206
-
207
- if (this.sensorHumidityServices) {
208
- for (let i = 0; i < this.sensorsHumidityCount; i++) {
209
- const value = this.sensorsHumidity[i];
210
- this.sensorHumidityServices[i].updateCharacteristic(Characteristic.CurrentRelativeHumidity, value);
211
- }
212
- }
213
-
214
- if (this.sensorCarbonDioxydeServices) {
215
- for (let i = 0; i < this.sensorsCarbonDioxydeCount; i++) {
216
- const state = this.sensorsCarbonDioxyde[i] > 1000;
217
- const value = this.sensorsCarbonDioxyde[i];
218
- this.sensorCarbonDioxydeServices[i]
219
- .updateCharacteristic(Characteristic.CarbonDioxideDetected, state)
220
- .updateCharacteristic(Characteristic.CarbonDioxideLevel, value)
221
- .updateCharacteristic(Characteristic.CarbonDioxidePeakLevel, value);
222
- }
223
- }
224
-
225
- if (this.sensorAmbientLightServices) {
226
- for (let i = 0; i < this.sensorsAmbientLightCount; i++) {
227
- const value = this.sensorsAmbientLight[i];
228
- this.sensorAmbientLightServices[i].updateCharacteristic(Characteristic.CurrentAmbientLightLevel, value);
229
- }
230
- }
231
-
232
- if (this.sensorMotionServices) {
233
- for (let i = 0; i < this.sensorsMotionCount; i++) {
234
- const state = this.sensorsMotion[i];
235
- this.sensorMotionServices[i].updateCharacteristic(Characteristic.MotionDetected, state);
140
+ if (this.sensorsCount > 0) {
141
+ for (let i = 0; i < this.sensorsCount; i++) {
142
+ const sensor = this.sensors[i];
143
+ this.sensorTemperatureServices?.[i]?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.temperature);
144
+ this.sensorReferenceTemperatureServices?.[i]?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.referenceTemperature);
145
+ this.sensorObjTemperatureServices?.[i]?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.objTemperature);
146
+ this.sensorAmbTemperatureServices?.[i]?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.ambTemperature);
147
+ this.sensorDewPointTemperatureServices?.[i]?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.dewPointTemperature);
148
+ this.sensorHumidityServices?.[i]?.updateCharacteristic(Characteristic.CurrentRelativeHumidity, sensor.humidity);
149
+ this.sensorCarbonDioxydeServices?.[i]
150
+ ?.updateCharacteristic(Characteristic.CarbonDioxideDetected, sensor.carbonDioxyde > 1000)
151
+ .updateCharacteristic(Characteristic.CarbonDioxideLevel, sensor.carbonDioxyde)
152
+ .updateCharacteristic(Characteristic.CarbonDioxidePeakLevel, sensor.carbonDioxyde);
153
+ this.sensorAmbientLightServices?.[i]?.updateCharacteristic(Characteristic.CurrentAmbientLightLevel, sensor.ambientLight);
154
+ this.sensorMotionServices?.[i]?.updateCharacteristic(Characteristic.MotionDetected, sensor.motion);
236
155
  }
237
156
  }
238
157
  }
@@ -278,7 +197,7 @@ class Sensors extends EventEmitter {
278
197
  this.emit('devInfo', `----- ${this.info.deviceName} -----`);
279
198
  this.emit('devInfo', `Manufacturer: Tasmota`);
280
199
  this.emit('devInfo', `Hardware: ${this.info.modelName}`);
281
- this.emit('devInfo', `Serialnr: ${this.info.serialNumber}`)
200
+ this.emit('devInfo', `Serialnr: ${this.serialNumber}`)
282
201
  this.emit('devInfo', `Firmware: ${this.info.firmwareRevision}`);
283
202
  this.emit('devInfo', `Sensors: ${this.sensorsCount}`);
284
203
  this.emit('devInfo', `----------------------------------`);
@@ -292,7 +211,7 @@ class Sensors extends EventEmitter {
292
211
  try {
293
212
  //accessory
294
213
  const accessoryName = this.info.deviceName;
295
- const accessoryUUID = AccessoryUUID.generate(this.info.serialNumber);
214
+ const accessoryUUID = AccessoryUUID.generate(this.serialNumber);
296
215
  const accessoryCategory = Categories.SENSOR;
297
216
  const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
298
217
 
@@ -301,7 +220,7 @@ class Sensors extends EventEmitter {
301
220
  accessory.getService(Service.AccessoryInformation)
302
221
  .setCharacteristic(Characteristic.Manufacturer, 'Tasmota')
303
222
  .setCharacteristic(Characteristic.Model, this.info.modelName ?? 'Model Name')
304
- .setCharacteristic(Characteristic.SerialNumber, this.info.serialNumber ?? 'Serial Number')
223
+ .setCharacteristic(Characteristic.SerialNumber, this.serialNumber ?? 'Serial Number')
305
224
  .setCharacteristic(Characteristic.FirmwareRevision, this.info.firmwareRevision.replace(/[a-zA-Z]/g, '') ?? '0')
306
225
  .setCharacteristic(Characteristic.ConfiguredName, accessoryName);
307
226
 
@@ -310,12 +229,11 @@ class Sensors extends EventEmitter {
310
229
  const debug = this.enableDebugMode ? this.emit('debug', `Prepare Sensor Services`) : false;
311
230
 
312
231
  //temperature
313
- const sensorsTemperatureCount = this.sensorsTemperatureCount;
314
- if (sensorsTemperatureCount > 0) {
315
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Temperature Sensor Services`) : false;
316
- this.sensorTemperatureServices = [];
317
- for (let i = 0; i < sensorsTemperatureCount; i++) {
318
- const sensorName = this.sensorsName[i];
232
+ for (const sensor of this.sensors) {
233
+ const sensorName = sensor.name;
234
+ if (sensor.temperature !== undefined) {
235
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Temperature Sensor Services`) : false;
236
+ this.sensorTemperatureServices = [];
319
237
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Temperature` : `${sensorName} Temperature`;
320
238
  const sensorTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Temperature Sensor ${i}`);
321
239
  sensorTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
@@ -328,15 +246,11 @@ class Sensors extends EventEmitter {
328
246
  });
329
247
  this.sensorTemperatureServices.push(sensorTemperatureService);
330
248
  }
331
- }
332
249
 
333
- //reference temperature
334
- const sensorsReferenceTemperatureCount = this.sensorsReferenceTemperatureCount;
335
- if (sensorsReferenceTemperatureCount > 0) {
336
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Reference Temperature Sensor Services`) : false;
337
- this.sensorReferenceTemperatureServices = [];
338
- for (let i = 0; i < sensorsReferenceTemperatureCount; i++) {
339
- const sensorName = this.sensorsName[i];
250
+ //reference temperature
251
+ if (sensor.referenceTemperature !== undefined) {
252
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Reference Temperature Sensor Services`) : false;
253
+ this.sensorReferenceTemperatureServices = [];
340
254
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Reference Temperature` : `${sensorName} Reference Temperature`;
341
255
  const sensorReferenceTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Reference Temperature Sensor ${i}`);
342
256
  sensorReferenceTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
@@ -349,15 +263,11 @@ class Sensors extends EventEmitter {
349
263
  });
350
264
  this.sensorReferenceTemperatureServices.push(sensorReferenceTemperatureService);
351
265
  }
352
- }
353
266
 
354
- //object temperature
355
- const sensorsObjTemperatureCount = this.sensorsObjTemperatureCount;
356
- if (sensorsObjTemperatureCount > 0) {
357
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Obj Temperature Sensor Services`) : false;
358
- this.sensorObjTemperatureServices = [];
359
- for (let i = 0; i < sensorsObjTemperatureCount; i++) {
360
- const sensorName = this.sensorsName[i];
267
+ //object temperature
268
+ if (sensor.objTemperature !== undefined) {
269
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Obj Temperature Sensor Services`) : false;
270
+ this.sensorObjTemperatureServices = [];
361
271
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Obj Temperature` : `${sensorName} Obj Temperature`;
362
272
  const sensorObjTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Obj Temperature Sensor ${i}`);
363
273
  sensorObjTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
@@ -370,15 +280,11 @@ class Sensors extends EventEmitter {
370
280
  });
371
281
  this.sensorObjTemperatureServices.push(sensorObjTemperatureService);
372
282
  }
373
- }
374
283
 
375
- //ambient temperature
376
- const sensorsAmbTemperatureCount = this.sensorsAmbTemperatureCount;
377
- if (sensorsAmbTemperatureCount > 0) {
378
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Amb Temperature Sensor Services`) : false;
379
- this.sensorAmbTemperatureServices = [];
380
- for (let i = 0; i < sensorsAmbTemperatureCount; i++) {
381
- const sensorName = this.sensorsName[i];
284
+ //ambient temperature
285
+ if (sensor.ambTemperature !== undefined) {
286
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Amb Temperature Sensor Services`) : false;
287
+ this.sensorAmbTemperatureServices = [];
382
288
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Amb Temperature` : `${sensorName} Amb Temperature`;
383
289
  const sensorAmbTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Amb Temperature Sensor ${i}`);
384
290
  sensorAmbTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
@@ -391,15 +297,11 @@ class Sensors extends EventEmitter {
391
297
  });
392
298
  this.sensorAmbTemperatureServices.push(sensorAmbTemperatureService);
393
299
  }
394
- }
395
300
 
396
- //dew point temperature
397
- const sensorsDewPointTemperatureCount = this.sensorsDewPointTemperatureCount;
398
- if (sensorsDewPointTemperatureCount > 0) {
399
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Dew Point Temperature Sensor Services`) : false;
400
- this.sensorDewPointTemperatureServices = [];
401
- for (let i = 0; i < sensorsDewPointTemperatureCount; i++) {
402
- const sensorName = this.sensorsName[i];
301
+ //dew point temperature
302
+ if (sensor.dewPointTemperature !== undefined) {
303
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Dew Point Temperature Sensor Services`) : false;
304
+ this.sensorDewPointTemperatureServices = [];
403
305
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Dew Point` : `${sensorName} Dew Point`;
404
306
  const sensorDewPointTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Dew Point Temperature Sensor ${i}`);
405
307
  sensorDewPointTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
@@ -412,15 +314,11 @@ class Sensors extends EventEmitter {
412
314
  });
413
315
  this.sensorDewPointTemperatureServices.push(sensorDewPointTemperatureService);
414
316
  }
415
- }
416
317
 
417
- //humidity
418
- const sensorsHumidityCount = this.sensorsHumidityCount;
419
- if (sensorsHumidityCount > 0) {
420
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Humidity Sensor Services`) : false;
421
- this.sensorHumidityServices = [];
422
- for (let i = 0; i < sensorsHumidityCount; i++) {
423
- const sensorName = this.sensorsName[i];
318
+ //humidity
319
+ if (sensor.humidity !== undefined) {
320
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Humidity Sensor Services`) : false;
321
+ this.sensorHumidityServices = [];
424
322
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Humidity` : `${sensorName} Humidity`;
425
323
  const sensorHumidityService = accessory.addService(Service.HumiditySensor, serviceName, `Humidity Sensor ${i}`);
426
324
  sensorHumidityService.addOptionalCharacteristic(Characteristic.ConfiguredName);
@@ -433,19 +331,15 @@ class Sensors extends EventEmitter {
433
331
  });
434
332
  this.sensorHumidityServices.push(sensorHumidityService);
435
333
  }
436
- }
437
334
 
438
- //pressure
335
+ //pressure
439
336
 
440
- //gas
337
+ //gas
441
338
 
442
- //carbon dioxyde
443
- const sensorsCarbonDioxydeCount = this.sensorsCarbonDioxydeCount;
444
- if (sensorsCarbonDioxydeCount > 0) {
445
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Carbon Dioxyde Sensor Services`) : false;
446
- this.sensorCarbonDioxydeServices = [];
447
- for (let i = 0; i < sensorsCarbonDioxydeCount; i++) {
448
- const sensorName = this.sensorsName[i];
339
+ //carbon dioxyde
340
+ if (sensor.carbonDioxyde !== undefined) {
341
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Carbon Dioxyde Sensor Services`) : false;
342
+ this.sensorCarbonDioxydeServices = [];
449
343
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Carbon Dioxyde` : `${sensorName} Carbon Dioxyde`;
450
344
  const sensorCarbonDioxydeService = accessory.addService(Service.CarbonDioxideSensor, serviceName, `Carbon Dioxyde Sensor ${i}`);
451
345
  sensorCarbonDioxydeService.addOptionalCharacteristic(Characteristic.ConfiguredName);
@@ -470,15 +364,11 @@ class Sensors extends EventEmitter {
470
364
  });
471
365
  this.sensorCarbonDioxydeServices.push(sensorCarbonDioxydeService);
472
366
  }
473
- }
474
367
 
475
- //ambient light
476
- const sensorsAmbientLightCount = this.sensorsAmbientLightCount;
477
- if (sensorsAmbientLightCount > 0) {
478
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Ambient Light Sensor Services`) : false;
479
- this.sensorAmbientLightServices = [];
480
- for (let i = 0; i < sensorsAmbientLightCount; i++) {
481
- const sensorName = this.sensorsName[i];
368
+ //ambient light
369
+ if (sensor.ambientLight !== undefined) {
370
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Ambient Light Sensor Services`) : false;
371
+ this.sensorAmbientLightServices = [];
482
372
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Ambient Light` : `${sensorName} Ambient Light`;
483
373
  const sensorAmbientLightService = accessory.addService(Service.LightSensor, serviceName, `Ambient Light Sensor ${i}`);
484
374
  sensorAmbientLightService.addOptionalCharacteristic(Characteristic.ConfiguredName);
@@ -491,15 +381,11 @@ class Sensors extends EventEmitter {
491
381
  });
492
382
  this.sensorAmbientLightServices.push(sensorAmbientLightService);
493
383
  }
494
- }
495
384
 
496
- //motion
497
- const sensorsMotionCount = this.sensorsMotionCount;
498
- if (sensorsMotionCount > 0) {
499
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Motion Sensor Services`) : false;
500
- this.sensorMotionServices = [];
501
- for (let i = 0; i < sensorsMotionCount; i++) {
502
- const sensorName = this.sensorsName[i];
385
+ //motion
386
+ if (sensor.motion !== undefined) {
387
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Motion Sensor Services`) : false;
388
+ this.sensorMotionServices = [];
503
389
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Motion` : `${sensorName} Motion`;
504
390
  const sensorMotionService = accessory.addService(Service.MotionSensor, serviceName, `Motion Sensor ${i}`);
505
391
  sensorMotionService.addOptionalCharacteristic(Characteristic.ConfiguredName);
package/src/switches.js CHANGED
@@ -6,7 +6,7 @@ import { ApiCommands } from './constants.js';
6
6
  let Accessory, Characteristic, Service, Categories, AccessoryUUID;
7
7
 
8
8
  class Switches extends EventEmitter {
9
- constructor(api, config, info, refreshInterval) {
9
+ constructor(api, config, info, serialNumber, refreshInterval) {
10
10
  super();
11
11
 
12
12
  Accessory = api.platformAccessory;
@@ -17,6 +17,8 @@ class Switches extends EventEmitter {
17
17
 
18
18
  //info
19
19
  this.info = info;
20
+ this.serialNumber = serialNumber;
21
+ this.relaysCount = info.friendlyNames.length;
20
22
 
21
23
  //other config
22
24
  this.relaysDisplayType = config.relaysDisplayType || 0;
@@ -64,7 +66,7 @@ class Switches extends EventEmitter {
64
66
  const debug = this.enableDebugMode ? this.emit('debug', `Power status: ${JSON.stringify(powerStatus, null, 2)}`) : false;
65
67
 
66
68
  //relays
67
- const relaysCount = this.info.relaysCount;
69
+ const relaysCount = this.relaysCount;
68
70
  if (relaysCount > 0) {
69
71
  this.switchesOutlets = [];
70
72
 
@@ -134,9 +136,9 @@ class Switches extends EventEmitter {
134
136
  this.emit('devInfo', `----- ${this.info.deviceName} -----`);
135
137
  this.emit('devInfo', `Manufacturer: Tasmota`);
136
138
  this.emit('devInfo', `Hardware: ${this.info.modelName}`);
137
- this.emit('devInfo', `Serialnr: ${this.info.serialNumber}`)
139
+ this.emit('devInfo', `Serialnr: ${this.serialNumber}`)
138
140
  this.emit('devInfo', `Firmware: ${this.info.firmwareRevision}`);
139
- this.emit('devInfo', `Relays: ${this.info.relaysCount}`);
141
+ this.emit('devInfo', `Relays: ${this.relaysCount}`);
140
142
  this.emit('devInfo', `----------------------------------`);
141
143
  return;
142
144
  }
@@ -148,7 +150,7 @@ class Switches extends EventEmitter {
148
150
  try {
149
151
  //accessory
150
152
  const accessoryName = this.info.deviceName;
151
- const accessoryUUID = AccessoryUUID.generate(this.info.serialNumber);
153
+ const accessoryUUID = AccessoryUUID.generate(this.serialNumber);
152
154
  const accessoryCategory = this.relaysDisplayType === 0 ? Categories.OUTLET : Categories.SWITCH;
153
155
  const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
154
156
 
@@ -157,7 +159,7 @@ class Switches extends EventEmitter {
157
159
  accessory.getService(Service.AccessoryInformation)
158
160
  .setCharacteristic(Characteristic.Manufacturer, 'Tasmota')
159
161
  .setCharacteristic(Characteristic.Model, this.info.modelName ?? 'Model Name')
160
- .setCharacteristic(Characteristic.SerialNumber, this.info.serialNumber ?? 'Serial Number')
162
+ .setCharacteristic(Characteristic.SerialNumber, this.serialNumber ?? 'Serial Number')
161
163
  .setCharacteristic(Characteristic.FirmwareRevision, this.info.firmwareRevision.replace(/[a-zA-Z]/g, '') ?? '0')
162
164
  .setCharacteristic(Characteristic.ConfiguredName, accessoryName);
163
165