homebridge-tasmota-control 1.4.1-beta.8 → 1.5.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/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.8",
4
+ "version": "1.5.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,61 @@ 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';
125
-
126
- //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;
100
+ //sensor
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
+ //energy
115
+ energyTotalStartTime: sensorData.TotalStartTime ?? '',
116
+ energyTotal: sensorData.Total ?? 0,
117
+ energyPeriod: sensorData.Period ?? 0,
118
+ energyYesterday: sensorData.Yesterday ?? 0,
119
+ energyToday: sensorData.Today ?? 0,
120
+ power: sensorData.Power ?? 0,
121
+ apparentPower: sensorData.ApparentPower ?? 0,
122
+ reactivePower: sensorData.ReactivePower ?? 0,
123
+ factor: sensorData.Factor ?? 0,
124
+ voltage: sensorData.Voltage ?? 0,
125
+ current: sensorData.Current ?? 0,
126
+ load: sensorData.Load ?? 0,
127
+ time: sensorStatus.Time ?? '',
128
+ tempUnit: sensorStatus.TempUnit === 'C' ? '°C' : 'F',
129
+ pressureUnit: sensorStatus.PressureUnit ?? 'hPa'
130
+ }
139
131
 
140
132
  //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;
133
+ this.sensors.push(obj);
153
134
  }
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
-
135
+ this.sensorsCount = this.sensors.length;
171
136
 
172
137
  //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);
138
+ if (this.sensorsCount > 0) {
139
+ for (let i = 0; i < this.sensorsCount; i++) {
140
+ const sensor = this.sensors[i];
141
+ this.sensorTemperatureServices?.[i]?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.temperature);
142
+ this.sensorReferenceTemperatureServices?.[i]?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.referenceTemperature);
143
+ this.sensorObjTemperatureServices?.[i]?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.objTemperature);
144
+ this.sensorAmbTemperatureServices?.[i]?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.ambTemperature);
145
+ this.sensorDewPointTemperatureServices?.[i]?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.dewPointTemperature);
146
+ this.sensorHumidityServices?.[i]?.updateCharacteristic(Characteristic.CurrentRelativeHumidity, sensor.humidity);
147
+ this.sensorCarbonDioxydeServices?.[i]
148
+ ?.updateCharacteristic(Characteristic.CarbonDioxideDetected, sensor.carbonDioxyde > 1000)
149
+ .updateCharacteristic(Characteristic.CarbonDioxideLevel, sensor.carbonDioxyde)
150
+ .updateCharacteristic(Characteristic.CarbonDioxidePeakLevel, sensor.carbonDioxyde);
151
+ this.sensorAmbientLightServices?.[i]?.updateCharacteristic(Characteristic.CurrentAmbientLightLevel, sensor.ambientLight);
152
+ this.sensorMotionServices?.[i]?.updateCharacteristic(Characteristic.MotionDetected, sensor.motion);
237
153
  }
238
154
  }
239
155
  }
@@ -311,208 +227,177 @@ class Sensors extends EventEmitter {
311
227
  const debug = this.enableDebugMode ? this.emit('debug', `Prepare Sensor Services`) : false;
312
228
 
313
229
  //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];
230
+ let i = 0;
231
+ for (const sensor of this.sensors) {
232
+ const sensorName = sensor.name;
233
+ if (sensor.temperature !== undefined) {
234
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Temperature Sensor Services`) : false;
235
+ this.sensorTemperatureServices = [];
320
236
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Temperature` : `${sensorName} Temperature`;
321
237
  const sensorTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Temperature Sensor ${i}`);
322
238
  sensorTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
323
239
  sensorTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
324
240
  sensorTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
325
241
  .onGet(async () => {
326
- const value = this.sensorsTemperature[i];
327
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} temperature: ${value} °${this.tempUnit}`);
242
+ const value = sensor.temperature;
243
+ const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} temperature: ${value} °${sensor.tempUnit}`);
328
244
  return value;
329
245
  });
330
246
  this.sensorTemperatureServices.push(sensorTemperatureService);
331
247
  }
332
- }
333
248
 
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];
249
+ //reference temperature
250
+ if (sensor.referenceTemperature !== undefined) {
251
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Reference Temperature Sensor Services`) : false;
252
+ this.sensorReferenceTemperatureServices = [];
341
253
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Reference Temperature` : `${sensorName} Reference Temperature`;
342
254
  const sensorReferenceTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Reference Temperature Sensor ${i}`);
343
255
  sensorReferenceTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
344
256
  sensorReferenceTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
345
257
  sensorReferenceTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
346
258
  .onGet(async () => {
347
- const value = this.sensorsReferenceTemperature[i];
348
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} reference temperature: ${value} °${this.tempUnit}`);
259
+ const value = sensor.referenceTemperature;
260
+ const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} reference temperature: ${value} °${sensor.tempUnit}`);
349
261
  return value;
350
262
  });
351
263
  this.sensorReferenceTemperatureServices.push(sensorReferenceTemperatureService);
352
264
  }
353
- }
354
265
 
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];
266
+ //object temperature
267
+ if (sensor.objTemperature !== undefined) {
268
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Obj Temperature Sensor Services`) : false;
269
+ this.sensorObjTemperatureServices = [];
362
270
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Obj Temperature` : `${sensorName} Obj Temperature`;
363
271
  const sensorObjTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Obj Temperature Sensor ${i}`);
364
272
  sensorObjTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
365
273
  sensorObjTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
366
274
  sensorObjTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
367
275
  .onGet(async () => {
368
- const value = this.sensorsObjTemperature[i];
369
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} obj temperature: ${value} °${this.tempUnit}`);
276
+ const value = sensor.objTemperature;
277
+ const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} obj temperature: ${value} °${sensor.tempUnit}`);
370
278
  return value;
371
279
  });
372
280
  this.sensorObjTemperatureServices.push(sensorObjTemperatureService);
373
281
  }
374
- }
375
282
 
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];
283
+ //ambient temperature
284
+ if (sensor.ambTemperature !== undefined) {
285
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Amb Temperature Sensor Services`) : false;
286
+ this.sensorAmbTemperatureServices = [];
383
287
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Amb Temperature` : `${sensorName} Amb Temperature`;
384
288
  const sensorAmbTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Amb Temperature Sensor ${i}`);
385
289
  sensorAmbTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
386
290
  sensorAmbTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
387
291
  sensorAmbTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
388
292
  .onGet(async () => {
389
- const value = this.sensorsAmbTemperature[i];
390
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} amb temperature: ${value} °${this.tempUnit}`);
293
+ const value = sensor.ambTemperature;
294
+ const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} amb temperature: ${value} °${sensor.tempUnit}`);
391
295
  return value;
392
296
  });
393
297
  this.sensorAmbTemperatureServices.push(sensorAmbTemperatureService);
394
298
  }
395
- }
396
299
 
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];
300
+ //dew point temperature
301
+ if (sensor.dewPointTemperature !== undefined) {
302
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Dew Point Temperature Sensor Services`) : false;
303
+ this.sensorDewPointTemperatureServices = [];
404
304
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Dew Point` : `${sensorName} Dew Point`;
405
305
  const sensorDewPointTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Dew Point Temperature Sensor ${i}`);
406
306
  sensorDewPointTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
407
307
  sensorDewPointTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
408
308
  sensorDewPointTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
409
309
  .onGet(async () => {
410
- const value = this.sensorsDewPointTemperature[i];
411
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} dew point: ${value} °${this.tempUnit}`);
310
+ const value = sensor.dewPointTemperature;
311
+ const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} dew point: ${value} °${sensor.tempUnit}`);
412
312
  return value;
413
313
  });
414
314
  this.sensorDewPointTemperatureServices.push(sensorDewPointTemperatureService);
415
315
  }
416
- }
417
316
 
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];
317
+ //humidity
318
+ if (sensor.humidity !== undefined) {
319
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Humidity Sensor Services`) : false;
320
+ this.sensorHumidityServices = [];
425
321
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Humidity` : `${sensorName} Humidity`;
426
322
  const sensorHumidityService = accessory.addService(Service.HumiditySensor, serviceName, `Humidity Sensor ${i}`);
427
323
  sensorHumidityService.addOptionalCharacteristic(Characteristic.ConfiguredName);
428
324
  sensorHumidityService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
429
325
  sensorHumidityService.getCharacteristic(Characteristic.CurrentRelativeHumidity)
430
326
  .onGet(async () => {
431
- const value = this.sensorsHumidity[i];
327
+ const value = sensor.humidity;
432
328
  const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} humidity: ${value} %`);
433
329
  return value;
434
330
  });
435
331
  this.sensorHumidityServices.push(sensorHumidityService);
436
332
  }
437
- }
438
333
 
439
- //pressure
334
+ //pressure
440
335
 
441
- //gas
336
+ //gas
442
337
 
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];
338
+ //carbon dioxyde
339
+ if (sensor.carbonDioxyde !== undefined) {
340
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Carbon Dioxyde Sensor Services`) : false;
341
+ this.sensorCarbonDioxydeServices = [];
450
342
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Carbon Dioxyde` : `${sensorName} Carbon Dioxyde`;
451
343
  const sensorCarbonDioxydeService = accessory.addService(Service.CarbonDioxideSensor, serviceName, `Carbon Dioxyde Sensor ${i}`);
452
344
  sensorCarbonDioxydeService.addOptionalCharacteristic(Characteristic.ConfiguredName);
453
345
  sensorCarbonDioxydeService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
454
346
  sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxideDetected)
455
347
  .onGet(async () => {
456
- const state = this.sensorsCarbonDioxyde[i] > 1000;
348
+ const state = sensor.carbonDioxyde > 1000;
457
349
  const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} carbon dioxyde detected: ${state ? 'Yes' : 'No'}`);
458
350
  return state;
459
351
  });
460
352
  sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxideLevel)
461
353
  .onGet(async () => {
462
- const value = this.sensorsCarbonDioxyde[i];
354
+ const value = sensor.carbonDioxyde;
463
355
  const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} carbon dioxyde level: ${value} ppm`);
464
356
  return value;
465
357
  });
466
358
  sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxidePeakLevel)
467
359
  .onGet(async () => {
468
- const value = this.sensorsCarbonDioxyde[i];
360
+ const value = sensor.carbonDioxyde;
469
361
  const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} carbon dioxyde peak level: ${value} ppm`);
470
362
  return value;
471
363
  });
472
364
  this.sensorCarbonDioxydeServices.push(sensorCarbonDioxydeService);
473
365
  }
474
- }
475
366
 
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];
367
+ //ambient light
368
+ if (sensor.ambientLight !== undefined) {
369
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Ambient Light Sensor Services`) : false;
370
+ this.sensorAmbientLightServices = [];
483
371
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Ambient Light` : `${sensorName} Ambient Light`;
484
372
  const sensorAmbientLightService = accessory.addService(Service.LightSensor, serviceName, `Ambient Light Sensor ${i}`);
485
373
  sensorAmbientLightService.addOptionalCharacteristic(Characteristic.ConfiguredName);
486
374
  sensorAmbientLightService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
487
375
  sensorAmbientLightService.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
488
376
  .onGet(async () => {
489
- const value = this.sensorsAmbientLight[i];
377
+ const value = sensor.ambientLight;
490
378
  const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} ambient light: ${value} lx`);
491
379
  return value;
492
380
  });
493
381
  this.sensorAmbientLightServices.push(sensorAmbientLightService);
494
382
  }
495
- }
496
383
 
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];
384
+ //motion
385
+ if (sensor.motion !== undefined) {
386
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Motion Sensor Services`) : false;
387
+ this.sensorMotionServices = [];
504
388
  const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Motion` : `${sensorName} Motion`;
505
389
  const sensorMotionService = accessory.addService(Service.MotionSensor, serviceName, `Motion Sensor ${i}`);
506
390
  sensorMotionService.addOptionalCharacteristic(Characteristic.ConfiguredName);
507
391
  sensorMotionService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
508
392
  sensorMotionService.getCharacteristic(Characteristic.MotionDetected)
509
393
  .onGet(async () => {
510
- const state = this.sensorsMotion[i];
394
+ const state = sensor.motion;
511
395
  const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} motion: ${state ? 'ON' : 'OFF'}`);
512
396
  return state;
513
397
  });
514
398
  this.sensorMotionServices.push(sensorMotionService);
515
399
  }
400
+ i++;
516
401
  }
517
402
  }
518
403
 
package/src/switches.js CHANGED
@@ -2,7 +2,7 @@ import { promises as fsPromises } from 'fs';
2
2
  import axios from 'axios';
3
3
  import EventEmitter from 'events';
4
4
  import ImpulseGenerator from './impulsegenerator.js';
5
- import { ApiCommands, SensorKeys } from './constants.js';
5
+ import { ApiCommands } from './constants.js';
6
6
  let Accessory, Characteristic, Service, Categories, AccessoryUUID;
7
7
 
8
8
  class Switches extends EventEmitter {
@@ -18,11 +18,11 @@ 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;
24
25
  this.relaysNamePrefix = config.relaysNamePrefix || false;
25
- this.sensorsNamePrefix = config.sensorsNamePrefix || false;
26
26
  this.enableDebugMode = config.enableDebugMode || false;
27
27
  this.disableLogInfo = config.disableLogInfo || false;
28
28
  this.disableLogDeviceInfo = config.disableLogDeviceInfo || false;
@@ -65,20 +65,8 @@ class Switches extends EventEmitter {
65
65
  const powerStatus = powerStatusData.data ?? {};
66
66
  const debug = this.enableDebugMode ? this.emit('debug', `Power status: ${JSON.stringify(powerStatus, null, 2)}`) : false;
67
67
 
68
- //sensor status
69
- const sensorStatusData = await this.axiosInstance(ApiCommands.Status);
70
- const sensorStatus = sensorStatusData.data ?? {};
71
- const debug1 = this.enableDebugMode ? this.emit('debug', `Sensors status: ${JSON.stringify(sensorStatus, null, 2)}`) : false;
72
-
73
- //sensor status keys
74
- const sensorStatusKeys = Object.keys(sensorStatus);
75
-
76
- //status SNS
77
- const statusSnsSupported = sensorStatusKeys.includes('StatusSNS');
78
- const statusSns = statusSnsSupported ? sensorStatus.StatusSNS : {};
79
-
80
68
  //relays
81
- const relaysCount = this.info.relaysCount;
69
+ const relaysCount = this.relaysCount;
82
70
  if (relaysCount > 0) {
83
71
  this.switchesOutlets = [];
84
72
 
@@ -107,160 +95,6 @@ class Switches extends EventEmitter {
107
95
  }
108
96
  }
109
97
 
110
- //status SNS
111
- if (statusSnsSupported) {
112
- this.sensorsName = [];
113
- this.sensorsTemperature = [];
114
- this.sensorsReferenceTemperature = [];
115
- this.sensorsObjTemperature = [];
116
- this.sensorsAmbTemperature = [];
117
- this.sensorsDewPointTemperature = [];
118
- this.sensorsHumidity = [];
119
- this.sensorsPressure = [];
120
- this.sensorsGas = [];
121
- this.sensorsCarbonDioxyde = [];
122
- this.sensorsAmbientLight = [];
123
- this.sensorsMotion = [];
124
-
125
- const sensor = Object.entries(statusSns)
126
- .filter(([key]) => SensorKeys.some(type => key.includes(type)))
127
- .reduce((obj, [key, value]) => {
128
- obj[key] = value;
129
- return obj;
130
- }, {});
131
-
132
- for (const [key, value] of Object.entries(sensor)) {
133
- const sensorName = key ?? `Sensor`;
134
- const sensorData = value;
135
-
136
- //sensors
137
- const temperature = sensorData.Temperature ?? false;
138
- const referenceTemperature = sensorData.ReferenceTemperature ?? false;
139
- const objTemperature = sensorData.OBJTMP ?? false;
140
- const ambTemperature = sensorData.AMBTMP ?? false;
141
- const dewPointTemperature = sensorData.DewPoint ?? false;
142
- const humidity = sensorData.Humidity ?? false;
143
- const pressure = sensorData.Pressure ?? false;
144
- const gas = sensorData.Gas ?? false;
145
- const carbonDioxyde = sensorData.CarbonDioxyde ?? false;
146
- const ambientLight = sensorData.Ambient ?? false;
147
- const motion = sensorData === 'ON';
148
-
149
- //energy
150
- const energyTotalStartTime = sensorData.TotalStartTime ?? '';
151
- const energyTotal = sensorData.Total ?? 0;
152
- const energyPeriod = sensorData.Period ?? 0;
153
- const energyYesterday = sensorData.Yesterday ?? 0;
154
- const energyToday = sensorData.Today ?? 0;
155
- const power = sensorData.Power ?? 0;
156
- const apparentPower = sensorData.ApparentPower ?? 0;
157
- const reactivePower = sensorData.ReactivePower ?? 0;
158
- const factor = sensorData.Factor ?? 0;
159
- const voltage = sensorData.Voltage ?? 0;
160
- const current = sensorData.Current ?? 0;
161
- const load = sensorData.Load ?? 0;
162
-
163
- //push to array
164
- this.sensorsName.push(sensorName);
165
- const push1 = temperature ? this.sensorsTemperature.push(temperature) : false;
166
- const push2 = referenceTemperature ? this.sensorsReferenceTemperature.push(referenceTemperature) : false;
167
- const push3 = objTemperature ? this.sensorsAmbTemperature.push(objTemperature) : false;
168
- const push4 = ambTemperature ? this.sensorsAmbTemperature.push(ambTemperature) : false;
169
- const push5 = dewPointTemperature ? this.sensorsDewPointTemperature.push(dewPointTemperature) : false;
170
- const push6 = humidity ? this.sensorsHumidity.push(humidity) : false;
171
- const push7 = pressure ? this.sensorsPressure.push(pressure) : false;
172
- const push8 = gas ? this.sensorsGas.push(gas) : false;
173
- const push9 = carbonDioxyde ? this.sensorsCarbonDioxyde.push(carbonDioxyde) : false;
174
- const push10 = ambientLight ? this.sensorsAmbientLight.push(ambientLight) : false;
175
- const push11 = motion ? this.sensorsMotion.push(motion) : false;
176
- }
177
-
178
- this.time = sensorStatus.Time ?? '';
179
- this.tempUnit = sensorStatus.TempUnit === 'C' ? '°C' : 'F';
180
- this.pressureUnit = sensorStatus.PressureUnit ?? 'hPa';
181
- this.sensorsTemperatureCount = this.sensorsTemperature.length;
182
- this.sensorsReferenceTemperatureCount = this.sensorsReferenceTemperature.length;
183
- this.sensorsObjTemperatureCount = this.sensorsObjTemperature.length;
184
- this.sensorsAmbTemperatureCount = this.sensorsAmbTemperature.length;
185
- this.sensorsDewPointTemperatureCount = this.sensorsDewPointTemperature.length;
186
- this.sensorsHumidityCount = this.sensorsHumidity.length;
187
- this.sensorsPressureCount = this.sensorsPressure.length;
188
- this.sensorsGasCount = this.sensorsGas.length;
189
- this.sensorsCarbonDioxydeCount = this.sensorsCarbonDioxyde.length;
190
- this.sensorsAmbientLightCount = this.sensorsAmbientLight.length;
191
- this.sensorsMotionCount = this.sensorsMotion.length;
192
- this.sensorsCount = this.sensorsName.length;
193
-
194
-
195
- //update characteristics
196
- if (this.sensorTemperatureServices) {
197
- for (let i = 0; i < this.sensorsTemperatureCount; i++) {
198
- const value = this.sensorsTemperature[i];
199
- this.sensorTemperatureServices[i].updateCharacteristic(Characteristic.CurrentTemperature, value);
200
- }
201
- }
202
-
203
- if (this.sensorReferenceTemperatureServices) {
204
- for (let i = 0; i < this.sensorsReferenceTemperatureCount; i++) {
205
- const value = this.sensorsReferenceTemperature[i];
206
- this.sensorReferenceTemperatureServices[i].updateCharacteristic(Characteristic.CurrentTemperature, value);
207
- }
208
- }
209
-
210
- if (this.sensorObjTemperatureServices) {
211
- for (let i = 0; i < this.sensorsObjTemperatureCount; i++) {
212
- const value = this.sensorsObjTemperature[i];
213
- this.sensorObjTemperatureServices[i].updateCharacteristic(Characteristic.CurrentTemperature, value);
214
- }
215
- }
216
-
217
- if (this.sensorAmbTemperatureServices) {
218
- for (let i = 0; i < this.sensorsAmbTemperatureCount; i++) {
219
- const value = this.sensorsAmbTemperature[i];
220
- this.sensorAmbTemperatureServices[i].updateCharacteristic(Characteristic.CurrentTemperature, value);
221
- }
222
- }
223
-
224
- if (this.sensorDewPointTemperatureServices) {
225
- for (let i = 0; i < this.sensorsDewPointTemperatureCount; i++) {
226
- const value = this.sensorsDewPointTemperature[i];
227
- this.sensorDewPointTemperatureServices[i].updateCharacteristic(Characteristic.CurrentTemperature, value);
228
- }
229
- }
230
-
231
- if (this.sensorHumidityServices) {
232
- for (let i = 0; i < this.sensorsHumidityCount; i++) {
233
- const value = this.sensorsHumidity[i];
234
- this.sensorHumidityServices[i].updateCharacteristic(Characteristic.CurrentRelativeHumidity, value);
235
- }
236
- }
237
-
238
- if (this.sensorCarbonDioxydeServices) {
239
- for (let i = 0; i < this.sensorsCarbonDioxydeCount; i++) {
240
- const state = this.sensorsCarbonDioxyde[i] > 1000;
241
- const value = this.sensorsCarbonDioxyde[i];
242
- this.sensorCarbonDioxydeServices[i]
243
- .updateCharacteristic(Characteristic.CarbonDioxideDetected, state)
244
- .updateCharacteristic(Characteristic.CarbonDioxideLevel, value)
245
- .updateCharacteristic(Characteristic.CarbonDioxidePeakLevel, value);
246
- }
247
- }
248
-
249
- if (this.sensorAmbientLightServices) {
250
- for (let i = 0; i < this.sensorsAmbientLightCount; i++) {
251
- const value = this.sensorsAmbientLight[i];
252
- this.sensorAmbientLightServices[i].updateCharacteristic(Characteristic.CurrentAmbientLightLevel, value);
253
- }
254
- }
255
-
256
- if (this.sensorMotionServices) {
257
- for (let i = 0; i < this.sensorsMotionCount; i++) {
258
- const state = this.sensorsMotion[i];
259
- this.sensorMotionServices[i].updateCharacteristic(Characteristic.MotionDetected, state);
260
- }
261
- }
262
- }
263
-
264
98
  return true;
265
99
  } catch (error) {
266
100
  throw new Error(`Check state error: ${error}`);
@@ -304,7 +138,7 @@ class Switches extends EventEmitter {
304
138
  this.emit('devInfo', `Hardware: ${this.info.modelName}`);
305
139
  this.emit('devInfo', `Serialnr: ${this.serialNumber}`)
306
140
  this.emit('devInfo', `Firmware: ${this.info.firmwareRevision}`);
307
- this.emit('devInfo', `Relays: ${this.info.relaysCount}`);
141
+ this.emit('devInfo', `Relays: ${this.relaysCount}`);
308
142
  this.emit('devInfo', `----------------------------------`);
309
143
  return;
310
144
  }
@@ -365,216 +199,6 @@ class Switches extends EventEmitter {
365
199
  }
366
200
  };
367
201
 
368
- //Prepare services
369
- if (this.sensorsCount > 0) {
370
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Sensor Services`) : false;
371
-
372
- //temperature
373
- const sensorsTemperatureCount = this.sensorsTemperatureCount;
374
- if (sensorsTemperatureCount > 0) {
375
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Temperature Sensor Services`) : false;
376
- this.sensorTemperatureServices = [];
377
- for (let i = 0; i < sensorsTemperatureCount; i++) {
378
- const sensorName = this.sensorsName[i];
379
- const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Temperature` : `${sensorName} Temperature`;
380
- const sensorTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Temperature Sensor ${i}`);
381
- sensorTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
382
- sensorTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
383
- sensorTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
384
- .onGet(async () => {
385
- const value = this.sensorsTemperature[i];
386
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} temperature: ${value} °${this.tempUnit}`);
387
- return value;
388
- });
389
- this.sensorTemperatureServices.push(sensorTemperatureService);
390
- }
391
- }
392
-
393
- //reference temperature
394
- const sensorsReferenceTemperatureCount = this.sensorsReferenceTemperatureCount;
395
- if (sensorsReferenceTemperatureCount > 0) {
396
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Reference Temperature Sensor Services`) : false;
397
- this.sensorReferenceTemperatureServices = [];
398
- for (let i = 0; i < sensorsReferenceTemperatureCount; i++) {
399
- const sensorName = this.sensorsName[i];
400
- const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Reference Temperature` : `${sensorName} Reference Temperature`;
401
- const sensorReferenceTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Reference Temperature Sensor ${i}`);
402
- sensorReferenceTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
403
- sensorReferenceTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
404
- sensorReferenceTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
405
- .onGet(async () => {
406
- const value = this.sensorsReferenceTemperature[i];
407
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} reference temperature: ${value} °${this.tempUnit}`);
408
- return value;
409
- });
410
- this.sensorReferenceTemperatureServices.push(sensorReferenceTemperatureService);
411
- }
412
- }
413
-
414
- //object temperature
415
- const sensorsObjTemperatureCount = this.sensorsObjTemperatureCount;
416
- if (sensorsObjTemperatureCount > 0) {
417
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Obj Temperature Sensor Services`) : false;
418
- this.sensorObjTemperatureServices = [];
419
- for (let i = 0; i < sensorsObjTemperatureCount; i++) {
420
- const sensorName = this.sensorsName[i];
421
- const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Obj Temperature` : `${sensorName} Obj Temperature`;
422
- const sensorObjTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Obj Temperature Sensor ${i}`);
423
- sensorObjTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
424
- sensorObjTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
425
- sensorObjTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
426
- .onGet(async () => {
427
- const value = this.sensorsObjTemperature[i];
428
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} obj temperature: ${value} °${this.tempUnit}`);
429
- return value;
430
- });
431
- this.sensorObjTemperatureServices.push(sensorObjTemperatureService);
432
- }
433
- }
434
-
435
- //ambient temperature
436
- const sensorsAmbTemperatureCount = this.sensorsAmbTemperatureCount;
437
- if (sensorsAmbTemperatureCount > 0) {
438
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Amb Temperature Sensor Services`) : false;
439
- this.sensorAmbTemperatureServices = [];
440
- for (let i = 0; i < sensorsAmbTemperatureCount; i++) {
441
- const sensorName = this.sensorsName[i];
442
- const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Amb Temperature` : `${sensorName} Amb Temperature`;
443
- const sensorAmbTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Amb Temperature Sensor ${i}`);
444
- sensorAmbTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
445
- sensorAmbTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
446
- sensorAmbTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
447
- .onGet(async () => {
448
- const value = this.sensorsAmbTemperature[i];
449
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} amb temperature: ${value} °${this.tempUnit}`);
450
- return value;
451
- });
452
- this.sensorAmbTemperatureServices.push(sensorAmbTemperatureService);
453
- }
454
- }
455
-
456
- //dew point temperature
457
- const sensorsDewPointTemperatureCount = this.sensorsDewPointTemperatureCount;
458
- if (sensorsDewPointTemperatureCount > 0) {
459
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Dew Point Temperature Sensor Services`) : false;
460
- this.sensorDewPointTemperatureServices = [];
461
- for (let i = 0; i < sensorsDewPointTemperatureCount; i++) {
462
- const sensorName = this.sensorsName[i];
463
- const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Dew Point` : `${sensorName} Dew Point`;
464
- const sensorDewPointTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Dew Point Temperature Sensor ${i}`);
465
- sensorDewPointTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
466
- sensorDewPointTemperatureService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
467
- sensorDewPointTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
468
- .onGet(async () => {
469
- const value = this.sensorsDewPointTemperature[i];
470
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} dew point: ${value} °${this.tempUnit}`);
471
- return value;
472
- });
473
- this.sensorDewPointTemperatureServices.push(sensorDewPointTemperatureService);
474
- }
475
- }
476
-
477
- //humidity
478
- const sensorsHumidityCount = this.sensorsHumidityCount;
479
- if (sensorsHumidityCount > 0) {
480
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Humidity Sensor Services`) : false;
481
- this.sensorHumidityServices = [];
482
- for (let i = 0; i < sensorsHumidityCount; i++) {
483
- const sensorName = this.sensorsName[i];
484
- const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Humidity` : `${sensorName} Humidity`;
485
- const sensorHumidityService = accessory.addService(Service.HumiditySensor, serviceName, `Humidity Sensor ${i}`);
486
- sensorHumidityService.addOptionalCharacteristic(Characteristic.ConfiguredName);
487
- sensorHumidityService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
488
- sensorHumidityService.getCharacteristic(Characteristic.CurrentRelativeHumidity)
489
- .onGet(async () => {
490
- const value = this.sensorsHumidity[i];
491
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} humidity: ${value} %`);
492
- return value;
493
- });
494
- this.sensorHumidityServices.push(sensorHumidityService);
495
- }
496
- }
497
-
498
- //pressure
499
-
500
- //gas
501
-
502
- //carbon dioxyde
503
- const sensorsCarbonDioxydeCount = this.sensorsCarbonDioxydeCount;
504
- if (sensorsCarbonDioxydeCount > 0) {
505
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Carbon Dioxyde Sensor Services`) : false;
506
- this.sensorCarbonDioxydeServices = [];
507
- for (let i = 0; i < sensorsCarbonDioxydeCount; i++) {
508
- const sensorName = this.sensorsName[i];
509
- const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Carbon Dioxyde` : `${sensorName} Carbon Dioxyde`;
510
- const sensorCarbonDioxydeService = accessory.addService(Service.CarbonDioxideSensor, serviceName, `Carbon Dioxyde Sensor ${i}`);
511
- sensorCarbonDioxydeService.addOptionalCharacteristic(Characteristic.ConfiguredName);
512
- sensorCarbonDioxydeService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
513
- sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxideDetected)
514
- .onGet(async () => {
515
- const state = this.sensorsCarbonDioxyde[i] > 1000;
516
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} carbon dioxyde detected: ${state ? 'Yes' : 'No'}`);
517
- return state;
518
- });
519
- sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxideLevel)
520
- .onGet(async () => {
521
- const value = this.sensorsCarbonDioxyde[i];
522
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} carbon dioxyde level: ${value} ppm`);
523
- return value;
524
- });
525
- sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxidePeakLevel)
526
- .onGet(async () => {
527
- const value = this.sensorsCarbonDioxyde[i];
528
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} carbon dioxyde peak level: ${value} ppm`);
529
- return value;
530
- });
531
- this.sensorCarbonDioxydeServices.push(sensorCarbonDioxydeService);
532
- }
533
- }
534
-
535
- //ambient light
536
- const sensorsAmbientLightCount = this.sensorsAmbientLightCount;
537
- if (sensorsAmbientLightCount > 0) {
538
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Ambient Light Sensor Services`) : false;
539
- this.sensorAmbientLightServices = [];
540
- for (let i = 0; i < sensorsAmbientLightCount; i++) {
541
- const sensorName = this.sensorsName[i];
542
- const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Ambient Light` : `${sensorName} Ambient Light`;
543
- const sensorAmbientLightService = accessory.addService(Service.LightSensor, serviceName, `Ambient Light Sensor ${i}`);
544
- sensorAmbientLightService.addOptionalCharacteristic(Characteristic.ConfiguredName);
545
- sensorAmbientLightService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
546
- sensorAmbientLightService.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
547
- .onGet(async () => {
548
- const value = this.sensorsAmbientLight[i];
549
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} ambient light: ${value} lx`);
550
- return value;
551
- });
552
- this.sensorAmbientLightServices.push(sensorAmbientLightService);
553
- }
554
- }
555
-
556
- //motion
557
- const sensorsMotionCount = this.sensorsMotionCount;
558
- if (sensorsMotionCount > 0) {
559
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Motion Sensor Services`) : false;
560
- this.sensorMotionServices = [];
561
- for (let i = 0; i < sensorsMotionCount; i++) {
562
- const sensorName = this.sensorsName[i];
563
- const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Motion` : `${sensorName} Motion`;
564
- const sensorMotionService = accessory.addService(Service.MotionSensor, serviceName, `Motion Sensor ${i}`);
565
- sensorMotionService.addOptionalCharacteristic(Characteristic.ConfiguredName);
566
- sensorMotionService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
567
- sensorMotionService.getCharacteristic(Characteristic.MotionDetected)
568
- .onGet(async () => {
569
- const state = this.sensorsMotion[i];
570
- const logInfo = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} motion: ${state ? 'ON' : 'OFF'}`);
571
- return state;
572
- });
573
- this.sensorMotionServices.push(sensorMotionService);
574
- }
575
- }
576
- }
577
-
578
202
  return accessory;
579
203
  } catch (error) {
580
204
  throw new Error(`Prepare accessory error: ${error}`)