homebridge-tasmota-control 1.4.1-beta.9 → 1.5.1-beta.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/CHANGELOG.md CHANGED
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.5.0] - (31.05.2025)
9
+
10
+ ## Changes
11
+
12
+ - added support for sensors as a seperate accessory
13
+ - redme updated
14
+ - cleanup
15
+
8
16
  ## [1.4.0] - (30.05.2025)
9
17
 
10
18
  ## Changes
package/README.md CHANGED
@@ -76,7 +76,7 @@ Homebridge plugin for Tasmota flashed devices.
76
76
  * Light - `Power ON/OFF`, `Dimmer`, `Color Temperature`, `Hue`, `Saturation`
77
77
  * Outlet - `Power ON/OFF`
78
78
  * Switch - `Power ON/OFF`
79
- * Fan - `Power ON/OFF`, `Speed`
79
+ * Fan - `Fan ON/OFF`, `Speed`, `Light ON/OFF`
80
80
 
81
81
  * Supported Sensors:
82
82
  * Temperature - `Temperature`, `Dew Point`, `Reference`, `Obj`, `Amb`
package/index.js CHANGED
@@ -144,7 +144,7 @@ class tasmotaPlatform {
144
144
  const emitLog = disableLogInfo ? false : log.info(`Device: ${host} ${deviceName}, ${info}.`);
145
145
  })
146
146
  .on('debug', (debug) => {
147
- const emitLog = !enableDebugMode ? false : log.info(`Device: ${host} ${deviceName}, debug: ${debug}.`);
147
+ const emitLog = enableDebugMode ? false : log.info(`Device: ${host} ${deviceName}, debug: ${debug}.`);
148
148
  })
149
149
  .on('warn', (warn) => {
150
150
  const emitLog = disableLogWarn ? false : log.warn(`Device: ${host} ${deviceName}, ${warn}.`);
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.9",
4
+ "version": "1.5.1-beta.0",
5
5
  "description": "Homebridge plugin to control Tasmota flashed devices.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/deviceinfo.js CHANGED
@@ -72,8 +72,7 @@ class DeviceInfo extends EventEmitter {
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
@@ -18,6 +18,7 @@ class Fans extends EventEmitter {
18
18
  //info
19
19
  this.info = info;
20
20
  this.serialNumber = serialNumber;
21
+ this.relaysCount = info.friendlyNames.length;
21
22
 
22
23
  //other config
23
24
  this.lightsNamePrefix = config.lightsNamePrefix || false;
@@ -78,7 +79,7 @@ class Fans extends EventEmitter {
78
79
  const statusSts = statusStsSupported ? sensorStatus.StatusSTS : {};
79
80
 
80
81
  //relays
81
- const relaysCount = this.info.relaysCount;
82
+ const relaysCount = this.relaysCount;
82
83
  if (relaysCount > 0) {
83
84
  this.lights = [];
84
85
  this.fans = [];
@@ -177,8 +178,7 @@ class Fans extends EventEmitter {
177
178
  this.emit('devInfo', `Hardware: ${this.info.modelName}`);
178
179
  this.emit('devInfo', `Serialnr: ${this.serialNumber}`)
179
180
  this.emit('devInfo', `Firmware: ${this.info.firmwareRevision}`);
180
- this.emit('devInfo', `Relays: ${this.info.relaysCount}`);
181
- this.emit('devInfo', `Sensors: ${this.sensorsCount}`);
181
+ this.emit('devInfo', `Relays: ${this.relaysCount}`);
182
182
  this.emit('devInfo', `----------------------------------`);
183
183
  return;
184
184
  }
package/src/lights.js CHANGED
@@ -18,10 +18,10 @@ class Lights extends EventEmitter {
18
18
  //info
19
19
  this.info = info;
20
20
  this.serialNumber = serialNumber;
21
+ this.relaysCount = info.friendlyNames.length;
21
22
 
22
23
  //other config
23
24
  this.lightsNamePrefix = config.lightsNamePrefix || false;
24
- this.sensorsNamePrefix = config.sensorsNamePrefix || false;
25
25
  this.enableDebugMode = config.enableDebugMode || false;
26
26
  this.disableLogInfo = config.disableLogInfo || false;
27
27
  this.disableLogDeviceInfo = config.disableLogDeviceInfo || false;
@@ -78,7 +78,7 @@ class Lights extends EventEmitter {
78
78
  const statusSts = statusStsSupported ? sensorStatus.StatusSTS : {};
79
79
 
80
80
  //relays
81
- const relaysCount = this.info.relaysCount;
81
+ const relaysCount = this.relaysCount;
82
82
  if (relaysCount > 0) {
83
83
  this.lights = [];
84
84
 
@@ -194,7 +194,7 @@ class Lights extends EventEmitter {
194
194
  this.emit('devInfo', `Hardware: ${this.info.modelName}`);
195
195
  this.emit('devInfo', `Serialnr: ${this.serialNumber}`)
196
196
  this.emit('devInfo', `Firmware: ${this.info.firmwareRevision}`);
197
- this.emit('devInfo', `Relays: ${this.info.relaysCount}`);
197
+ this.emit('devInfo', `Relays: ${this.relaysCount}`);
198
198
  this.emit('devInfo', `----------------------------------`);
199
199
  return;
200
200
  }
package/src/sensors.js CHANGED
@@ -86,19 +86,7 @@ class Sensors extends EventEmitter {
86
86
 
87
87
  //status SNS
88
88
  if (statusSnsSupported) {
89
- this.sensorsName = [];
90
- this.sensorsTemperature = [];
91
- this.sensorsReferenceTemperature = [];
92
- this.sensorsObjTemperature = [];
93
- this.sensorsAmbTemperature = [];
94
- this.sensorsDewPointTemperature = [];
95
- this.sensorsHumidity = [];
96
- this.sensorsPressure = [];
97
- this.sensorsGas = [];
98
- this.sensorsCarbonDioxyde = [];
99
- this.sensorsAmbientLight = [];
100
- this.sensorsMotion = [];
101
-
89
+ this.sensors = [];
102
90
  const sensor = Object.entries(statusSns)
103
91
  .filter(([key]) => SensorKeys.some(type => key.includes(type)))
104
92
  .reduce((obj, [key, value]) => {
@@ -107,133 +95,67 @@ class Sensors extends EventEmitter {
107
95
  }, {});
108
96
 
109
97
  for (const [key, value] of Object.entries(sensor)) {
110
- const sensorName = key ?? `Sensor`;
111
98
  const sensorData = value;
112
99
 
113
- //sensors
114
- const temperature = sensorData.Temperature ?? false;
115
- const referenceTemperature = sensorData.ReferenceTemperature ?? false;
116
- const objTemperature = sensorData.OBJTMP ?? false;
117
- const ambTemperature = sensorData.AMBTMP ?? false;
118
- const dewPointTemperature = sensorData.DewPoint ?? false;
119
- const humidity = sensorData.Humidity ?? false;
120
- const pressure = sensorData.Pressure ?? false;
121
- const gas = sensorData.Gas ?? false;
122
- const carbonDioxyde = sensorData.CarbonDioxyde ?? false;
123
- const ambientLight = sensorData.Ambient ?? false;
124
- const motion = sensorData === 'ON';
100
+ //sensor
101
+ const obj = {
102
+ name: key,
103
+ time: sensorStatus.Time,
104
+ tempUnit: sensorStatus.TempUnit === 'C' ? '°C' : 'F',
105
+ pressureUnit: sensorStatus.PressureUnit ?? 'hPa',
106
+
107
+ temperature: sensorData.Temperature,
108
+ referenceTemperature: sensorData.ReferenceTemperature,
109
+ objTemperature: sensorData.OBJTMP,
110
+ ambTemperature: sensorData.AMBTMP,
111
+ dewPointTemperature: sensorData.DewPoint,
112
+ humidity: sensorData.Humidity,
113
+ pressure: sensorData.Pressure,
114
+ gas: sensorData.Gas,
115
+ carbonDioxyde: sensorData.CarbonDioxyde,
116
+ ambientLight: sensorData.Ambient,
117
+ motion: sensorData.Motion === 'ON',
118
+ }
125
119
 
126
120
  //energy
127
- const energyTotalStartTime = sensorData.TotalStartTime ?? '';
128
- const energyTotal = sensorData.Total ?? 0;
129
- const energyPeriod = sensorData.Period ?? 0;
130
- const energyYesterday = sensorData.Yesterday ?? 0;
131
- const energyToday = sensorData.Today ?? 0;
132
- const power = sensorData.Power ?? 0;
133
- const apparentPower = sensorData.ApparentPower ?? 0;
134
- const reactivePower = sensorData.ReactivePower ?? 0;
135
- const factor = sensorData.Factor ?? 0;
136
- const voltage = sensorData.Voltage ?? 0;
137
- const current = sensorData.Current ?? 0;
138
- const load = sensorData.Load ?? 0;
121
+ const obj1 = {
122
+ energyTotalStartTime: sensorData.TotalStartTime,
123
+ energyTotal: sensorData.Total,
124
+ energyPeriod: sensorData.Period,
125
+ energyYesterday: sensorData.Yesterday,
126
+ energyToday: sensorData.Today,
127
+ power: sensorData.Power,
128
+ apparentPower: sensorData.ApparentPower,
129
+ reactivePower: sensorData.ReactivePower,
130
+ factor: sensorData.Factor,
131
+ voltage: sensorData.Voltage,
132
+ current: sensorData.Current,
133
+ load: sensorData.Load,
134
+ }
135
+ obj = key === 'ENERGY' ? { ...obj, ...obj1 } : obj;
136
+ this.emit('debug', `Sensors status: ${JSON.stringify(obj, null, 2)}`)
139
137
 
140
138
  //push to array
141
- this.sensorsName.push(sensorName);
142
- const push1 = temperature ? this.sensorsTemperature.push(temperature) : false;
143
- const push2 = referenceTemperature ? this.sensorsReferenceTemperature.push(referenceTemperature) : false;
144
- const push3 = objTemperature ? this.sensorsAmbTemperature.push(objTemperature) : false;
145
- const push4 = ambTemperature ? this.sensorsAmbTemperature.push(ambTemperature) : false;
146
- const push5 = dewPointTemperature ? this.sensorsDewPointTemperature.push(dewPointTemperature) : false;
147
- const push6 = humidity ? this.sensorsHumidity.push(humidity) : false;
148
- const push7 = pressure ? this.sensorsPressure.push(pressure) : false;
149
- const push8 = gas ? this.sensorsGas.push(gas) : false;
150
- const push9 = carbonDioxyde ? this.sensorsCarbonDioxyde.push(carbonDioxyde) : false;
151
- const push10 = ambientLight ? this.sensorsAmbientLight.push(ambientLight) : false;
152
- const push11 = motion ? this.sensorsMotion.push(motion) : false;
139
+ this.sensors.push(obj);
153
140
  }
154
-
155
- this.time = sensorStatus.Time ?? '';
156
- this.tempUnit = sensorStatus.TempUnit === 'C' ? '°C' : 'F';
157
- this.pressureUnit = sensorStatus.PressureUnit ?? 'hPa';
158
- this.sensorsTemperatureCount = this.sensorsTemperature.length;
159
- this.sensorsReferenceTemperatureCount = this.sensorsReferenceTemperature.length;
160
- this.sensorsObjTemperatureCount = this.sensorsObjTemperature.length;
161
- this.sensorsAmbTemperatureCount = this.sensorsAmbTemperature.length;
162
- this.sensorsDewPointTemperatureCount = this.sensorsDewPointTemperature.length;
163
- this.sensorsHumidityCount = this.sensorsHumidity.length;
164
- this.sensorsPressureCount = this.sensorsPressure.length;
165
- this.sensorsGasCount = this.sensorsGas.length;
166
- this.sensorsCarbonDioxydeCount = this.sensorsCarbonDioxyde.length;
167
- this.sensorsAmbientLightCount = this.sensorsAmbientLight.length;
168
- this.sensorsMotionCount = this.sensorsMotion.length;
169
- this.sensorsCount = this.sensorsName.length;
170
-
141
+ this.sensorsCount = this.sensors.length;
171
142
 
172
143
  //update characteristics
173
- if (this.sensorTemperatureServices) {
174
- for (let i = 0; i < this.sensorsTemperatureCount; i++) {
175
- const value = this.sensorsTemperature[i];
176
- this.sensorTemperatureServices[i].updateCharacteristic(Characteristic.CurrentTemperature, value);
177
- }
178
- }
179
-
180
- if (this.sensorReferenceTemperatureServices) {
181
- for (let i = 0; i < this.sensorsReferenceTemperatureCount; i++) {
182
- const value = this.sensorsReferenceTemperature[i];
183
- this.sensorReferenceTemperatureServices[i].updateCharacteristic(Characteristic.CurrentTemperature, value);
184
- }
185
- }
186
-
187
- if (this.sensorObjTemperatureServices) {
188
- for (let i = 0; i < this.sensorsObjTemperatureCount; i++) {
189
- const value = this.sensorsObjTemperature[i];
190
- this.sensorObjTemperatureServices[i].updateCharacteristic(Characteristic.CurrentTemperature, value);
191
- }
192
- }
193
-
194
- if (this.sensorAmbTemperatureServices) {
195
- for (let i = 0; i < this.sensorsAmbTemperatureCount; i++) {
196
- const value = this.sensorsAmbTemperature[i];
197
- this.sensorAmbTemperatureServices[i].updateCharacteristic(Characteristic.CurrentTemperature, value);
198
- }
199
- }
200
-
201
- if (this.sensorDewPointTemperatureServices) {
202
- for (let i = 0; i < this.sensorsDewPointTemperatureCount; i++) {
203
- const value = this.sensorsDewPointTemperature[i];
204
- this.sensorDewPointTemperatureServices[i].updateCharacteristic(Characteristic.CurrentTemperature, value);
205
- }
206
- }
207
-
208
- if (this.sensorHumidityServices) {
209
- for (let i = 0; i < this.sensorsHumidityCount; i++) {
210
- const value = this.sensorsHumidity[i];
211
- this.sensorHumidityServices[i].updateCharacteristic(Characteristic.CurrentRelativeHumidity, value);
212
- }
213
- }
214
-
215
- if (this.sensorCarbonDioxydeServices) {
216
- for (let i = 0; i < this.sensorsCarbonDioxydeCount; i++) {
217
- const state = this.sensorsCarbonDioxyde[i] > 1000;
218
- const value = this.sensorsCarbonDioxyde[i];
219
- this.sensorCarbonDioxydeServices[i]
220
- .updateCharacteristic(Characteristic.CarbonDioxideDetected, state)
221
- .updateCharacteristic(Characteristic.CarbonDioxideLevel, value)
222
- .updateCharacteristic(Characteristic.CarbonDioxidePeakLevel, value);
223
- }
224
- }
225
-
226
- if (this.sensorAmbientLightServices) {
227
- for (let i = 0; i < this.sensorsAmbientLightCount; i++) {
228
- const value = this.sensorsAmbientLight[i];
229
- this.sensorAmbientLightServices[i].updateCharacteristic(Characteristic.CurrentAmbientLightLevel, value);
230
- }
231
- }
232
-
233
- if (this.sensorMotionServices) {
234
- for (let i = 0; i < this.sensorsMotionCount; i++) {
235
- const state = this.sensorsMotion[i];
236
- this.sensorMotionServices[i].updateCharacteristic(Characteristic.MotionDetected, state);
144
+ if (this.sensorsCount > 0) {
145
+ for (let i = 0; i < this.sensorsCount; i++) {
146
+ const sensor = this.sensors[i];
147
+ this.sensorTemperatureServices?.[i]?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.temperature);
148
+ this.sensorReferenceTemperatureServices?.[i]?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.referenceTemperature);
149
+ this.sensorObjTemperatureServices?.[i]?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.objTemperature);
150
+ this.sensorAmbTemperatureServices?.[i]?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.ambTemperature);
151
+ this.sensorDewPointTemperatureServices?.[i]?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.dewPointTemperature);
152
+ this.sensorHumidityServices?.[i]?.updateCharacteristic(Characteristic.CurrentRelativeHumidity, sensor.humidity);
153
+ this.sensorCarbonDioxydeServices?.[i]
154
+ ?.updateCharacteristic(Characteristic.CarbonDioxideDetected, sensor.carbonDioxyde > 1000)
155
+ .updateCharacteristic(Characteristic.CarbonDioxideLevel, sensor.carbonDioxyde)
156
+ .updateCharacteristic(Characteristic.CarbonDioxidePeakLevel, sensor.carbonDioxyde);
157
+ this.sensorAmbientLightServices?.[i]?.updateCharacteristic(Characteristic.CurrentAmbientLightLevel, sensor.ambientLight);
158
+ this.sensorMotionServices?.[i]?.updateCharacteristic(Characteristic.MotionDetected, sensor.motion);
237
159
  }
238
160
  }
239
161
  }
@@ -311,208 +233,177 @@ class Sensors extends EventEmitter {
311
233
  const debug = this.enableDebugMode ? this.emit('debug', `Prepare Sensor Services`) : false;
312
234
 
313
235
  //temperature
314
- const sensorsTemperatureCount = this.sensorsTemperatureCount;
315
- if (sensorsTemperatureCount > 0) {
316
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Temperature Sensor Services`) : false;
317
- this.sensorTemperatureServices = [];
318
- for (let i = 0; i < sensorsTemperatureCount; i++) {
319
- const sensorName = this.sensorsName[i];
236
+ let i = 0;
237
+ for (const sensor of this.sensors) {
238
+ const sensorName = sensor.name;
239
+ if (sensor.temperature !== undefined) {
240
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Temperature Sensor Services`) : false;
241
+ this.sensorTemperatureServices = [];
320
242
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Temperature` : `${sensorName} Temperature`;
321
243
  const sensorTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Temperature Sensor ${i}`);
322
244
  sensorTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
323
245
  sensorTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
324
246
  sensorTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
325
247
  .onGet(async () => {
326
- const value = this.sensorsTemperature[i];
327
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} temperature: ${value} °${this.tempUnit}`);
248
+ const value = sensor.temperature;
249
+ const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} temperature: ${value} °${sensor.tempUnit}`);
328
250
  return value;
329
251
  });
330
252
  this.sensorTemperatureServices.push(sensorTemperatureService);
331
253
  }
332
- }
333
254
 
334
- //reference temperature
335
- const sensorsReferenceTemperatureCount = this.sensorsReferenceTemperatureCount;
336
- if (sensorsReferenceTemperatureCount > 0) {
337
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Reference Temperature Sensor Services`) : false;
338
- this.sensorReferenceTemperatureServices = [];
339
- for (let i = 0; i < sensorsReferenceTemperatureCount; i++) {
340
- const sensorName = this.sensorsName[i];
255
+ //reference temperature
256
+ if (sensor.referenceTemperature !== undefined) {
257
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Reference Temperature Sensor Services`) : false;
258
+ this.sensorReferenceTemperatureServices = [];
341
259
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Reference Temperature` : `${sensorName} Reference Temperature`;
342
260
  const sensorReferenceTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Reference Temperature Sensor ${i}`);
343
261
  sensorReferenceTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
344
262
  sensorReferenceTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
345
263
  sensorReferenceTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
346
264
  .onGet(async () => {
347
- const value = this.sensorsReferenceTemperature[i];
348
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} reference temperature: ${value} °${this.tempUnit}`);
265
+ const value = sensor.referenceTemperature;
266
+ const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} reference temperature: ${value} °${sensor.tempUnit}`);
349
267
  return value;
350
268
  });
351
269
  this.sensorReferenceTemperatureServices.push(sensorReferenceTemperatureService);
352
270
  }
353
- }
354
271
 
355
- //object temperature
356
- const sensorsObjTemperatureCount = this.sensorsObjTemperatureCount;
357
- if (sensorsObjTemperatureCount > 0) {
358
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Obj Temperature Sensor Services`) : false;
359
- this.sensorObjTemperatureServices = [];
360
- for (let i = 0; i < sensorsObjTemperatureCount; i++) {
361
- const sensorName = this.sensorsName[i];
272
+ //object temperature
273
+ if (sensor.objTemperature !== undefined) {
274
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Obj Temperature Sensor Services`) : false;
275
+ this.sensorObjTemperatureServices = [];
362
276
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Obj Temperature` : `${sensorName} Obj Temperature`;
363
277
  const sensorObjTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Obj Temperature Sensor ${i}`);
364
278
  sensorObjTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
365
279
  sensorObjTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
366
280
  sensorObjTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
367
281
  .onGet(async () => {
368
- const value = this.sensorsObjTemperature[i];
369
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} obj temperature: ${value} °${this.tempUnit}`);
282
+ const value = sensor.objTemperature;
283
+ const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} obj temperature: ${value} °${sensor.tempUnit}`);
370
284
  return value;
371
285
  });
372
286
  this.sensorObjTemperatureServices.push(sensorObjTemperatureService);
373
287
  }
374
- }
375
288
 
376
- //ambient temperature
377
- const sensorsAmbTemperatureCount = this.sensorsAmbTemperatureCount;
378
- if (sensorsAmbTemperatureCount > 0) {
379
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Amb Temperature Sensor Services`) : false;
380
- this.sensorAmbTemperatureServices = [];
381
- for (let i = 0; i < sensorsAmbTemperatureCount; i++) {
382
- const sensorName = this.sensorsName[i];
289
+ //ambient temperature
290
+ if (sensor.ambTemperature !== undefined) {
291
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Amb Temperature Sensor Services`) : false;
292
+ this.sensorAmbTemperatureServices = [];
383
293
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Amb Temperature` : `${sensorName} Amb Temperature`;
384
294
  const sensorAmbTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Amb Temperature Sensor ${i}`);
385
295
  sensorAmbTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
386
296
  sensorAmbTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
387
297
  sensorAmbTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
388
298
  .onGet(async () => {
389
- const value = this.sensorsAmbTemperature[i];
390
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} amb temperature: ${value} °${this.tempUnit}`);
299
+ const value = sensor.ambTemperature;
300
+ const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} amb temperature: ${value} °${sensor.tempUnit}`);
391
301
  return value;
392
302
  });
393
303
  this.sensorAmbTemperatureServices.push(sensorAmbTemperatureService);
394
304
  }
395
- }
396
305
 
397
- //dew point temperature
398
- const sensorsDewPointTemperatureCount = this.sensorsDewPointTemperatureCount;
399
- if (sensorsDewPointTemperatureCount > 0) {
400
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Dew Point Temperature Sensor Services`) : false;
401
- this.sensorDewPointTemperatureServices = [];
402
- for (let i = 0; i < sensorsDewPointTemperatureCount; i++) {
403
- const sensorName = this.sensorsName[i];
306
+ //dew point temperature
307
+ if (sensor.dewPointTemperature !== undefined) {
308
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Dew Point Temperature Sensor Services`) : false;
309
+ this.sensorDewPointTemperatureServices = [];
404
310
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Dew Point` : `${sensorName} Dew Point`;
405
311
  const sensorDewPointTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Dew Point Temperature Sensor ${i}`);
406
312
  sensorDewPointTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
407
313
  sensorDewPointTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
408
314
  sensorDewPointTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
409
315
  .onGet(async () => {
410
- const value = this.sensorsDewPointTemperature[i];
411
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} dew point: ${value} °${this.tempUnit}`);
316
+ const value = sensor.dewPointTemperature;
317
+ const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} dew point: ${value} °${sensor.tempUnit}`);
412
318
  return value;
413
319
  });
414
320
  this.sensorDewPointTemperatureServices.push(sensorDewPointTemperatureService);
415
321
  }
416
- }
417
322
 
418
- //humidity
419
- const sensorsHumidityCount = this.sensorsHumidityCount;
420
- if (sensorsHumidityCount > 0) {
421
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Humidity Sensor Services`) : false;
422
- this.sensorHumidityServices = [];
423
- for (let i = 0; i < sensorsHumidityCount; i++) {
424
- const sensorName = this.sensorsName[i];
323
+ //humidity
324
+ if (sensor.humidity !== undefined) {
325
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Humidity Sensor Services`) : false;
326
+ this.sensorHumidityServices = [];
425
327
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Humidity` : `${sensorName} Humidity`;
426
328
  const sensorHumidityService = accessory.addService(Service.HumiditySensor, serviceName, `Humidity Sensor ${i}`);
427
329
  sensorHumidityService.addOptionalCharacteristic(Characteristic.ConfiguredName);
428
330
  sensorHumidityService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
429
331
  sensorHumidityService.getCharacteristic(Characteristic.CurrentRelativeHumidity)
430
332
  .onGet(async () => {
431
- const value = this.sensorsHumidity[i];
333
+ const value = sensor.humidity;
432
334
  const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} humidity: ${value} %`);
433
335
  return value;
434
336
  });
435
337
  this.sensorHumidityServices.push(sensorHumidityService);
436
338
  }
437
- }
438
339
 
439
- //pressure
340
+ //pressure
440
341
 
441
- //gas
342
+ //gas
442
343
 
443
- //carbon dioxyde
444
- const sensorsCarbonDioxydeCount = this.sensorsCarbonDioxydeCount;
445
- if (sensorsCarbonDioxydeCount > 0) {
446
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Carbon Dioxyde Sensor Services`) : false;
447
- this.sensorCarbonDioxydeServices = [];
448
- for (let i = 0; i < sensorsCarbonDioxydeCount; i++) {
449
- const sensorName = this.sensorsName[i];
344
+ //carbon dioxyde
345
+ if (sensor.carbonDioxyde !== undefined) {
346
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Carbon Dioxyde Sensor Services`) : false;
347
+ this.sensorCarbonDioxydeServices = [];
450
348
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Carbon Dioxyde` : `${sensorName} Carbon Dioxyde`;
451
349
  const sensorCarbonDioxydeService = accessory.addService(Service.CarbonDioxideSensor, serviceName, `Carbon Dioxyde Sensor ${i}`);
452
350
  sensorCarbonDioxydeService.addOptionalCharacteristic(Characteristic.ConfiguredName);
453
351
  sensorCarbonDioxydeService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
454
352
  sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxideDetected)
455
353
  .onGet(async () => {
456
- const state = this.sensorsCarbonDioxyde[i] > 1000;
354
+ const state = sensor.carbonDioxyde > 1000;
457
355
  const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} carbon dioxyde detected: ${state ? 'Yes' : 'No'}`);
458
356
  return state;
459
357
  });
460
358
  sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxideLevel)
461
359
  .onGet(async () => {
462
- const value = this.sensorsCarbonDioxyde[i];
360
+ const value = sensor.carbonDioxyde;
463
361
  const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} carbon dioxyde level: ${value} ppm`);
464
362
  return value;
465
363
  });
466
364
  sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxidePeakLevel)
467
365
  .onGet(async () => {
468
- const value = this.sensorsCarbonDioxyde[i];
366
+ const value = sensor.carbonDioxyde;
469
367
  const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} carbon dioxyde peak level: ${value} ppm`);
470
368
  return value;
471
369
  });
472
370
  this.sensorCarbonDioxydeServices.push(sensorCarbonDioxydeService);
473
371
  }
474
- }
475
372
 
476
- //ambient light
477
- const sensorsAmbientLightCount = this.sensorsAmbientLightCount;
478
- if (sensorsAmbientLightCount > 0) {
479
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Ambient Light Sensor Services`) : false;
480
- this.sensorAmbientLightServices = [];
481
- for (let i = 0; i < sensorsAmbientLightCount; i++) {
482
- const sensorName = this.sensorsName[i];
373
+ //ambient light
374
+ if (sensor.ambientLight !== undefined) {
375
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Ambient Light Sensor Services`) : false;
376
+ this.sensorAmbientLightServices = [];
483
377
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Ambient Light` : `${sensorName} Ambient Light`;
484
378
  const sensorAmbientLightService = accessory.addService(Service.LightSensor, serviceName, `Ambient Light Sensor ${i}`);
485
379
  sensorAmbientLightService.addOptionalCharacteristic(Characteristic.ConfiguredName);
486
380
  sensorAmbientLightService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
487
381
  sensorAmbientLightService.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
488
382
  .onGet(async () => {
489
- const value = this.sensorsAmbientLight[i];
383
+ const value = sensor.ambientLight;
490
384
  const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} ambient light: ${value} lx`);
491
385
  return value;
492
386
  });
493
387
  this.sensorAmbientLightServices.push(sensorAmbientLightService);
494
388
  }
495
- }
496
389
 
497
- //motion
498
- const sensorsMotionCount = this.sensorsMotionCount;
499
- if (sensorsMotionCount > 0) {
500
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Motion Sensor Services`) : false;
501
- this.sensorMotionServices = [];
502
- for (let i = 0; i < sensorsMotionCount; i++) {
503
- const sensorName = this.sensorsName[i];
390
+ //motion
391
+ if (sensor.motion !== undefined) {
392
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Motion Sensor Services`) : false;
393
+ this.sensorMotionServices = [];
504
394
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Motion` : `${sensorName} Motion`;
505
395
  const sensorMotionService = accessory.addService(Service.MotionSensor, serviceName, `Motion Sensor ${i}`);
506
396
  sensorMotionService.addOptionalCharacteristic(Characteristic.ConfiguredName);
507
397
  sensorMotionService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
508
398
  sensorMotionService.getCharacteristic(Characteristic.MotionDetected)
509
399
  .onGet(async () => {
510
- const state = this.sensorsMotion[i];
400
+ const state = sensor.motion;
511
401
  const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} motion: ${state ? 'ON' : 'OFF'}`);
512
402
  return state;
513
403
  });
514
404
  this.sensorMotionServices.push(sensorMotionService);
515
405
  }
406
+ i++;
516
407
  }
517
408
  }
518
409
 
package/src/switches.js CHANGED
@@ -18,6 +18,7 @@ class Switches extends EventEmitter {
18
18
  //info
19
19
  this.info = info;
20
20
  this.serialNumber = serialNumber;
21
+ this.relaysCount = info.friendlyNames.length;
21
22
 
22
23
  //other config
23
24
  this.relaysDisplayType = config.relaysDisplayType || 0;
@@ -65,7 +66,7 @@ class Switches extends EventEmitter {
65
66
  const debug = this.enableDebugMode ? this.emit('debug', `Power status: ${JSON.stringify(powerStatus, null, 2)}`) : false;
66
67
 
67
68
  //relays
68
- const relaysCount = this.info.relaysCount;
69
+ const relaysCount = this.relaysCount;
69
70
  if (relaysCount > 0) {
70
71
  this.switchesOutlets = [];
71
72
 
@@ -137,7 +138,7 @@ class Switches extends EventEmitter {
137
138
  this.emit('devInfo', `Hardware: ${this.info.modelName}`);
138
139
  this.emit('devInfo', `Serialnr: ${this.serialNumber}`)
139
140
  this.emit('devInfo', `Firmware: ${this.info.firmwareRevision}`);
140
- this.emit('devInfo', `Relays: ${this.info.relaysCount}`);
141
+ this.emit('devInfo', `Relays: ${this.relaysCount}`);
141
142
  this.emit('devInfo', `----------------------------------`);
142
143
  return;
143
144
  }