homebridge-tasmota-control 1.5.1-beta.8 → 1.6.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 +8 -0
- package/README.md +6 -0
- package/index.js +5 -3
- package/package.json +1 -1
- package/src/customcharacteristics.js +198 -0
- package/src/deviceinfo.js +1 -5
- package/src/mielhvac.js +1 -1
- package/src/sensors.js +187 -48
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.6.0] - (01.06.2025)
|
|
9
|
+
|
|
10
|
+
## Changes
|
|
11
|
+
|
|
12
|
+
- added support for Energy Sensors with custom characteristics in EVE ir Controler aopp.
|
|
13
|
+
- redme updated
|
|
14
|
+
- cleanup
|
|
15
|
+
|
|
8
16
|
## [1.5.0] - (31.05.2025)
|
|
9
17
|
|
|
10
18
|
## Changes
|
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import Fans from './src/fans.js';
|
|
|
8
8
|
import Sensors from './src/sensors.js';
|
|
9
9
|
import ImpulseGenerator from './src/impulsegenerator.js';
|
|
10
10
|
import { PluginName, PlatformName } from './src/constants.js';
|
|
11
|
+
import CustomCharacteristics from './src/customcharacteristics.js';
|
|
11
12
|
|
|
12
13
|
class tasmotaPlatform {
|
|
13
14
|
constructor(log, config, api) {
|
|
@@ -56,7 +57,7 @@ class tasmotaPlatform {
|
|
|
56
57
|
const disableLogSuccess = device.disableLogSuccess || false;
|
|
57
58
|
const disableLogWarn = device.disableLogWarn || false;
|
|
58
59
|
const disableLogError = device.disableLogError || false;
|
|
59
|
-
const debug = enableDebugMode ? log.info(`Device: ${host} ${deviceName}, debug: Did finish launching.`)
|
|
60
|
+
const debug = !enableDebugMode ? false : log.info(`Device: ${host} ${deviceName}, debug: Did finish launching.`);
|
|
60
61
|
const newConfig = {
|
|
61
62
|
...device,
|
|
62
63
|
user: 'removed',
|
|
@@ -71,7 +72,7 @@ class tasmotaPlatform {
|
|
|
71
72
|
const emitLog = !enableDebugMode ? false : log.info(`Device: ${host} ${deviceName}, debug: ${debug}.`);
|
|
72
73
|
})
|
|
73
74
|
.on('debug', (debug) => {
|
|
74
|
-
const emitLog = enableDebugMode ? false : log.info(`Device: ${host} ${deviceName}, debug: ${debug}.`);
|
|
75
|
+
const emitLog = !enableDebugMode ? false : log.info(`Device: ${host} ${deviceName}, debug: ${debug}.`);
|
|
75
76
|
})
|
|
76
77
|
.on('warn', (warn) => {
|
|
77
78
|
const emitLog = disableLogWarn ? false : log.warn(`Device: ${host} ${deviceName}, ${warn}.`);
|
|
@@ -147,7 +148,7 @@ class tasmotaPlatform {
|
|
|
147
148
|
const emitLog = disableLogInfo ? false : log.info(`Device: ${host} ${deviceName}, ${info}.`);
|
|
148
149
|
})
|
|
149
150
|
.on('debug', (debug) => {
|
|
150
|
-
const emitLog = enableDebugMode ? false : log.info(`Device: ${host} ${deviceName}, debug: ${debug}.`);
|
|
151
|
+
const emitLog = !enableDebugMode ? false : log.info(`Device: ${host} ${deviceName}, debug: ${debug}.`);
|
|
151
152
|
})
|
|
152
153
|
.on('warn', (warn) => {
|
|
153
154
|
const emitLog = disableLogWarn ? false : log.warn(`Device: ${host} ${deviceName}, ${warn}.`);
|
|
@@ -189,5 +190,6 @@ class tasmotaPlatform {
|
|
|
189
190
|
}
|
|
190
191
|
|
|
191
192
|
export default (api) => {
|
|
193
|
+
CustomCharacteristics(api);
|
|
192
194
|
api.registerPlatform(PluginName, PlatformName, tasmotaPlatform);
|
|
193
195
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
export default (api) => {
|
|
2
|
+
const { Service, Characteristic, Units, Formats, Perms } = api.hap;
|
|
3
|
+
|
|
4
|
+
//Envoy production/consumption characteristics
|
|
5
|
+
class Power extends Characteristic {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('Power', '00000071-000B-1000-8000-0026BB765291');
|
|
8
|
+
this.setProps({
|
|
9
|
+
format: Formats.FLOAT,
|
|
10
|
+
unit: 'W',
|
|
11
|
+
maxValue: 10000,
|
|
12
|
+
minValue: -10000,
|
|
13
|
+
minStep: 0.001,
|
|
14
|
+
perms: [Perms.PAIRED_READ, Perms.NOTIFY]
|
|
15
|
+
});
|
|
16
|
+
this.value = this.getDefaultValue();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
Characteristic.Power = Power;
|
|
20
|
+
|
|
21
|
+
class ApparentPower extends Characteristic {
|
|
22
|
+
constructor() {
|
|
23
|
+
super('Apparent power', '00000072-000B-1000-8000-0026BB765291');
|
|
24
|
+
this.setProps({
|
|
25
|
+
format: Formats.FLOAT,
|
|
26
|
+
unit: 'VA',
|
|
27
|
+
maxValue: 10000,
|
|
28
|
+
minValue: -10000,
|
|
29
|
+
minStep: 0.001,
|
|
30
|
+
perms: [Perms.PAIRED_READ, Perms.NOTIFY]
|
|
31
|
+
});
|
|
32
|
+
this.value = this.getDefaultValue();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
Characteristic.ApparentPower = ApparentPower;
|
|
36
|
+
|
|
37
|
+
class ReactivePower extends Characteristic {
|
|
38
|
+
constructor() {
|
|
39
|
+
super('Reactive power', '00000073-000B-1000-8000-0026BB765291');
|
|
40
|
+
this.setProps({
|
|
41
|
+
format: Formats.FLOAT,
|
|
42
|
+
unit: 'VAr',
|
|
43
|
+
maxValue: 10000,
|
|
44
|
+
minValue: -10000,
|
|
45
|
+
minStep: 0.001,
|
|
46
|
+
perms: [Perms.PAIRED_READ, Perms.NOTIFY]
|
|
47
|
+
});
|
|
48
|
+
this.value = this.getDefaultValue();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
Characteristic.ReactivePower = ReactivePower;
|
|
52
|
+
|
|
53
|
+
class EnergyToday extends Characteristic {
|
|
54
|
+
constructor() {
|
|
55
|
+
super('Energy today', '00000074-000B-1000-8000-0026BB765291');
|
|
56
|
+
this.setProps({
|
|
57
|
+
format: Formats.FLOAT,
|
|
58
|
+
unit: 'kWh',
|
|
59
|
+
maxValue: 1000,
|
|
60
|
+
minValue: -1000,
|
|
61
|
+
minStep: 0.001,
|
|
62
|
+
perms: [Perms.PAIRED_READ, Perms.NOTIFY]
|
|
63
|
+
});
|
|
64
|
+
this.value = this.getDefaultValue();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
Characteristic.EnergyToday = EnergyToday;
|
|
68
|
+
|
|
69
|
+
class EnergyLastDay extends Characteristic {
|
|
70
|
+
constructor() {
|
|
71
|
+
super('Energy last day', '00000075-000B-1000-8000-0026BB765291');
|
|
72
|
+
this.setProps({
|
|
73
|
+
format: Formats.FLOAT,
|
|
74
|
+
unit: 'kWh',
|
|
75
|
+
maxValue: 1000,
|
|
76
|
+
minValue: -1000,
|
|
77
|
+
minStep: 0.001,
|
|
78
|
+
perms: [Perms.PAIRED_READ, Perms.NOTIFY]
|
|
79
|
+
});
|
|
80
|
+
this.value = this.getDefaultValue();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
Characteristic.EnergyLastDay = EnergyLastDay;
|
|
84
|
+
|
|
85
|
+
class EnergyLifetime extends Characteristic {
|
|
86
|
+
constructor() {
|
|
87
|
+
super('Energy lifetime', '00000076-000B-1000-8000-0026BB765291');
|
|
88
|
+
this.setProps({
|
|
89
|
+
format: Formats.FLOAT,
|
|
90
|
+
unit: 'kWh',
|
|
91
|
+
maxValue: 100000000,
|
|
92
|
+
minValue: -100000000,
|
|
93
|
+
minStep: 0.001,
|
|
94
|
+
perms: [Perms.PAIRED_READ, Perms.NOTIFY]
|
|
95
|
+
});
|
|
96
|
+
this.value = this.getDefaultValue();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
Characteristic.EnergyLifetime = EnergyLifetime;
|
|
100
|
+
|
|
101
|
+
class Current extends Characteristic {
|
|
102
|
+
constructor() {
|
|
103
|
+
super('Current', '00000077-000B-1000-8000-0026BB765291');
|
|
104
|
+
this.setProps({
|
|
105
|
+
format: Formats.FLOAT,
|
|
106
|
+
unit: 'A',
|
|
107
|
+
maxValue: 1000,
|
|
108
|
+
minValue: -1000,
|
|
109
|
+
minStep: 0.001,
|
|
110
|
+
perms: [Perms.PAIRED_READ, Perms.NOTIFY]
|
|
111
|
+
});
|
|
112
|
+
this.value = this.getDefaultValue();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
Characteristic.Current = Current;
|
|
116
|
+
|
|
117
|
+
class Voltage extends Characteristic {
|
|
118
|
+
constructor() {
|
|
119
|
+
super('Voltage', '00000078-000B-1000-8000-0026BB765291');
|
|
120
|
+
this.setProps({
|
|
121
|
+
format: Formats.FLOAT,
|
|
122
|
+
unit: 'V',
|
|
123
|
+
maxValue: 1000,
|
|
124
|
+
minValue: 0,
|
|
125
|
+
minStep: 0.1,
|
|
126
|
+
perms: [Perms.PAIRED_READ, Perms.NOTIFY]
|
|
127
|
+
});
|
|
128
|
+
this.value = this.getDefaultValue();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
Characteristic.Voltage = Voltage;
|
|
132
|
+
|
|
133
|
+
class Factor extends Characteristic {
|
|
134
|
+
constructor() {
|
|
135
|
+
super('Power factor', '00000079-000B-1000-8000-0026BB765291');
|
|
136
|
+
this.setProps({
|
|
137
|
+
format: Formats.FLOAT,
|
|
138
|
+
unit: 'cos φ',
|
|
139
|
+
maxValue: 1,
|
|
140
|
+
minValue: -1,
|
|
141
|
+
minStep: 0.01,
|
|
142
|
+
perms: [Perms.PAIRED_READ, Perms.NOTIFY]
|
|
143
|
+
});
|
|
144
|
+
this.value = this.getDefaultValue();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
Characteristic.Factor = Factor;
|
|
148
|
+
|
|
149
|
+
class Freqency extends Characteristic {
|
|
150
|
+
constructor() {
|
|
151
|
+
super('Frequency', '00000080-000B-1000-8000-0026BB765291');
|
|
152
|
+
this.setProps({
|
|
153
|
+
format: Formats.FLOAT,
|
|
154
|
+
unit: 'Hz',
|
|
155
|
+
maxValue: 100,
|
|
156
|
+
minValue: 0,
|
|
157
|
+
minStep: 0.01,
|
|
158
|
+
perms: [Perms.PAIRED_READ, Perms.NOTIFY]
|
|
159
|
+
});
|
|
160
|
+
this.value = this.getDefaultValue();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
Characteristic.Freqency = Freqency;
|
|
164
|
+
|
|
165
|
+
class ReadingTime extends Characteristic {
|
|
166
|
+
constructor() {
|
|
167
|
+
super('Reading time', '00000081-000B-1000-8000-0026BB765291');
|
|
168
|
+
this.setProps({
|
|
169
|
+
format: Formats.STRING,
|
|
170
|
+
perms: [Perms.PAIRED_READ, Perms.NOTIFY]
|
|
171
|
+
});
|
|
172
|
+
this.value = this.getDefaultValue();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
Characteristic.ReadingTime = ReadingTime;
|
|
176
|
+
|
|
177
|
+
//power production service
|
|
178
|
+
class PowerAndEnergyService extends Service {
|
|
179
|
+
constructor(displayName, subtype) {
|
|
180
|
+
super(displayName, '00000004-000A-1000-8000-0026BB765291', subtype);
|
|
181
|
+
// Mandatory Characteristics
|
|
182
|
+
this.addCharacteristic(Characteristic.Power)
|
|
183
|
+
// Optional Characteristics
|
|
184
|
+
this.addOptionalCharacteristic(Characteristic.ApparentPower);
|
|
185
|
+
this.addOptionalCharacteristic(Characteristic.ReactivePower);
|
|
186
|
+
this.addOptionalCharacteristic(Characteristic.EnergyToday);
|
|
187
|
+
this.addOptionalCharacteristic(Characteristic.EnergyLastDay);
|
|
188
|
+
this.addOptionalCharacteristic(Characteristic.EnergyLifetime);
|
|
189
|
+
this.addOptionalCharacteristic(Characteristic.Current);
|
|
190
|
+
this.addOptionalCharacteristic(Characteristic.Voltage);
|
|
191
|
+
this.addOptionalCharacteristic(Characteristic.Factor);
|
|
192
|
+
this.addOptionalCharacteristic(Characteristic.Freqency);
|
|
193
|
+
this.addOptionalCharacteristic(Characteristic.ReadingTime);
|
|
194
|
+
this.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
Service.PowerAndEnergyService = PowerAndEnergyService;
|
|
198
|
+
};
|
package/src/deviceinfo.js
CHANGED
|
@@ -54,11 +54,6 @@ class DeviceInfo extends EventEmitter {
|
|
|
54
54
|
//status SNS
|
|
55
55
|
const statusSns = deviceInfo.StatusSNS ?? {};
|
|
56
56
|
const statusSnsKeys = Object.keys(statusSns);
|
|
57
|
-
const sensorName = Object.entries(statusSns)
|
|
58
|
-
.filter(([key]) => SensorKeys.some(type => key.includes(type)))
|
|
59
|
-
.reduce((obj, [key, value]) => {
|
|
60
|
-
return key;
|
|
61
|
-
}, {});
|
|
62
57
|
|
|
63
58
|
//status STS
|
|
64
59
|
const statusSts = deviceInfo.StatusSTS ?? {};
|
|
@@ -71,6 +66,7 @@ class DeviceInfo extends EventEmitter {
|
|
|
71
66
|
const fans = statusStsKeys.includes('FanSpeed') ? types.push(3) : false;
|
|
72
67
|
const switches = !mielhvac && !lights && !fans ? types.push(1) : false
|
|
73
68
|
const sensors = statusSnsKeys.some(key => SensorKeys.includes(key)) ? types.push(4) : false;
|
|
69
|
+
const sensorName = Object.entries(statusSns).filter(([key]) => SensorKeys.some(type => key.includes(type))).reduce((obj, [key, value]) => { return key; }, {});
|
|
74
70
|
const obj = {
|
|
75
71
|
deviceTypes: types,
|
|
76
72
|
deviceName: deviceName,
|
package/src/mielhvac.js
CHANGED
|
@@ -814,7 +814,7 @@ class MiElHvac extends EventEmitter {
|
|
|
814
814
|
this.emit('devInfo', `Hardware: ${this.info.modelName}`);
|
|
815
815
|
this.emit('devInfo', `Serialnr: ${this.serialNumber}`)
|
|
816
816
|
this.emit('devInfo', `Firmware: ${this.info.firmwareRevision}`);
|
|
817
|
-
this.emit('devInfo', `
|
|
817
|
+
this.emit('devInfo', `Device: MiELHVAC`);
|
|
818
818
|
this.emit('devInfo', `----------------------------------`);
|
|
819
819
|
return;
|
|
820
820
|
}
|
package/src/sensors.js
CHANGED
|
@@ -75,7 +75,7 @@ class Sensors extends EventEmitter {
|
|
|
75
75
|
//sensor status
|
|
76
76
|
const sensorStatusData = await this.axiosInstance(ApiCommands.Status);
|
|
77
77
|
const sensorStatus = sensorStatusData.data ?? {};
|
|
78
|
-
const debug1 =
|
|
78
|
+
const debug1 = this.enableDebugMode ? this.emit('debug', `Sensors status: ${JSON.stringify(sensorStatus, null, 2)}`) : false;
|
|
79
79
|
|
|
80
80
|
//sensor status keys
|
|
81
81
|
const sensorStatusKeys = Object.keys(sensorStatus);
|
|
@@ -100,10 +100,9 @@ class Sensors extends EventEmitter {
|
|
|
100
100
|
//sensor
|
|
101
101
|
const obj = {
|
|
102
102
|
name: key,
|
|
103
|
-
time:
|
|
104
|
-
tempUnit:
|
|
105
|
-
pressureUnit:
|
|
106
|
-
|
|
103
|
+
time: statusSns.Time,
|
|
104
|
+
tempUnit: statusSns.TempUnit,
|
|
105
|
+
pressureUnit: statusSns.PressureUnit,
|
|
107
106
|
temperature: sensorData.Temperature,
|
|
108
107
|
referenceTemperature: sensorData.ReferenceTemperature,
|
|
109
108
|
objTemperature: sensorData.OBJTMP,
|
|
@@ -115,27 +114,29 @@ class Sensors extends EventEmitter {
|
|
|
115
114
|
carbonDioxyde: sensorData.CarbonDioxyde,
|
|
116
115
|
ambientLight: sensorData.Ambient,
|
|
117
116
|
motion: sensorData.Motion
|
|
117
|
+
};
|
|
118
|
+
if (obj.tempUnit === 'C') {
|
|
119
|
+
obj.tempUnit = '°C';
|
|
118
120
|
}
|
|
119
|
-
|
|
120
|
-
obj.tempUnit = obj.tempUnit === 'C' ? '°C' : 'F';
|
|
121
|
-
}
|
|
121
|
+
|
|
122
122
|
//energy
|
|
123
123
|
const obj1 = {
|
|
124
|
-
energyTotalStartTime: sensorData.TotalStartTime,
|
|
125
|
-
energyTotal: sensorData.Total,
|
|
126
|
-
energyPeriod: sensorData.Period,
|
|
127
|
-
energyYesterday: sensorData.Yesterday,
|
|
128
|
-
energyToday: sensorData.Today,
|
|
129
124
|
power: sensorData.Power,
|
|
130
125
|
apparentPower: sensorData.ApparentPower,
|
|
131
126
|
reactivePower: sensorData.ReactivePower,
|
|
132
|
-
|
|
133
|
-
|
|
127
|
+
energyToday: sensorData.Today,
|
|
128
|
+
energyLastDay: sensorData.Yesterday,
|
|
129
|
+
energyLifetime: sensorData.Total,
|
|
130
|
+
energyLifeTimeStartTime: sensorData.TotalStartTime,
|
|
131
|
+
energyPeriod: sensorData.Period,
|
|
134
132
|
current: sensorData.Current,
|
|
133
|
+
voltage: sensorData.Voltage,
|
|
134
|
+
factor: sensorData.Factor,
|
|
135
|
+
frequency: sensorData.Frequency,
|
|
135
136
|
load: sensorData.Load,
|
|
136
|
-
}
|
|
137
|
+
};
|
|
137
138
|
const sensor = key === 'ENERGY' ? { ...obj, ...obj1 } : obj;
|
|
138
|
-
this.emit('debug', `
|
|
139
|
+
const debug1 = this.enableDebugMode ? this.emit('debug', `Sensor: ${JSON.stringify(sensor, null, 2)}`) : false;
|
|
139
140
|
|
|
140
141
|
//push to array
|
|
141
142
|
this.sensors.push(sensor);
|
|
@@ -146,18 +147,58 @@ class Sensors extends EventEmitter {
|
|
|
146
147
|
if (this.sensorsCount > 0) {
|
|
147
148
|
for (let i = 0; i < this.sensorsCount; i++) {
|
|
148
149
|
const sensor = this.sensors[i];
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
this.
|
|
160
|
-
this.
|
|
150
|
+
|
|
151
|
+
const update = (service, charName, value) => {
|
|
152
|
+
const characteristic = service?.[i]?.Characteristic?.[charName];
|
|
153
|
+
if (characteristic && Characteristic?.[charName]) {
|
|
154
|
+
characteristic.updateCharacteristic(Characteristic[charName], value);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
//temperature
|
|
159
|
+
update(this.sensorTemperatureServices, 'CurrentTemperature', sensor.temperature);
|
|
160
|
+
update(this.sensorReferenceTemperatureServices, 'CurrentTemperature', sensor.referenceTemperature);
|
|
161
|
+
update(this.sensorObjTemperatureServices, 'CurrentTemperature', sensor.objTemperature);
|
|
162
|
+
update(this.sensorAmbTemperatureServices, 'CurrentTemperature', sensor.ambTemperature);
|
|
163
|
+
update(this.sensorDewPointTemperatureServices, 'CurrentTemperature', sensor.dewPointTemperature);
|
|
164
|
+
|
|
165
|
+
//humidity
|
|
166
|
+
update(this.sensorHumidityServices, 'CurrentRelativeHumidity', sensor.humidity);
|
|
167
|
+
|
|
168
|
+
//co₂
|
|
169
|
+
const co2Service = this.sensorCarbonDioxydeServices?.[i];
|
|
170
|
+
update(this.sensorCarbonDioxydeServices, 'CarbonDioxideDetected', sensor.carbonDioxyde > 1000);
|
|
171
|
+
update(this.sensorCarbonDioxydeServices, 'CarbonDioxideLevel', sensor.carbonDioxyde);
|
|
172
|
+
update(this.sensorCarbonDioxydeServices, 'CarbonDioxidePeakLevel', sensor.carbonDioxyde);
|
|
173
|
+
|
|
174
|
+
//ambient light
|
|
175
|
+
update(this.sensorAmbientLightServices, 'CurrentAmbientLightLevel', sensor.ambientLight);
|
|
176
|
+
|
|
177
|
+
//motion
|
|
178
|
+
update(this.sensorMotionServices, 'MotionDetected', sensor.motion);
|
|
179
|
+
|
|
180
|
+
//energy
|
|
181
|
+
const energyFields = {
|
|
182
|
+
Power: 'power',
|
|
183
|
+
ApparentPower: 'apparentpower',
|
|
184
|
+
ReactivePower: 'reactivepower',
|
|
185
|
+
EnergyToday: 'energytoday',
|
|
186
|
+
EnergyLastDay: 'energylastday',
|
|
187
|
+
EnergyLifetime: 'energylifetime',
|
|
188
|
+
Current: 'current',
|
|
189
|
+
Voltage: 'voltage',
|
|
190
|
+
Factor: 'factor',
|
|
191
|
+
Frequency: 'frequency',
|
|
192
|
+
ReadingTime: 'readingtime'
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const energyService = this.sensorEnergyServices?.[i]?.Characteristic;
|
|
196
|
+
for (const [charName, sensorKey] of Object.entries(energyFields)) {
|
|
197
|
+
const value = sensor[sensorKey];
|
|
198
|
+
if (energyService?.[charName] && Characteristic?.[charName] !== undefined) {
|
|
199
|
+
energyService[charName].updateCharacteristic(Characteristic[charName], value);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
161
202
|
}
|
|
162
203
|
}
|
|
163
204
|
}
|
|
@@ -205,7 +246,7 @@ class Sensors extends EventEmitter {
|
|
|
205
246
|
this.emit('devInfo', `Hardware: ${this.info.modelName}`);
|
|
206
247
|
this.emit('devInfo', `Serialnr: ${this.serialNumber}`)
|
|
207
248
|
this.emit('devInfo', `Firmware: ${this.info.firmwareRevision}`);
|
|
208
|
-
this.emit('devInfo', `
|
|
249
|
+
this.emit('devInfo', `Sensor: ${this.info.sensorName}`);
|
|
209
250
|
this.emit('devInfo', `----------------------------------`);
|
|
210
251
|
return;
|
|
211
252
|
}
|
|
@@ -233,14 +274,23 @@ class Sensors extends EventEmitter {
|
|
|
233
274
|
//Prepare services
|
|
234
275
|
if (this.sensorsCount > 0) {
|
|
235
276
|
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Sensor Services`) : false;
|
|
277
|
+
this.sensorTemperatureServices = [];
|
|
278
|
+
this.sensorReferenceTemperatureServices = [];
|
|
279
|
+
this.sensorObjTemperatureServices = [];
|
|
280
|
+
this.sensorAmbTemperatureServices = [];
|
|
281
|
+
this.sensorDewPointTemperatureServices = [];
|
|
282
|
+
this.sensorHumidityServices = [];
|
|
283
|
+
this.sensorCarbonDioxydeServices = [];
|
|
284
|
+
this.sensorAmbientLightServices = [];
|
|
285
|
+
this.sensorMotionServices = [];
|
|
286
|
+
this.sensorEnergyServices = [];
|
|
236
287
|
|
|
237
288
|
//temperature
|
|
238
289
|
let i = 0;
|
|
239
290
|
for (const sensor of this.sensors) {
|
|
240
291
|
const sensorName = sensor.name;
|
|
241
|
-
if (sensor.temperature
|
|
292
|
+
if (sensor.temperature) {
|
|
242
293
|
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Temperature Sensor Services`) : false;
|
|
243
|
-
this.sensorTemperatureServices = [];
|
|
244
294
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Temperature` : `${sensorName} Temperature`;
|
|
245
295
|
const sensorTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Temperature Sensor ${i}`);
|
|
246
296
|
sensorTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -255,9 +305,8 @@ class Sensors extends EventEmitter {
|
|
|
255
305
|
}
|
|
256
306
|
|
|
257
307
|
//reference temperature
|
|
258
|
-
if (sensor.referenceTemperature
|
|
308
|
+
if (sensor.referenceTemperature) {
|
|
259
309
|
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Reference Temperature Sensor Services`) : false;
|
|
260
|
-
this.sensorReferenceTemperatureServices = [];
|
|
261
310
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Reference Temperature` : `${sensorName} Reference Temperature`;
|
|
262
311
|
const sensorReferenceTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Reference Temperature Sensor ${i}`);
|
|
263
312
|
sensorReferenceTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -272,9 +321,8 @@ class Sensors extends EventEmitter {
|
|
|
272
321
|
}
|
|
273
322
|
|
|
274
323
|
//object temperature
|
|
275
|
-
if (sensor.objTemperature
|
|
324
|
+
if (sensor.objTemperature) {
|
|
276
325
|
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Obj Temperature Sensor Services`) : false;
|
|
277
|
-
this.sensorObjTemperatureServices = [];
|
|
278
326
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Obj Temperature` : `${sensorName} Obj Temperature`;
|
|
279
327
|
const sensorObjTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Obj Temperature Sensor ${i}`);
|
|
280
328
|
sensorObjTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -289,9 +337,8 @@ class Sensors extends EventEmitter {
|
|
|
289
337
|
}
|
|
290
338
|
|
|
291
339
|
//ambient temperature
|
|
292
|
-
if (sensor.ambTemperature
|
|
340
|
+
if (sensor.ambTemperature) {
|
|
293
341
|
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Amb Temperature Sensor Services`) : false;
|
|
294
|
-
this.sensorAmbTemperatureServices = [];
|
|
295
342
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Amb Temperature` : `${sensorName} Amb Temperature`;
|
|
296
343
|
const sensorAmbTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Amb Temperature Sensor ${i}`);
|
|
297
344
|
sensorAmbTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -306,9 +353,8 @@ class Sensors extends EventEmitter {
|
|
|
306
353
|
}
|
|
307
354
|
|
|
308
355
|
//dew point temperature
|
|
309
|
-
if (sensor.dewPointTemperature
|
|
356
|
+
if (sensor.dewPointTemperature) {
|
|
310
357
|
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Dew Point Temperature Sensor Services`) : false;
|
|
311
|
-
this.sensorDewPointTemperatureServices = [];
|
|
312
358
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Dew Point` : `${sensorName} Dew Point`;
|
|
313
359
|
const sensorDewPointTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Dew Point Temperature Sensor ${i}`);
|
|
314
360
|
sensorDewPointTemperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -323,9 +369,8 @@ class Sensors extends EventEmitter {
|
|
|
323
369
|
}
|
|
324
370
|
|
|
325
371
|
//humidity
|
|
326
|
-
if (sensor.humidity
|
|
372
|
+
if (sensor.humidity) {
|
|
327
373
|
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Humidity Sensor Services`) : false;
|
|
328
|
-
this.sensorHumidityServices = [];
|
|
329
374
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Humidity` : `${sensorName} Humidity`;
|
|
330
375
|
const sensorHumidityService = accessory.addService(Service.HumiditySensor, serviceName, `Humidity Sensor ${i}`);
|
|
331
376
|
sensorHumidityService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -344,9 +389,8 @@ class Sensors extends EventEmitter {
|
|
|
344
389
|
//gas
|
|
345
390
|
|
|
346
391
|
//carbon dioxyde
|
|
347
|
-
if (sensor.carbonDioxyde
|
|
392
|
+
if (sensor.carbonDioxyde) {
|
|
348
393
|
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Carbon Dioxyde Sensor Services`) : false;
|
|
349
|
-
this.sensorCarbonDioxydeServices = [];
|
|
350
394
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Carbon Dioxyde` : `${sensorName} Carbon Dioxyde`;
|
|
351
395
|
const sensorCarbonDioxydeService = accessory.addService(Service.CarbonDioxideSensor, serviceName, `Carbon Dioxyde Sensor ${i}`);
|
|
352
396
|
sensorCarbonDioxydeService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -373,9 +417,8 @@ class Sensors extends EventEmitter {
|
|
|
373
417
|
}
|
|
374
418
|
|
|
375
419
|
//ambient light
|
|
376
|
-
if (sensor.ambientLight
|
|
420
|
+
if (sensor.ambientLight) {
|
|
377
421
|
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Ambient Light Sensor Services`) : false;
|
|
378
|
-
this.sensorAmbientLightServices = [];
|
|
379
422
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Ambient Light` : `${sensorName} Ambient Light`;
|
|
380
423
|
const sensorAmbientLightService = accessory.addService(Service.LightSensor, serviceName, `Ambient Light Sensor ${i}`);
|
|
381
424
|
sensorAmbientLightService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -390,9 +433,8 @@ class Sensors extends EventEmitter {
|
|
|
390
433
|
}
|
|
391
434
|
|
|
392
435
|
//motion
|
|
393
|
-
if (sensor.motion
|
|
436
|
+
if (sensor.motion) {
|
|
394
437
|
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Motion Sensor Services`) : false;
|
|
395
|
-
this.sensorMotionServices = [];
|
|
396
438
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Motion` : `${sensorName} Motion`;
|
|
397
439
|
const sensorMotionService = accessory.addService(Service.MotionSensor, serviceName, `Motion Sensor ${i}`);
|
|
398
440
|
sensorMotionService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -405,6 +447,103 @@ class Sensors extends EventEmitter {
|
|
|
405
447
|
});
|
|
406
448
|
this.sensorMotionServices.push(sensorMotionService);
|
|
407
449
|
}
|
|
450
|
+
|
|
451
|
+
//energy
|
|
452
|
+
if (sensor.name === 'ENERGY') {
|
|
453
|
+
const debug4 = this.enableDebugMode ? this.emit('debug', `Prepare Power And Energy Service`) : false;
|
|
454
|
+
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName}` : `${sensorName} Sensor`;
|
|
455
|
+
const energyService = accessory.addService(Service.PowerAndEnergyService, serviceName, `Energy Sensor ${i}`);
|
|
456
|
+
energyService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
457
|
+
if (sensor.power) {
|
|
458
|
+
energyService.getCharacteristic(Characteristic.Power)
|
|
459
|
+
.onGet(async () => {
|
|
460
|
+
const value = sensor.power;
|
|
461
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} power: ${value} W`);
|
|
462
|
+
return value;
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
if (sensor.apparentPower) {
|
|
466
|
+
energyService.getCharacteristic(Characteristic.ApparentPower)
|
|
467
|
+
.onGet(async () => {
|
|
468
|
+
const value = sensor.apparentPower;
|
|
469
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} apparent power: ${value} VA`);
|
|
470
|
+
return value;
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
if (sensor.reactivePower) {
|
|
474
|
+
energyService.getCharacteristic(Characteristic.ReactivePower)
|
|
475
|
+
.onGet(async () => {
|
|
476
|
+
const value = sensor.reactivePower;
|
|
477
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} reactive power: ${value} VAr`);
|
|
478
|
+
return value;
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
if (sensor.energyToday) {
|
|
482
|
+
energyService.getCharacteristic(Characteristic.EnergyToday)
|
|
483
|
+
.onGet(async () => {
|
|
484
|
+
const value = sensor.energyToday;
|
|
485
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} energy today: ${value} kWh`);
|
|
486
|
+
return value;
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
if (sensor.energyLastDay) {
|
|
490
|
+
energyService.getCharacteristic(Characteristic.EnergyLastDay)
|
|
491
|
+
.onGet(async () => {
|
|
492
|
+
const value = sensor.energyLastDay;
|
|
493
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} energy last day: ${value} kWh`);
|
|
494
|
+
return value;
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
if (sensor.energyLifetime) {
|
|
498
|
+
energyService.getCharacteristic(Characteristic.EnergyLifetime)
|
|
499
|
+
.onGet(async () => {
|
|
500
|
+
const value = sensor.energyLifetime;
|
|
501
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} energy lifetime: ${value} kWh`);
|
|
502
|
+
return value;
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
if (sensor.current) {
|
|
506
|
+
energyService.getCharacteristic(Characteristic.Current)
|
|
507
|
+
.onGet(async () => {
|
|
508
|
+
const value = sensor.current;
|
|
509
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} current: ${value} A`);
|
|
510
|
+
return value;
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
if (sensor.voltage) {
|
|
514
|
+
energyService.getCharacteristic(Characteristic.Voltage)
|
|
515
|
+
.onGet(async () => {
|
|
516
|
+
const value = sensor.voltage;
|
|
517
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} voltage: ${value} V`);
|
|
518
|
+
return value;
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
if (sensor.factor) {
|
|
522
|
+
energyService.getCharacteristic(Characteristic.Factor)
|
|
523
|
+
.onGet(async () => {
|
|
524
|
+
const value = sensor.factor;
|
|
525
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} power factor: ${value} cos φ`);
|
|
526
|
+
return value;
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
if (sensor.frequency) {
|
|
530
|
+
energyService.getCharacteristic(Characteristic.Freqency)
|
|
531
|
+
.onGet(async () => {
|
|
532
|
+
const value = sensor.frequency;
|
|
533
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} frequency: ${value} Hz`);
|
|
534
|
+
return value;
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
if (sensor.time) {
|
|
538
|
+
energyService.getCharacteristic(Characteristic.ReadingTime)
|
|
539
|
+
.onGet(async () => {
|
|
540
|
+
const value = sensor.time;
|
|
541
|
+
const info = this.disableLogInfo ? false : this.emit('info', `sensor: ${sensorName} last report: ${value}`);
|
|
542
|
+
return value;
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
this.sensorEnergyServices.push(energyService);
|
|
546
|
+
}
|
|
408
547
|
i++;
|
|
409
548
|
}
|
|
410
549
|
}
|