iobroker.luxtronik2-controller 0.1.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/LICENSE +21 -0
- package/README.md +89 -0
- package/admin/i18n/de.json +5 -0
- package/admin/i18n/en.json +5 -0
- package/admin/i18n/es.json +5 -0
- package/admin/i18n/fr.json +5 -0
- package/admin/i18n/it.json +5 -0
- package/admin/i18n/nl.json +5 -0
- package/admin/i18n/pl.json +5 -0
- package/admin/i18n/pt.json +5 -0
- package/admin/i18n/ru.json +5 -0
- package/admin/i18n/uk.json +5 -0
- package/admin/i18n/zh-cn.json +5 -0
- package/admin/jsonConfig.json +1194 -0
- package/admin/luxtronik2-controller.png +0 -0
- package/build/actionHandlers.js +71 -0
- package/build/actionHandlers.js.map +7 -0
- package/build/codes.js +241 -0
- package/build/codes.js.map +7 -0
- package/build/logger.js +54 -0
- package/build/logger.js.map +7 -0
- package/build/main.js +692 -0
- package/build/main.js.map +7 -0
- package/build/notificationManager.js +175 -0
- package/build/notificationManager.js.map +7 -0
- package/build/objectManager.js +333 -0
- package/build/objectManager.js.map +7 -0
- package/build/rawFunctions.js +183 -0
- package/build/rawFunctions.js.map +7 -0
- package/build/stateMapping.js +3925 -0
- package/build/stateMapping.js.map +7 -0
- package/build/virtualStates.js +456 -0
- package/build/virtualStates.js.map +7 -0
- package/build/zipManager.js +160 -0
- package/build/zipManager.js.map +7 -0
- package/io-package.json +233 -0
- package/package.json +79 -0
package/build/main.js
ADDED
|
@@ -0,0 +1,692 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var utils = __toESM(require("@iobroker/adapter-core"));
|
|
25
|
+
var import_actionHandlers = require("./actionHandlers");
|
|
26
|
+
var import_logger = require("./logger");
|
|
27
|
+
var import_notificationManager = require("./notificationManager");
|
|
28
|
+
var import_objectManager = require("./objectManager");
|
|
29
|
+
var import_rawFunctions = require("./rawFunctions");
|
|
30
|
+
var import_stateMapping = require("./stateMapping");
|
|
31
|
+
var import_virtualStates = require("./virtualStates");
|
|
32
|
+
var import_zipManager = require("./zipManager");
|
|
33
|
+
class Luxtronik2Controller extends utils.Adapter {
|
|
34
|
+
createdStates = /* @__PURE__ */ new Set();
|
|
35
|
+
zipTimer;
|
|
36
|
+
originalZipConfig = null;
|
|
37
|
+
lastKnownErrorTimestamp = null;
|
|
38
|
+
isDebugLogActive = false;
|
|
39
|
+
pollingInterval;
|
|
40
|
+
pump;
|
|
41
|
+
lastBzVal = "";
|
|
42
|
+
updateRunning = false;
|
|
43
|
+
lastPumpOptimization = 0;
|
|
44
|
+
writeQueue = [];
|
|
45
|
+
isWriting = false;
|
|
46
|
+
errorCount = 0;
|
|
47
|
+
MAX_ERRORS = 3;
|
|
48
|
+
constructor(options = {}) {
|
|
49
|
+
super({
|
|
50
|
+
...options,
|
|
51
|
+
name: "luxtronik2-controller"
|
|
52
|
+
});
|
|
53
|
+
(0, import_logger.initLogger)(this);
|
|
54
|
+
this.on("ready", this.onReady.bind(this));
|
|
55
|
+
this.on("stateChange", this.onStateChange.bind(this));
|
|
56
|
+
this.on("unload", this.onUnload.bind(this));
|
|
57
|
+
this.on("message", this.onMessage.bind(this));
|
|
58
|
+
}
|
|
59
|
+
async onMessage(obj) {
|
|
60
|
+
if (obj.command === "testTelegram") {
|
|
61
|
+
await (0, import_notificationManager.handleTestMessage)(this, obj);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async onReady() {
|
|
65
|
+
const config = this.config;
|
|
66
|
+
const ip = config.host;
|
|
67
|
+
const port = config.port || 8889;
|
|
68
|
+
await this.setState("info.connection", { val: false, ack: true });
|
|
69
|
+
(0, import_logger.writeLog)(`Verbinde mit W\xE4rmepumpe auf ${ip}:${port}...`, "info");
|
|
70
|
+
await (0, import_objectManager.cleanupStates)(this);
|
|
71
|
+
await (0, import_objectManager.cleanupCustomStates)(this);
|
|
72
|
+
await (0, import_objectManager.cleanupEmptyFolders)(this);
|
|
73
|
+
await (0, import_objectManager.ensureAllObjectsExist)(this);
|
|
74
|
+
await (0, import_objectManager.ensureCustomObjectsExist)(this);
|
|
75
|
+
const debugState = await this.getStateAsync((0, import_stateMapping.getDpPath)("Schreibe_Debug_Log"));
|
|
76
|
+
this.isDebugLogActive = (debugState == null ? void 0 : debugState.val) === true;
|
|
77
|
+
(0, import_logger.setCustomDebug)(this.isDebugLogActive);
|
|
78
|
+
if (this.isDebugLogActive) {
|
|
79
|
+
(0, import_logger.writeLog)("Synchronisiere Konfigurationswerte mit der W\xE4rmepumpe...", "info");
|
|
80
|
+
}
|
|
81
|
+
await this.setIdleDefaults();
|
|
82
|
+
if (config.motion_sensors_aktiv && Array.isArray(config.motionSensors)) {
|
|
83
|
+
for (const sensor of config.motionSensors) {
|
|
84
|
+
if (sensor.oid && typeof sensor.oid === "string" && sensor.oid.trim() !== "") {
|
|
85
|
+
this.subscribeForeignStates(sensor.oid.trim());
|
|
86
|
+
if (this.isDebugLogActive) {
|
|
87
|
+
(0, import_logger.writeLog)(`Bewegungssensor abonniert: ${sensor.name} (${sensor.oid})`, "info");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
this.subscribeStates("*");
|
|
93
|
+
await this.updateData();
|
|
94
|
+
let intervalSeconds = config.interval || 30;
|
|
95
|
+
if (intervalSeconds < 10) {
|
|
96
|
+
intervalSeconds = 10;
|
|
97
|
+
(0, import_logger.writeLog)("Eingestelltes Intervall war zu kurz. Wurde zum Schutz auf 10 Sekunden korrigiert.", "warn");
|
|
98
|
+
}
|
|
99
|
+
(0, import_logger.writeLog)(`Starte Polling-Intervall. Lese Daten und optimiere alle ${intervalSeconds} Sekunden.`, "info");
|
|
100
|
+
await this.setState("info.connection", true, true);
|
|
101
|
+
this.pollingInterval = setInterval(() => {
|
|
102
|
+
void this.updateData();
|
|
103
|
+
}, intervalSeconds * 1e3);
|
|
104
|
+
}
|
|
105
|
+
async syncConfigValue(mappingKey, val) {
|
|
106
|
+
if (val === void 0 || val === null) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const id = (0, import_stateMapping.getDpPath)(mappingKey);
|
|
110
|
+
const state = await this.getStateAsync(id);
|
|
111
|
+
if (!state || state.val !== val) {
|
|
112
|
+
const definition = import_stateMapping.STATE_MAPPING[mappingKey];
|
|
113
|
+
if (!definition) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
await this.setState(id, { val, ack: true });
|
|
117
|
+
if (this.isDebugLogActive) {
|
|
118
|
+
(0, import_logger.writeLog)(`Schreibe Wert direkt in W\xE4rmepumpe: ${mappingKey} = ${val}`, "info");
|
|
119
|
+
}
|
|
120
|
+
if (definition.write === true && !definition.isVirtual && definition.luxWriteId) {
|
|
121
|
+
let valueToWrite = val;
|
|
122
|
+
if (definition.factor && typeof val === "number") {
|
|
123
|
+
valueToWrite = val * definition.factor;
|
|
124
|
+
}
|
|
125
|
+
const isRawWrite = definition.dataSource === "raw_parameter" || definition.dataSource === "raw_value" || !definition.dataSource && /^\d+$/.test(definition.luxWriteId || "");
|
|
126
|
+
if (isRawWrite && definition.unit === "\xB0C" && typeof val === "number" && !definition.factor) {
|
|
127
|
+
valueToWrite = val * 10;
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
const targetWriteId = definition.luxWriteId;
|
|
131
|
+
const writeId = isRawWrite ? parseInt(targetWriteId, 10) : targetWriteId;
|
|
132
|
+
await this.queueWrite(writeId, valueToWrite);
|
|
133
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
134
|
+
} catch (err) {
|
|
135
|
+
(0, import_logger.writeLog)(`Fehler beim Schreiben von ${mappingKey} an die Pumpe: ${err.message}`, "error");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async setOwnStateIfDifferent(id, val, ack = false) {
|
|
141
|
+
try {
|
|
142
|
+
if (val === void 0) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const state = await this.getStateAsync(id);
|
|
146
|
+
if (!state || state.val !== val) {
|
|
147
|
+
await this.setState(id, { val, ack });
|
|
148
|
+
if (this.isDebugLogActive) {
|
|
149
|
+
(0, import_logger.writeLog)(`Setze Werte f\xFCr ${id}: ${val}`, "debug");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
} catch (err) {
|
|
153
|
+
(0, import_logger.writeLog)(`Fehler in setOwnStateIfDifferent f\xFCr ${id}: ${err.message}`, "error");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async setIdleDefaults() {
|
|
157
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
158
|
+
try {
|
|
159
|
+
const config = this.config;
|
|
160
|
+
await this.syncConfigValue("heating_curve_end_point", (_a = config.endpunkt) != null ? _a : 23);
|
|
161
|
+
await this.syncConfigValue("heating_curve_parallel_offset", (_b = config.fusspunkt) != null ? _b : 21.7);
|
|
162
|
+
await this.syncConfigValue(
|
|
163
|
+
"heating_system_circ_pump_voltage_minimal",
|
|
164
|
+
(_c = config.sync_heating_system_circ_pump_voltage_minimal_heating) != null ? _c : 3
|
|
165
|
+
);
|
|
166
|
+
await this.syncConfigValue(
|
|
167
|
+
"heating_system_circ_pump_voltage_nominal",
|
|
168
|
+
(_d = config.sync_heating_system_circ_pump_voltage_nominal_heating) != null ? _d : 7
|
|
169
|
+
);
|
|
170
|
+
await this.syncConfigValue("warmwater_temperature", (_e = config.sync_warmwater_target_temperature) != null ? _e : 54);
|
|
171
|
+
await this.syncConfigValue(
|
|
172
|
+
"hotWaterTemperatureHysteresis",
|
|
173
|
+
(_f = config.sync_hotwater_temperature_hysteresis) != null ? _f : 10
|
|
174
|
+
);
|
|
175
|
+
await this.syncConfigValue("returnTemperatureHysteresis", (_g = config.sync_return_temperature_hysteresis) != null ? _g : 1.5);
|
|
176
|
+
await this.syncConfigValue("zip_aktiv", (_h = config.zip_aktiv) != null ? _h : 0);
|
|
177
|
+
await this.syncConfigValue("Heizen_nach_Wasser", (_i = config.Heating_after_warmwater) != null ? _i : false);
|
|
178
|
+
} catch (err) {
|
|
179
|
+
(0, import_logger.writeLog)(`Fehler beim Setzen der Leerlauf-Vorgabewerte: ${err.message}`, "error");
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async istBetriebszustandAelterAls10Min() {
|
|
183
|
+
var _a;
|
|
184
|
+
try {
|
|
185
|
+
const state = await this.getStateAsync((0, import_stateMapping.getDpPath)("WP_BZ_akt"));
|
|
186
|
+
const lastChange = (_a = state == null ? void 0 : state.lc) != null ? _a : 0;
|
|
187
|
+
return (Date.now() - lastChange) / 6e4 >= 10;
|
|
188
|
+
} catch {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
async runOptimizationSchedule() {
|
|
193
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
194
|
+
try {
|
|
195
|
+
const regelungAktiv = await this.getStateAsync((0, import_stateMapping.getDpPath)("Regelung_Aktiv"));
|
|
196
|
+
if ((regelungAktiv == null ? void 0 : regelungAktiv.val) === false) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const bzState = await this.getStateAsync((0, import_stateMapping.getDpPath)("WP_BZ_akt"));
|
|
200
|
+
const bzVal = bzState && bzState.val !== null ? String(bzState.val).trim() : "";
|
|
201
|
+
const istHeizen = bzVal === "0";
|
|
202
|
+
const istWarmwasser = bzVal === "1";
|
|
203
|
+
const istAbtauen = bzVal === "4";
|
|
204
|
+
const istLeerlauf = bzVal === "5";
|
|
205
|
+
if (!istHeizen && !istWarmwasser && !istLeerlauf && !istAbtauen) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const config = this.config;
|
|
209
|
+
if (bzVal !== this.lastBzVal) {
|
|
210
|
+
if (istLeerlauf) {
|
|
211
|
+
await this.setIdleDefaults();
|
|
212
|
+
} else if (istHeizen) {
|
|
213
|
+
await this.syncConfigValue("zip_aktiv", (_a = config.zip_aktiv) != null ? _a : 0);
|
|
214
|
+
await this.syncConfigValue(
|
|
215
|
+
"heating_system_circ_pump_voltage_minimal",
|
|
216
|
+
(_b = config.sync_heating_system_circ_pump_voltage_minimal_heating) != null ? _b : 3
|
|
217
|
+
);
|
|
218
|
+
await this.syncConfigValue(
|
|
219
|
+
"heating_system_circ_pump_voltage_nominal",
|
|
220
|
+
(_c = config.sync_heating_system_circ_pump_voltage_nominal_heating) != null ? _c : 7
|
|
221
|
+
);
|
|
222
|
+
await this.syncConfigValue("Heizen_nach_Wasser", (_d = config.Heating_after_warmwater) != null ? _d : false);
|
|
223
|
+
} else if (istWarmwasser) {
|
|
224
|
+
await this.syncConfigValue(
|
|
225
|
+
"hotWaterTemperatureHysteresis",
|
|
226
|
+
(_e = config.sync_hotwater_temperature_hysteresis) != null ? _e : 2
|
|
227
|
+
);
|
|
228
|
+
await this.syncConfigValue("zip_aktiv", (_f = config.zip_aktiv_ww) != null ? _f : 0);
|
|
229
|
+
await this.syncConfigValue(
|
|
230
|
+
"heating_system_circ_pump_voltage_minimal",
|
|
231
|
+
(_g = config.sync_heating_system_circ_pump_voltage_minimal_water) != null ? _g : 3
|
|
232
|
+
);
|
|
233
|
+
await this.syncConfigValue(
|
|
234
|
+
"heating_system_circ_pump_voltage_nominal",
|
|
235
|
+
(_h = config.sync_heating_system_circ_pump_voltage_nominal_water) != null ? _h : 10
|
|
236
|
+
);
|
|
237
|
+
await this.setOwnStateIfDifferent((0, import_stateMapping.getDpPath)("Activate_Zip"), true, false);
|
|
238
|
+
} else if (istAbtauen) {
|
|
239
|
+
await this.syncConfigValue("heating_system_circ_pump_voltage_nominal", 10);
|
|
240
|
+
}
|
|
241
|
+
this.lastBzVal = bzVal;
|
|
242
|
+
}
|
|
243
|
+
const [
|
|
244
|
+
wwSollState,
|
|
245
|
+
wwIstState,
|
|
246
|
+
ruecklaufState,
|
|
247
|
+
spreizungState,
|
|
248
|
+
heatingStateStrState,
|
|
249
|
+
vd1State,
|
|
250
|
+
wwHystereseState,
|
|
251
|
+
ruecklaufSollState,
|
|
252
|
+
hupAktivState,
|
|
253
|
+
heizenHystereseState,
|
|
254
|
+
nachWasserState,
|
|
255
|
+
aelterAls10
|
|
256
|
+
] = await Promise.all([
|
|
257
|
+
this.getStateAsync((0, import_stateMapping.getDpPath)("Wamwassertemperatur_Soll")),
|
|
258
|
+
this.getStateAsync((0, import_stateMapping.getDpPath)("Wamwassertemperatur_Ist")),
|
|
259
|
+
this.getStateAsync((0, import_stateMapping.getDpPath)("temperature_return")),
|
|
260
|
+
this.getStateAsync((0, import_stateMapping.getDpPath)("spreizung_vorlauf_ruecklauf")),
|
|
261
|
+
this.getStateAsync((0, import_stateMapping.getDpPath)("opStateHeatingString")),
|
|
262
|
+
this.getStateAsync((0, import_stateMapping.getDpPath)("VD1out")),
|
|
263
|
+
this.getStateAsync((0, import_stateMapping.getDpPath)("hotWaterTemperatureHysteresis")),
|
|
264
|
+
this.getStateAsync((0, import_stateMapping.getDpPath)("temperature_target_return")),
|
|
265
|
+
this.getStateAsync((0, import_stateMapping.getDpPath)("HUPout")),
|
|
266
|
+
this.getStateAsync((0, import_stateMapping.getDpPath)("returnTemperatureHysteresis")),
|
|
267
|
+
this.getStateAsync((0, import_stateMapping.getDpPath)("Heizen_nach_Wasser")),
|
|
268
|
+
this.istBetriebszustandAelterAls10Min()
|
|
269
|
+
]);
|
|
270
|
+
const wwSoll = (_i = wwSollState == null ? void 0 : wwSollState.val) != null ? _i : 0;
|
|
271
|
+
const wwIst = (_j = wwIstState == null ? void 0 : wwIstState.val) != null ? _j : 0;
|
|
272
|
+
const ruecklauf = (_k = ruecklaufState == null ? void 0 : ruecklaufState.val) != null ? _k : 0;
|
|
273
|
+
const spreizung = (_l = spreizungState == null ? void 0 : spreizungState.val) != null ? _l : 0;
|
|
274
|
+
const heatingStateStr = String((heatingStateStrState == null ? void 0 : heatingStateStrState.val) || "").trim();
|
|
275
|
+
const vd1 = (vd1State == null ? void 0 : vd1State.val) === 1;
|
|
276
|
+
const wwHysterese = (_m = wwHystereseState == null ? void 0 : wwHystereseState.val) != null ? _m : 0;
|
|
277
|
+
const ruecklaufSoll = (_n = ruecklaufSollState == null ? void 0 : ruecklaufSollState.val) != null ? _n : 0;
|
|
278
|
+
const hupAktiv = (_o = hupAktivState == null ? void 0 : hupAktivState.val) != null ? _o : 0;
|
|
279
|
+
const heizenHysterese = (_p = heizenHystereseState == null ? void 0 : heizenHystereseState.val) != null ? _p : 0;
|
|
280
|
+
const nachWasser = nachWasserState == null ? void 0 : nachWasserState.val;
|
|
281
|
+
const betriebsart = (_q = bzState == null ? void 0 : bzState.val) != null ? _q : 0;
|
|
282
|
+
if (istHeizen) {
|
|
283
|
+
if (aelterAls10 && vd1) {
|
|
284
|
+
const fusspunkt = (_r = await this.getStateAsync((0, import_stateMapping.getDpPath)("heating_curve_parallel_offset"))) == null ? void 0 : _r.val;
|
|
285
|
+
if (fusspunkt === 35) {
|
|
286
|
+
const fallbackFusspunkt = (_s = config.fusspunkt) != null ? _s : 21.7;
|
|
287
|
+
await this.syncConfigValue("heating_curve_parallel_offset", fallbackFusspunkt);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const now = Date.now();
|
|
291
|
+
if (now - this.lastPumpOptimization > 3e5) {
|
|
292
|
+
if (spreizung < 6.5 && hupAktiv > 5.5) {
|
|
293
|
+
await this.syncConfigValue("heating_system_circ_pump_voltage_nominal", hupAktiv - 0.25);
|
|
294
|
+
this.lastPumpOptimization = now;
|
|
295
|
+
(0, import_logger.writeLog)(
|
|
296
|
+
`Spreizung zu gering (${spreizung}K). HUP-Spannung auf ${hupAktiv - 0.25}V gesenkt. N\xE4chste Pr\xFCfung in 5 Min.`,
|
|
297
|
+
"info"
|
|
298
|
+
);
|
|
299
|
+
} else if (spreizung > 7.5 && hupAktiv < 10) {
|
|
300
|
+
await this.syncConfigValue("heating_system_circ_pump_voltage_nominal", hupAktiv + 0.25);
|
|
301
|
+
this.lastPumpOptimization = now;
|
|
302
|
+
(0, import_logger.writeLog)(
|
|
303
|
+
`Spreizung zu hoch (${spreizung}K). HUP-Spannung auf ${hupAktiv + 0.25}V erh\xF6ht. N\xE4chste Pr\xFCfung in 5 Min.`,
|
|
304
|
+
"info"
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
if (ruecklauf >= ruecklaufSoll + heizenHysterese - 0.1) {
|
|
309
|
+
if (aelterAls10) {
|
|
310
|
+
await this.syncConfigValue("Heizen_nach_Wasser", false);
|
|
311
|
+
}
|
|
312
|
+
} else if (!nachWasser && config.Heating_after_warmwater === true) {
|
|
313
|
+
await this.syncConfigValue("Heizen_nach_Wasser", true);
|
|
314
|
+
}
|
|
315
|
+
if (wwSoll - wwIst > 2 && ruecklauf >= ruecklaufSoll + heizenHysterese - 0.1) {
|
|
316
|
+
const fallbackHyst = (_t = config.sync_hotwater_temperature_hysteresis) != null ? _t : 2;
|
|
317
|
+
await this.syncConfigValue("hotWaterTemperatureHysteresis", fallbackHyst);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
if (istWarmwasser && nachWasser) {
|
|
321
|
+
await this.syncConfigValue("heating_curve_parallel_offset", 35);
|
|
322
|
+
}
|
|
323
|
+
if (istLeerlauf) {
|
|
324
|
+
if (wwIst <= wwSoll - wwHysterese || ruecklauf <= ruecklaufSoll - heizenHysterese) {
|
|
325
|
+
await (0, import_zipManager.stopZipAndDeaeration)(this);
|
|
326
|
+
}
|
|
327
|
+
if (wwSoll - wwIst >= wwHysterese - 1.5 && ruecklauf <= ruecklaufSoll && betriebsart !== 4 && heatingStateStr !== "Heizgrenze") {
|
|
328
|
+
await this.syncConfigValue("heating_curve_parallel_offset", 35);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
} catch (err) {
|
|
332
|
+
(0, import_logger.writeLog)(`Fehler im runOptimizationSchedule-Ablauf: ${err.message}`, "error");
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
async writePumpAsync(cmd, val) {
|
|
336
|
+
if (this.isDebugLogActive) {
|
|
337
|
+
(0, import_logger.writeLog)(`writePumpAsync Raw-Befehl: ID ${cmd}, val: ${val}`, "debug");
|
|
338
|
+
}
|
|
339
|
+
const paramId = typeof cmd === "string" ? parseInt(cmd, 10) : cmd;
|
|
340
|
+
let value = typeof val === "string" ? parseInt(val, 10) : val;
|
|
341
|
+
if (typeof value === "boolean") {
|
|
342
|
+
value = value ? 1 : 0;
|
|
343
|
+
}
|
|
344
|
+
await (0, import_rawFunctions.writeRawParameter)(this, paramId, value);
|
|
345
|
+
}
|
|
346
|
+
async queueWrite(cmd, val) {
|
|
347
|
+
return new Promise((resolve, reject) => {
|
|
348
|
+
this.writeQueue.push(async () => {
|
|
349
|
+
try {
|
|
350
|
+
await this.writePumpAsync(cmd, val);
|
|
351
|
+
resolve();
|
|
352
|
+
} catch (err) {
|
|
353
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
void this.processQueue();
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
async processQueue() {
|
|
360
|
+
if (this.isWriting || this.writeQueue.length === 0) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
this.isWriting = true;
|
|
364
|
+
const task = this.writeQueue.shift();
|
|
365
|
+
if (task) {
|
|
366
|
+
await task();
|
|
367
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
368
|
+
}
|
|
369
|
+
this.isWriting = false;
|
|
370
|
+
void this.processQueue();
|
|
371
|
+
}
|
|
372
|
+
formatSecondsToHMS(totalSeconds) {
|
|
373
|
+
if (totalSeconds < 0 || isNaN(totalSeconds)) {
|
|
374
|
+
return "00:00:00";
|
|
375
|
+
}
|
|
376
|
+
const hours = Math.floor(totalSeconds / 3600);
|
|
377
|
+
const minutes = Math.floor(totalSeconds % 3600 / 60);
|
|
378
|
+
const seconds = Math.floor(totalSeconds % 60);
|
|
379
|
+
return `${hours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
|
|
380
|
+
}
|
|
381
|
+
async updateData() {
|
|
382
|
+
if (this.updateRunning) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
this.updateRunning = true;
|
|
386
|
+
try {
|
|
387
|
+
let rawParams = [];
|
|
388
|
+
let rawValues = [];
|
|
389
|
+
try {
|
|
390
|
+
rawParams = await (0, import_rawFunctions.readAllRaw)(this, 3003);
|
|
391
|
+
} catch (err) {
|
|
392
|
+
(0, import_logger.writeLog)(`Raw 3003 Fehler: ${err.message}`, "debug");
|
|
393
|
+
}
|
|
394
|
+
await new Promise((r) => setTimeout(r, 3500));
|
|
395
|
+
try {
|
|
396
|
+
rawValues = await (0, import_rawFunctions.readAllRaw)(this, 3004);
|
|
397
|
+
} catch (err) {
|
|
398
|
+
(0, import_logger.writeLog)(`Raw 3004 Fehler: ${err.message}`, "debug");
|
|
399
|
+
}
|
|
400
|
+
await new Promise((r) => setTimeout(r, 3500));
|
|
401
|
+
this.errorCount = 0;
|
|
402
|
+
await this.setState("info.connection", { val: true, ack: true });
|
|
403
|
+
const statePromises = [];
|
|
404
|
+
const config = this.config;
|
|
405
|
+
for (const [key, definition] of Object.entries(import_stateMapping.STATE_MAPPING)) {
|
|
406
|
+
if (definition.isVirtual) {
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
if (!(0, import_objectManager.isStateEnabled)(key, definition, config)) {
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
const luxId = definition.luxWriteId || key;
|
|
413
|
+
let value = void 0;
|
|
414
|
+
if (definition.dataSource) {
|
|
415
|
+
switch (definition.dataSource) {
|
|
416
|
+
case "raw_parameter":
|
|
417
|
+
value = rawParams == null ? void 0 : rawParams[parseInt(luxId, 10)];
|
|
418
|
+
if (value !== void 0 && definition.factor) {
|
|
419
|
+
value /= definition.factor;
|
|
420
|
+
}
|
|
421
|
+
break;
|
|
422
|
+
case "raw_value":
|
|
423
|
+
value = rawValues == null ? void 0 : rawValues[parseInt(luxId, 10)];
|
|
424
|
+
if (value !== void 0 && definition.factor) {
|
|
425
|
+
value /= definition.factor;
|
|
426
|
+
}
|
|
427
|
+
break;
|
|
428
|
+
case "parameter":
|
|
429
|
+
case "value":
|
|
430
|
+
case "additional":
|
|
431
|
+
value = void 0;
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
} else {
|
|
435
|
+
if (/^\d+$/.test(luxId)) {
|
|
436
|
+
const idx = parseInt(luxId, 10);
|
|
437
|
+
value = definition.folder.startsWith("Einstellungen") ? rawParams == null ? void 0 : rawParams[idx] : rawValues == null ? void 0 : rawValues[idx];
|
|
438
|
+
if (value !== void 0 && definition.factor) {
|
|
439
|
+
value /= definition.factor;
|
|
440
|
+
}
|
|
441
|
+
} else {
|
|
442
|
+
value = void 0;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if (value !== void 0) {
|
|
446
|
+
if (definition.type === "number" && typeof value === "string") {
|
|
447
|
+
value = value.toLowerCase() === "ein" ? 1 : value.toLowerCase() === "aus" ? 0 : parseFloat(value);
|
|
448
|
+
} else if (definition.type === "boolean") {
|
|
449
|
+
value = value === true || value === 1 || String(value).toLowerCase() === "ein" || String(value).toLowerCase() === "true";
|
|
450
|
+
} else if (definition.type === "json" && typeof value === "object") {
|
|
451
|
+
value = JSON.stringify(value);
|
|
452
|
+
}
|
|
453
|
+
if (definition.unit === "s" && typeof value === "number") {
|
|
454
|
+
value = this.formatSecondsToHMS(value);
|
|
455
|
+
} else if (definition.role && ["value.datetime", "value.time", "date"].includes(definition.role)) {
|
|
456
|
+
const totalSeconds = typeof value === "number" ? value : parseInt(value, 10);
|
|
457
|
+
if (!isNaN(totalSeconds) && totalSeconds >= 0) {
|
|
458
|
+
if (totalSeconds < 86400) {
|
|
459
|
+
const h = Math.floor(totalSeconds / 3600).toString().padStart(2, "0");
|
|
460
|
+
const m = Math.floor(totalSeconds % 3600 / 60).toString().padStart(2, "0");
|
|
461
|
+
value = `${h}:${m}`;
|
|
462
|
+
} else {
|
|
463
|
+
value = new Date(totalSeconds * 1e3).toLocaleString("de-DE", {
|
|
464
|
+
day: "2-digit",
|
|
465
|
+
month: "2-digit",
|
|
466
|
+
year: "numeric",
|
|
467
|
+
hour: "2-digit",
|
|
468
|
+
minute: "2-digit",
|
|
469
|
+
second: "2-digit",
|
|
470
|
+
hour12: false
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
let targetIoBrokerType = definition.type === "json" ? "string" : definition.type;
|
|
476
|
+
if (definition.unit === "s" && definition.type === "number") {
|
|
477
|
+
targetIoBrokerType = "string";
|
|
478
|
+
}
|
|
479
|
+
if (definition.role && ["value.datetime", "value.time", "date"].includes(definition.role)) {
|
|
480
|
+
targetIoBrokerType = "string";
|
|
481
|
+
}
|
|
482
|
+
if (targetIoBrokerType === "string" && typeof value !== "string") {
|
|
483
|
+
value = String(value);
|
|
484
|
+
} else if (targetIoBrokerType === "number" && typeof value !== "number") {
|
|
485
|
+
value = Number(value);
|
|
486
|
+
} else if (targetIoBrokerType === "boolean" && typeof value !== "boolean") {
|
|
487
|
+
value = Boolean(value);
|
|
488
|
+
}
|
|
489
|
+
const stateId = `${definition.folder}.${key}`;
|
|
490
|
+
statePromises.push(this.setState(stateId, { val: value, ack: true }));
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
await Promise.all(statePromises);
|
|
494
|
+
await (0, import_virtualStates.calculateTotalThermalEnergy)(this);
|
|
495
|
+
await (0, import_virtualStates.calculateTotalEnergy)(this);
|
|
496
|
+
const fehlerDp = (0, import_stateMapping.getDpPath)("Fehlerspeicher");
|
|
497
|
+
const oldFehlerState = await this.getStateAsync(fehlerDp);
|
|
498
|
+
const oldFehlerVal = oldFehlerState == null ? void 0 : oldFehlerState.val;
|
|
499
|
+
await (0, import_virtualStates.updateErrorHistory)(this, rawValues);
|
|
500
|
+
const newFehlerState = await this.getStateAsync(fehlerDp);
|
|
501
|
+
const newFehlerVal = newFehlerState == null ? void 0 : newFehlerState.val;
|
|
502
|
+
await (0, import_notificationManager.checkAndSendErrorNotifications)(this, oldFehlerVal, newFehlerVal);
|
|
503
|
+
await (0, import_virtualStates.updateOutageHistory)(this, rawValues);
|
|
504
|
+
await (0, import_virtualStates.calculateTemperatureSpread)(this);
|
|
505
|
+
await (0, import_virtualStates.updateStatusStrings)(this, rawValues, rawParams);
|
|
506
|
+
await (0, import_virtualStates.updateCustomStates)(this, rawValues, rawParams);
|
|
507
|
+
await (0, import_virtualStates.updateTimerTables)(this);
|
|
508
|
+
await (0, import_virtualStates.updateSystemInfos)(this, rawValues);
|
|
509
|
+
await this.runOptimizationSchedule();
|
|
510
|
+
} catch (err) {
|
|
511
|
+
this.errorCount++;
|
|
512
|
+
(0, import_logger.writeLog)(`Abfragefehler (${this.errorCount}/${this.MAX_ERRORS}): ${err.message}`, "error");
|
|
513
|
+
if (this.errorCount >= this.MAX_ERRORS) {
|
|
514
|
+
await this.setState("info.connection", { val: false, ack: true });
|
|
515
|
+
(0, import_logger.writeLog)("W\xE4rmepumpe nicht erreichbar. Verbindung wurde als unterbrochen markiert.", "warn");
|
|
516
|
+
(0, import_notificationManager.sendTelegramNotification)(
|
|
517
|
+
this,
|
|
518
|
+
"W\xE4rmepumpe nicht erreichbar. Verbindung wurde als unterbrochen markiert."
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
} finally {
|
|
522
|
+
this.updateRunning = false;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
onUnload(callback) {
|
|
526
|
+
try {
|
|
527
|
+
if (this.pollingInterval) {
|
|
528
|
+
clearInterval(this.pollingInterval);
|
|
529
|
+
}
|
|
530
|
+
if (this.zipTimer) {
|
|
531
|
+
clearTimeout(this.zipTimer);
|
|
532
|
+
}
|
|
533
|
+
void this.setState("info.connection", { val: false, ack: true });
|
|
534
|
+
(0, import_logger.writeLog)("Adapter wird beendet. Alle Timer und Verbindungen sauber gestoppt.", "info");
|
|
535
|
+
callback();
|
|
536
|
+
} catch {
|
|
537
|
+
callback();
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
async onStateChange(id, state) {
|
|
541
|
+
if (!state) {
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
const config = this.config;
|
|
545
|
+
if (config.motion_sensors_aktiv && config.motionSensors && Array.isArray(config.motionSensors)) {
|
|
546
|
+
const matchedSensor = config.motionSensors.find((s) => s.oid && s.oid.trim() === id);
|
|
547
|
+
if (matchedSensor && state.val === true) {
|
|
548
|
+
const zipOutState = await this.getStateAsync((0, import_stateMapping.getDpPath)("ZIPout"));
|
|
549
|
+
if (zipOutState && zipOutState.val === 1) {
|
|
550
|
+
if (this.isDebugLogActive) {
|
|
551
|
+
(0, import_logger.writeLog)(`Bewegung an '${matchedSensor.name}' ignoriert, da ZIP bereits l\xE4uft.`, "debug");
|
|
552
|
+
}
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
const now = Date.now();
|
|
556
|
+
const lastZipChange = (zipOutState == null ? void 0 : zipOutState.lc) || 0;
|
|
557
|
+
if (now - lastZipChange > (config.zip_last_run_min || 600) * 1e3) {
|
|
558
|
+
if (this.isDebugLogActive) {
|
|
559
|
+
(0, import_logger.writeLog)(`Bewegung an '${matchedSensor.name || id}' erkannt. Triggere ZIP Makro.`, "debug");
|
|
560
|
+
}
|
|
561
|
+
await this.setForeignStateAsync(`${this.namespace}.${(0, import_stateMapping.getDpPath)("Activate_Zip")}`, {
|
|
562
|
+
val: true,
|
|
563
|
+
ack: false
|
|
564
|
+
});
|
|
565
|
+
} else {
|
|
566
|
+
if (this.isDebugLogActive) {
|
|
567
|
+
(0, import_logger.writeLog)(
|
|
568
|
+
`Bewegung an '${matchedSensor.name || id}' erkannt, aber ZIP hat k\xFCrzlich gearbeitet.`,
|
|
569
|
+
"debug"
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
if (state.ack) {
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
if (id.startsWith(`${this.namespace}.Benutzer.`)) {
|
|
580
|
+
try {
|
|
581
|
+
const obj = await this.getObjectAsync(id);
|
|
582
|
+
if (obj && obj.native && obj.native.source === "parameter") {
|
|
583
|
+
await this.setForeignStateAsync(id, { val: state.val, ack: true });
|
|
584
|
+
let valueToWrite = state.val;
|
|
585
|
+
if (obj.native.customType === "boolean") {
|
|
586
|
+
valueToWrite = state.val ? 1 : 0;
|
|
587
|
+
} else if (obj.native.customType === "number" && typeof state.val === "number") {
|
|
588
|
+
if (obj.native.factor) {
|
|
589
|
+
valueToWrite = Math.round(state.val / obj.native.factor);
|
|
590
|
+
} else {
|
|
591
|
+
valueToWrite = Math.round(state.val);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
const targetWriteId = parseInt(obj.native.luxId, 10);
|
|
595
|
+
if (!isNaN(targetWriteId)) {
|
|
596
|
+
if (this.isDebugLogActive) {
|
|
597
|
+
(0, import_logger.writeLog)(
|
|
598
|
+
`Schreibe benutzerdefinierten Parameter ${targetWriteId} mit Wert ${valueToWrite}`,
|
|
599
|
+
"info"
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
await this.queueWrite(targetWriteId, valueToWrite);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
} catch (err) {
|
|
606
|
+
(0, import_logger.writeLog)(`Fehler beim Schreiben eines eigenen Parameters: ${err.message}`, "error");
|
|
607
|
+
}
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
const mappingKey = id.split(".").pop();
|
|
611
|
+
if (!mappingKey) {
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
const definition = import_stateMapping.STATE_MAPPING[mappingKey];
|
|
615
|
+
if (!definition) {
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
try {
|
|
619
|
+
if (mappingKey === "Schreibe_Debug_Log") {
|
|
620
|
+
await this.setForeignStateAsync(id, { val: state.val, ack: true });
|
|
621
|
+
this.isDebugLogActive = state.val === true;
|
|
622
|
+
(0, import_logger.setCustomDebug)(this.isDebugLogActive);
|
|
623
|
+
(0, import_logger.writeLog)(`Erweitertes Logging ist nun ${this.isDebugLogActive ? "aktiviert" : "deaktiviert"}`, "info");
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
if (mappingKey === "Regelung_Aktiv" || mappingKey === "zip_aktiv") {
|
|
627
|
+
await this.setForeignStateAsync(id, { val: state.val, ack: true });
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
if (mappingKey === "Setze_Vorgabewerte" && state.val === true) {
|
|
631
|
+
await this.setForeignStateAsync(id, { val: false, ack: true });
|
|
632
|
+
await this.setIdleDefaults();
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
if (mappingKey === "Dump_Raw_To_Log" && state.val === true) {
|
|
636
|
+
await this.setForeignStateAsync(id, { val: false, ack: true });
|
|
637
|
+
await (0, import_rawFunctions.dumpAllRawToLog)(this);
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
if (mappingKey === "Zwangswarmwasser") {
|
|
641
|
+
if (state.val === true) {
|
|
642
|
+
await (0, import_actionHandlers.handleZwangswarmwasser)(this, id);
|
|
643
|
+
}
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
if (mappingKey === "Zwangsheizen") {
|
|
647
|
+
if (state.val === true) {
|
|
648
|
+
await (0, import_actionHandlers.handleZwangsheizen)(this, id);
|
|
649
|
+
}
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
if (mappingKey === "Activate_Zip") {
|
|
653
|
+
if (state.val === true) {
|
|
654
|
+
const durationState = await this.getStateAsync((0, import_stateMapping.getDpPath)("zip_aktiv"));
|
|
655
|
+
const durationSeconds = durationState && typeof durationState.val === "number" ? durationState.val : 120;
|
|
656
|
+
await (0, import_zipManager.handleActivateZip)(this, id, durationSeconds);
|
|
657
|
+
} else {
|
|
658
|
+
await this.setForeignStateAsync(id, { val: false, ack: true });
|
|
659
|
+
await (0, import_zipManager.stopZipAndDeaeration)(this);
|
|
660
|
+
}
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
if (!definition.luxWriteId || definition.write !== true) {
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
await this.setForeignStateAsync(id, { val: state.val, ack: true });
|
|
667
|
+
let valueToWrite = state.val;
|
|
668
|
+
if (definition.role === "value.datetime") {
|
|
669
|
+
const valStr = String(state.val).trim();
|
|
670
|
+
const timeMatch = valStr.match(/^(\d{1,2}):(\d{1,2})/);
|
|
671
|
+
if (timeMatch) {
|
|
672
|
+
valueToWrite = parseInt(timeMatch[1], 10) * 3600 + parseInt(timeMatch[2], 10) * 60;
|
|
673
|
+
}
|
|
674
|
+
} else if (definition.factor && typeof state.val === "number") {
|
|
675
|
+
valueToWrite = state.val * definition.factor;
|
|
676
|
+
}
|
|
677
|
+
if (definition.unit === "\xB0C" && typeof state.val === "number" && !definition.factor) {
|
|
678
|
+
valueToWrite = state.val * 10;
|
|
679
|
+
}
|
|
680
|
+
const targetWriteId = definition.luxWriteId;
|
|
681
|
+
await this.queueWrite(parseInt(targetWriteId, 10), valueToWrite);
|
|
682
|
+
} catch (err) {
|
|
683
|
+
(0, import_logger.writeLog)(`Fehler bei Befehlsausf\xFChrung: ${err.message}`, "error");
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
if (require.main !== module) {
|
|
688
|
+
module.exports = (options) => new Luxtronik2Controller(options);
|
|
689
|
+
} else {
|
|
690
|
+
(() => new Luxtronik2Controller())();
|
|
691
|
+
}
|
|
692
|
+
//# sourceMappingURL=main.js.map
|