hoffmation-base 2.12.3 → 2.12.4
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/lib/models/persistence/EnergyCalculation.d.ts +3 -0
- package/lib/models/persistence/EnergyCalculation.js +22 -0
- package/lib/server/devices/baseDeviceInterfaces/iEnergyManager.d.ts +3 -0
- package/lib/server/devices/jsObject/jsObjectEnergyManager.js +1 -15
- package/lib/server/services/ac/ac-device.js +1 -1
- package/lib/server/services/ac/own-daikin-device.js +1 -0
- package/lib/server/services/victron/victron-device.d.ts +9 -0
- package/lib/server/services/victron/victron-device.js +46 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { LogLevel } from '../logLevel';
|
|
2
|
+
import { LogDebugType } from '../../server';
|
|
1
3
|
export declare class EnergyCalculation {
|
|
2
4
|
startMs: number;
|
|
3
5
|
drawnKwH: number;
|
|
@@ -8,4 +10,5 @@ export declare class EnergyCalculation {
|
|
|
8
10
|
savedSelfConsume: number;
|
|
9
11
|
endMs: number;
|
|
10
12
|
constructor(startMs: number);
|
|
13
|
+
static persist(obj: EnergyCalculation, endMs: number, logger: (level: LogLevel, message: string, logDebugType?: LogDebugType) => void): boolean;
|
|
11
14
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EnergyCalculation = void 0;
|
|
4
|
+
const logLevel_1 = require("../logLevel");
|
|
5
|
+
const server_1 = require("../../server");
|
|
4
6
|
class EnergyCalculation {
|
|
5
7
|
constructor(startMs) {
|
|
6
8
|
this.startMs = startMs;
|
|
@@ -12,5 +14,25 @@ class EnergyCalculation {
|
|
|
12
14
|
this.savedSelfConsume = 0;
|
|
13
15
|
this.endMs = 0;
|
|
14
16
|
}
|
|
17
|
+
static persist(obj, endMs, logger) {
|
|
18
|
+
var _a, _b, _c, _d;
|
|
19
|
+
if (obj.drawnKwH === 0 && obj.injectedKwH === 0 && obj.selfConsumedKwH === 0) {
|
|
20
|
+
logger(logLevel_1.LogLevel.Warn, `Not persisting energy Data, as all values are 0.`);
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
if (!server_1.SettingsService.settings.wattagePrice) {
|
|
24
|
+
logger(logLevel_1.LogLevel.Warn, `Wattage price not set, assuming average of 34ct.`);
|
|
25
|
+
}
|
|
26
|
+
obj.endMs = endMs;
|
|
27
|
+
obj.earnedInjected = server_1.Utils.round(obj.injectedKwH * ((_a = server_1.SettingsService.settings.injectWattagePrice) !== null && _a !== void 0 ? _a : 0.06), 4);
|
|
28
|
+
obj.savedSelfConsume = server_1.Utils.round(obj.selfConsumedKwH * ((_b = server_1.SettingsService.settings.wattagePrice) !== null && _b !== void 0 ? _b : 0.35), 4);
|
|
29
|
+
obj.costDrawn = server_1.Utils.round(obj.drawnKwH * ((_c = server_1.SettingsService.settings.wattagePrice) !== null && _c !== void 0 ? _c : 0.35), 4);
|
|
30
|
+
obj.injectedKwH = server_1.Utils.round(obj.injectedKwH, 4);
|
|
31
|
+
obj.selfConsumedKwH = server_1.Utils.round(obj.selfConsumedKwH, 4);
|
|
32
|
+
obj.drawnKwH = server_1.Utils.round(obj.drawnKwH, 4);
|
|
33
|
+
(_d = server_1.Utils.dbo) === null || _d === void 0 ? void 0 : _d.persistEnergyManager(obj);
|
|
34
|
+
logger(logLevel_1.LogLevel.Info, `Persisting energy Manager Data.`);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
15
37
|
}
|
|
16
38
|
exports.EnergyCalculation = EnergyCalculation;
|
|
@@ -2,6 +2,9 @@ import { iExcessEnergyConsumer } from './iExcessEnergyConsumer';
|
|
|
2
2
|
import { iBaseDevice } from './iBaseDevice';
|
|
3
3
|
export interface iEnergyManager extends iBaseDevice {
|
|
4
4
|
excessEnergy: number;
|
|
5
|
+
readonly injectingWattage: number;
|
|
6
|
+
readonly drawingWattage: number;
|
|
7
|
+
readonly selfConsumingWattage: number;
|
|
5
8
|
addExcessConsumer(device: iExcessEnergyConsumer): void;
|
|
6
9
|
recalculatePowerSharing(): void;
|
|
7
10
|
cleanup(): void;
|
|
@@ -148,25 +148,11 @@ class JsObjectEnergyManager extends IoBrokerBaseDevice_1.IoBrokerBaseDevice {
|
|
|
148
148
|
this._lastPersistenceCalculation = now;
|
|
149
149
|
}
|
|
150
150
|
persist() {
|
|
151
|
-
var _a, _b, _c, _d;
|
|
152
151
|
const obj = JSON.parse(JSON.stringify(this._nextPersistEntry));
|
|
153
|
-
if (obj
|
|
154
|
-
this.log(models_1.LogLevel.Warn, `Not persisting energy Data, as all values are 0.`);
|
|
152
|
+
if (!models_1.EnergyCalculation.persist(obj, this._lastPersistenceCalculation, this.log.bind(this))) {
|
|
155
153
|
return;
|
|
156
154
|
}
|
|
157
|
-
if (!services_1.SettingsService.settings.wattagePrice) {
|
|
158
|
-
this.log(models_1.LogLevel.Warn, `Wattage price not set, assuming average of 34ct.`);
|
|
159
|
-
}
|
|
160
155
|
this._nextPersistEntry = new models_1.EnergyCalculation(this._lastPersistenceCalculation);
|
|
161
|
-
obj.endMs = this._lastPersistenceCalculation;
|
|
162
|
-
obj.earnedInjected = services_1.Utils.round(obj.injectedKwH * ((_a = services_1.SettingsService.settings.injectWattagePrice) !== null && _a !== void 0 ? _a : 0.06), 4);
|
|
163
|
-
obj.savedSelfConsume = services_1.Utils.round(obj.selfConsumedKwH * ((_b = services_1.SettingsService.settings.wattagePrice) !== null && _b !== void 0 ? _b : 0.35), 4);
|
|
164
|
-
obj.costDrawn = services_1.Utils.round(obj.drawnKwH * ((_c = services_1.SettingsService.settings.wattagePrice) !== null && _c !== void 0 ? _c : 0.35), 4);
|
|
165
|
-
obj.injectedKwH = services_1.Utils.round(obj.injectedKwH, 4);
|
|
166
|
-
obj.selfConsumedKwH = services_1.Utils.round(obj.selfConsumedKwH, 4);
|
|
167
|
-
obj.drawnKwH = services_1.Utils.round(obj.drawnKwH, 4);
|
|
168
|
-
(_d = services_1.Utils.dbo) === null || _d === void 0 ? void 0 : _d.persistEnergyManager(obj);
|
|
169
|
-
this.log(models_1.LogLevel.Info, `Persisting energy Manager Data.`);
|
|
170
156
|
}
|
|
171
157
|
turnOnAdditionalConsumer() {
|
|
172
158
|
const result = services_1.EnergyManagerUtils.turnOnAdditionalConsumer(this._excessEnergyConsumer, this._lastDeviceChange);
|
|
@@ -225,7 +225,7 @@ class AcDevice {
|
|
|
225
225
|
this.turnOn();
|
|
226
226
|
}
|
|
227
227
|
onRoomFirstEnter() {
|
|
228
|
-
if (!this.settings.noCoolingOnMovement || !this.on || this.mode
|
|
228
|
+
if (!this.settings.noCoolingOnMovement || !this.on || this.mode === ac_mode_1.AcMode.Heating) {
|
|
229
229
|
return;
|
|
230
230
|
}
|
|
231
231
|
this.log(models_1.LogLevel.Info, `Someone entered the room. Turning off AC`);
|
|
@@ -72,6 +72,7 @@ class OwnDaikinDevice extends ac_device_1.AcDevice {
|
|
|
72
72
|
this.log(models_1.LogLevel.Info, `Turning off`);
|
|
73
73
|
this._activatedByExcessEnergy = false;
|
|
74
74
|
this.desiredState = daikin_controller_1.Power.OFF;
|
|
75
|
+
this._mode = ac_mode_1.AcMode.Off;
|
|
75
76
|
this.setDesiredInfo();
|
|
76
77
|
}
|
|
77
78
|
automaticCheck() {
|
|
@@ -11,6 +11,10 @@ export declare class VictronDevice implements iEnergyManager {
|
|
|
11
11
|
private _excessEnergyConsumer;
|
|
12
12
|
private blockDeviceChangeTime;
|
|
13
13
|
private _lastDeviceChange;
|
|
14
|
+
private _iCalculationInterval;
|
|
15
|
+
private _iDatabaseLoggerInterval;
|
|
16
|
+
private _lastPersistenceCalculation;
|
|
17
|
+
private _nextPersistEntry;
|
|
14
18
|
constructor(opts: VictronMqttConnectionOptions);
|
|
15
19
|
protected _info: DeviceInfo;
|
|
16
20
|
get info(): DeviceInfo;
|
|
@@ -22,6 +26,9 @@ export declare class VictronDevice implements iEnergyManager {
|
|
|
22
26
|
get customName(): string;
|
|
23
27
|
get id(): string;
|
|
24
28
|
addExcessConsumer(device: iExcessEnergyConsumer): void;
|
|
29
|
+
get injectingWattage(): number;
|
|
30
|
+
get drawingWattage(): number;
|
|
31
|
+
get selfConsumingWattage(): number;
|
|
25
32
|
cleanup(): void;
|
|
26
33
|
getReport(): string;
|
|
27
34
|
recalculatePowerSharing(): void;
|
|
@@ -37,4 +44,6 @@ export declare class VictronDevice implements iEnergyManager {
|
|
|
37
44
|
private calculateExcessEnergy;
|
|
38
45
|
private turnOnAdditionalConsumer;
|
|
39
46
|
private turnOffAdditionalConsumer;
|
|
47
|
+
private persist;
|
|
48
|
+
private calculatePersistenceValues;
|
|
40
49
|
}
|
|
@@ -14,6 +14,9 @@ class VictronDevice {
|
|
|
14
14
|
this.deviceType = devices_1.DeviceType.Victron;
|
|
15
15
|
this._excessEnergyConsumer = [];
|
|
16
16
|
this.blockDeviceChangeTime = -1;
|
|
17
|
+
this._iCalculationInterval = null;
|
|
18
|
+
this._iDatabaseLoggerInterval = null;
|
|
19
|
+
this._lastPersistenceCalculation = utils_1.Utils.nowMS();
|
|
17
20
|
this._excessEnergy = 0;
|
|
18
21
|
this.settings = new models_1.VictronDeviceSettings();
|
|
19
22
|
this._info = new devices_1.DeviceInfo();
|
|
@@ -25,6 +28,13 @@ class VictronDevice {
|
|
|
25
28
|
this.persistDeviceInfo();
|
|
26
29
|
this.loadDeviceSettings();
|
|
27
30
|
this._victronConsumer = new victron_mqtt_consumer_1.VictronMqttConsumer(opts);
|
|
31
|
+
this._iCalculationInterval = utils_1.Utils.guardedInterval(() => {
|
|
32
|
+
this.calculateExcessEnergy();
|
|
33
|
+
}, 5 * 1000, this);
|
|
34
|
+
this._iDatabaseLoggerInterval = utils_1.Utils.guardedInterval(() => {
|
|
35
|
+
this.persist();
|
|
36
|
+
}, 15 * 60 * 1000, this);
|
|
37
|
+
this._nextPersistEntry = new models_1.EnergyCalculation(utils_1.Utils.nowMS());
|
|
28
38
|
}
|
|
29
39
|
get info() {
|
|
30
40
|
return this._info;
|
|
@@ -51,8 +61,28 @@ class VictronDevice {
|
|
|
51
61
|
addExcessConsumer(device) {
|
|
52
62
|
this._excessEnergyConsumer.push(device);
|
|
53
63
|
}
|
|
64
|
+
get injectingWattage() {
|
|
65
|
+
var _a;
|
|
66
|
+
return Math.min((_a = this.victronConsumer.data.grid.power) !== null && _a !== void 0 ? _a : 0, 0) * -1;
|
|
67
|
+
}
|
|
68
|
+
get drawingWattage() {
|
|
69
|
+
var _a;
|
|
70
|
+
return Math.max((_a = this.victronConsumer.data.grid.power) !== null && _a !== void 0 ? _a : 0, 0);
|
|
71
|
+
}
|
|
72
|
+
get selfConsumingWattage() {
|
|
73
|
+
var _a;
|
|
74
|
+
return Math.max((_a = this.victronConsumer.data.system.power) !== null && _a !== void 0 ? _a : 0, 0) - this.drawingWattage;
|
|
75
|
+
}
|
|
54
76
|
cleanup() {
|
|
55
77
|
this._victronConsumer.disconnect();
|
|
78
|
+
if (this._iDatabaseLoggerInterval !== null) {
|
|
79
|
+
clearInterval(this._iDatabaseLoggerInterval);
|
|
80
|
+
this._iDatabaseLoggerInterval = null;
|
|
81
|
+
}
|
|
82
|
+
if (this._iCalculationInterval !== null) {
|
|
83
|
+
clearInterval(this._iCalculationInterval);
|
|
84
|
+
this._iCalculationInterval = null;
|
|
85
|
+
}
|
|
56
86
|
}
|
|
57
87
|
getReport() {
|
|
58
88
|
return '';
|
|
@@ -126,6 +156,7 @@ class VictronDevice {
|
|
|
126
156
|
this.data.battery.soc > (hoursTilSunset > 4 ? 0.7 : 0.8)) {
|
|
127
157
|
this._excessEnergy = this.settings.maximumBatteryDischargeWattage - Math.max(this.data.battery.dcPower, 0);
|
|
128
158
|
}
|
|
159
|
+
this.calculatePersistenceValues();
|
|
129
160
|
}
|
|
130
161
|
turnOnAdditionalConsumer() {
|
|
131
162
|
const result = utils_1.EnergyManagerUtils.turnOnAdditionalConsumer(this._excessEnergyConsumer, this._lastDeviceChange);
|
|
@@ -153,5 +184,20 @@ class VictronDevice {
|
|
|
153
184
|
this._lastDeviceChange = result;
|
|
154
185
|
}
|
|
155
186
|
}
|
|
187
|
+
persist() {
|
|
188
|
+
const obj = JSON.parse(JSON.stringify(this._nextPersistEntry));
|
|
189
|
+
if (!models_1.EnergyCalculation.persist(obj, this._lastPersistenceCalculation, this.log.bind(this))) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
this._nextPersistEntry = new models_1.EnergyCalculation(this._lastPersistenceCalculation);
|
|
193
|
+
}
|
|
194
|
+
calculatePersistenceValues() {
|
|
195
|
+
const now = utils_1.Utils.nowMS();
|
|
196
|
+
const duration = now - this._lastPersistenceCalculation;
|
|
197
|
+
this._nextPersistEntry.drawnKwH += utils_1.Utils.kWh(this.drawingWattage, duration);
|
|
198
|
+
this._nextPersistEntry.injectedKwH += utils_1.Utils.kWh(this.injectingWattage, duration);
|
|
199
|
+
this._nextPersistEntry.selfConsumedKwH += utils_1.Utils.kWh(this.selfConsumingWattage, duration);
|
|
200
|
+
this._lastPersistenceCalculation = now;
|
|
201
|
+
}
|
|
156
202
|
}
|
|
157
203
|
exports.VictronDevice = VictronDevice;
|