iobroker.poolcontrol 0.3.0 → 0.4.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.
@@ -12,7 +12,7 @@
12
12
  * Wird durch pumpHelper3.js verwaltet.
13
13
  * Alle Werte sind persistent (persist: true).
14
14
  * ----------------------------------------------------------
15
- * Version: 1.0.0
15
+ * Version: 1.0.1
16
16
  */
17
17
 
18
18
  /**
@@ -49,7 +49,10 @@ async function createPumpStates3(adapter) {
49
49
  },
50
50
  native: {},
51
51
  });
52
- await adapter.setStateAsync('pump.learning.learned_avg_power_w', { val: 0, ack: true });
52
+ const existingPower = await adapter.getStateAsync('pump.learning.learned_avg_power_w');
53
+ if (existingPower === null || existingPower.val === null || existingPower.val === undefined) {
54
+ await adapter.setStateAsync('pump.learning.learned_avg_power_w', { val: 0, ack: true });
55
+ }
53
56
 
54
57
  // ------------------------------------------------------
55
58
  // Durchschnittlicher Durchfluss (L/h)
@@ -68,7 +71,10 @@ async function createPumpStates3(adapter) {
68
71
  },
69
72
  native: {},
70
73
  });
71
- await adapter.setStateAsync('pump.learning.learned_avg_flow_lh', { val: 0, ack: true });
74
+ const existingFlow = await adapter.getStateAsync('pump.learning.learned_avg_flow_lh');
75
+ if (existingFlow === null || existingFlow.val === null || existingFlow.val === undefined) {
76
+ await adapter.setStateAsync('pump.learning.learned_avg_flow_lh', { val: 0, ack: true });
77
+ }
72
78
 
73
79
  // ------------------------------------------------------
74
80
  // Normalbereich Leistung – Untere / Obere Grenze
@@ -87,7 +93,10 @@ async function createPumpStates3(adapter) {
87
93
  },
88
94
  native: {},
89
95
  });
90
- await adapter.setStateAsync('pump.learning.normal_range_power_low', { val: 0, ack: true });
96
+ const existingPowerLow = await adapter.getStateAsync('pump.learning.normal_range_power_low');
97
+ if (existingPowerLow === null || existingPowerLow.val === null || existingPowerLow.val === undefined) {
98
+ await adapter.setStateAsync('pump.learning.normal_range_power_low', { val: 0, ack: true });
99
+ }
91
100
 
92
101
  await adapter.setObjectNotExistsAsync('pump.learning.normal_range_power_high', {
93
102
  type: 'state',
@@ -103,7 +112,10 @@ async function createPumpStates3(adapter) {
103
112
  },
104
113
  native: {},
105
114
  });
106
- await adapter.setStateAsync('pump.learning.normal_range_power_high', { val: 0, ack: true });
115
+ const existingPowerHigh = await adapter.getStateAsync('pump.learning.normal_range_power_high');
116
+ if (existingPowerHigh === null || existingPowerHigh.val === null || existingPowerHigh.val === undefined) {
117
+ await adapter.setStateAsync('pump.learning.normal_range_power_high', { val: 0, ack: true });
118
+ }
107
119
 
108
120
  // ------------------------------------------------------
109
121
  // Normalbereich Durchfluss – Untere / Obere Grenze
@@ -122,7 +134,10 @@ async function createPumpStates3(adapter) {
122
134
  },
123
135
  native: {},
124
136
  });
125
- await adapter.setStateAsync('pump.learning.normal_range_flow_low', { val: 0, ack: true });
137
+ const existingFlowLow = await adapter.getStateAsync('pump.learning.normal_range_flow_low');
138
+ if (existingFlowLow === null || existingFlowLow.val === null || existingFlowLow.val === undefined) {
139
+ await adapter.setStateAsync('pump.learning.normal_range_flow_low', { val: 0, ack: true });
140
+ }
126
141
 
127
142
  await adapter.setObjectNotExistsAsync('pump.learning.normal_range_flow_high', {
128
143
  type: 'state',
@@ -138,7 +153,10 @@ async function createPumpStates3(adapter) {
138
153
  },
139
154
  native: {},
140
155
  });
141
- await adapter.setStateAsync('pump.learning.normal_range_flow_high', { val: 0, ack: true });
156
+ const existingFlowHigh = await adapter.getStateAsync('pump.learning.normal_range_flow_high');
157
+ if (existingFlowHigh === null || existingFlowHigh.val === null || existingFlowHigh.val === undefined) {
158
+ await adapter.setStateAsync('pump.learning.normal_range_flow_high', { val: 0, ack: true });
159
+ }
142
160
 
143
161
  // ------------------------------------------------------
144
162
  // Abweichungen (Prozent)
@@ -157,7 +175,10 @@ async function createPumpStates3(adapter) {
157
175
  },
158
176
  native: {},
159
177
  });
160
- await adapter.setStateAsync('pump.learning.deviation_power_percent', { val: 0, ack: true });
178
+ const existingDevPower = await adapter.getStateAsync('pump.learning.deviation_power_percent');
179
+ if (existingDevPower === null || existingDevPower.val === null || existingDevPower.val === undefined) {
180
+ await adapter.setStateAsync('pump.learning.deviation_power_percent', { val: 0, ack: true });
181
+ }
161
182
 
162
183
  await adapter.setObjectNotExistsAsync('pump.learning.deviation_flow_percent', {
163
184
  type: 'state',
@@ -173,7 +194,32 @@ async function createPumpStates3(adapter) {
173
194
  },
174
195
  native: {},
175
196
  });
176
- await adapter.setStateAsync('pump.learning.deviation_flow_percent', { val: 0, ack: true });
197
+ const existingDevFlow = await adapter.getStateAsync('pump.learning.deviation_flow_percent');
198
+ if (existingDevFlow === null || existingDevFlow.val === null || existingDevFlow.val === undefined) {
199
+ await adapter.setStateAsync('pump.learning.deviation_flow_percent', { val: 0, ack: true });
200
+ }
201
+
202
+ // ------------------------------------------------------
203
+ // Toleranzbereich für Normalbereichserkennung (%)
204
+ // ------------------------------------------------------
205
+ await adapter.setObjectNotExistsAsync('pump.learning.tolerance_percent', {
206
+ type: 'state',
207
+ common: {
208
+ name: 'Toleranzbereich für Normalbereichserkennung (%)',
209
+ desc: 'Abweichung, die noch als normal gilt, bevor eine Warnung ausgelöst wird',
210
+ type: 'number',
211
+ role: 'value.percent',
212
+ unit: '%',
213
+ read: true,
214
+ write: true,
215
+ persist: true,
216
+ },
217
+ native: {},
218
+ });
219
+ const existingTolerance = await adapter.getStateAsync('pump.learning.tolerance_percent');
220
+ if (existingTolerance === null || existingTolerance.val === null || existingTolerance.val === undefined) {
221
+ await adapter.setStateAsync('pump.learning.tolerance_percent', { val: 20, ack: true });
222
+ }
177
223
 
178
224
  // ------------------------------------------------------
179
225
  // Textbewertung (Status)
@@ -191,7 +237,10 @@ async function createPumpStates3(adapter) {
191
237
  },
192
238
  native: {},
193
239
  });
194
- await adapter.setStateAsync('pump.learning.status_text', { val: '', ack: true });
240
+ const existingStatus = await adapter.getStateAsync('pump.learning.status_text');
241
+ if (existingStatus === null || existingStatus.val === null || existingStatus.val === undefined) {
242
+ await adapter.setStateAsync('pump.learning.status_text', { val: '', ack: true });
243
+ }
195
244
 
196
245
  // ------------------------------------------------------
197
246
  // Anzahl Lernzyklen
@@ -209,7 +258,10 @@ async function createPumpStates3(adapter) {
209
258
  },
210
259
  native: {},
211
260
  });
212
- await adapter.setStateAsync('pump.learning.learning_cycles_total', { val: 0, ack: true });
261
+ const existingCycles = await adapter.getStateAsync('pump.learning.learning_cycles_total');
262
+ if (existingCycles === null || existingCycles.val === null || existingCycles.val === undefined) {
263
+ await adapter.setStateAsync('pump.learning.learning_cycles_total', { val: 0, ack: true });
264
+ }
213
265
 
214
266
  // ------------------------------------------------------
215
267
  // Log-Eintrag
@@ -36,7 +36,10 @@ async function createRuntimeStates(adapter) {
36
36
  },
37
37
  native: {},
38
38
  });
39
- await adapter.setStateAsync('runtime.total', { val: '0h 0m 0s', ack: true });
39
+ const existingTotal = await adapter.getStateAsync('runtime.total');
40
+ if (!existingTotal || existingTotal.val === null || existingTotal.val === undefined) {
41
+ await adapter.setStateAsync('runtime.total', { val: '0h 0m 0s', ack: true }); // FIX: Nur setzen, wenn leer
42
+ }
40
43
 
41
44
  // Tageslaufzeit (formatiert)
42
45
  await adapter.setObjectNotExistsAsync('runtime.today', {
@@ -51,7 +54,10 @@ async function createRuntimeStates(adapter) {
51
54
  },
52
55
  native: {},
53
56
  });
54
- await adapter.setStateAsync('runtime.today', { val: '0h 0m 0s', ack: true });
57
+ const existingToday = await adapter.getStateAsync('runtime.today');
58
+ if (!existingToday || existingToday.val === null || existingToday.val === undefined) {
59
+ await adapter.setStateAsync('runtime.today', { val: '0h 0m 0s', ack: true }); // FIX
60
+ }
55
61
 
56
62
  // -------------------------------------------------------------------------
57
63
  // NEU: Pumpenstarts heute
@@ -67,7 +73,10 @@ async function createRuntimeStates(adapter) {
67
73
  },
68
74
  native: {},
69
75
  });
70
- await adapter.setStateAsync('runtime.start_count_today', { val: 0, ack: true });
76
+ const existingStartCount = await adapter.getStateAsync('runtime.start_count_today');
77
+ if (!existingStartCount || existingStartCount.val === null || existingStartCount.val === undefined) {
78
+ await adapter.setStateAsync('runtime.start_count_today', { val: 0, ack: true }); // FIX
79
+ }
71
80
 
72
81
  // NEU: Aktuelle Laufzeit (seit Einschalten)
73
82
  await adapter.setObjectNotExistsAsync('runtime.current_session', {
@@ -82,7 +91,10 @@ async function createRuntimeStates(adapter) {
82
91
  },
83
92
  native: {},
84
93
  });
85
- await adapter.setStateAsync('runtime.current_session', { val: '0h 0m 0s', ack: true });
94
+ const existingCurrent = await adapter.getStateAsync('runtime.current_session');
95
+ if (!existingCurrent || existingCurrent.val === null || existingCurrent.val === undefined) {
96
+ await adapter.setStateAsync('runtime.current_session', { val: '0h 0m 0s', ack: true }); // FIX
97
+ }
86
98
 
87
99
  // NEU: Gesamtlaufzeit der aktuellen Saison (formatiert)
88
100
  await adapter.setObjectNotExistsAsync('runtime.season_total', {
@@ -97,7 +109,10 @@ async function createRuntimeStates(adapter) {
97
109
  },
98
110
  native: {},
99
111
  });
100
- await adapter.setStateAsync('runtime.season_total', { val: '0h 0m 0s', ack: true });
112
+ const existingSeason = await adapter.getStateAsync('runtime.season_total');
113
+ if (!existingSeason || existingSeason.val === null || existingSeason.val === undefined) {
114
+ await adapter.setStateAsync('runtime.season_total', { val: '0h 0m 0s', ack: true }); // FIX
115
+ }
101
116
 
102
117
  // -------------------------------------------------------------------------
103
118
  // --- Kanal circulation ---
@@ -0,0 +1,138 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * statisticsStates.js
5
+ * -------------------
6
+ * Erstellt alle States für die Tagesstatistik der Temperatursensoren.
7
+ * Struktur: analytics.statistics.temperature.today.*
8
+ *
9
+ * - Sechs Sensorbereiche (outside, ground, surface, flow, return, collector)
10
+ * - Je Sensor: Min/Max/Avg + Zeitstempel + JSON/HTML-Ausgabe
11
+ * - Zusätzlich: Gesamt-Ausgabe (summary_all_json / summary_all_html)
12
+ *
13
+ * Alle States sind persistiert, schreibgeschützt und überinstallationssicher.
14
+ */
15
+
16
+ /**
17
+ * @param {ioBroker.Adapter} adapter - Instanz des ioBroker-Adapters
18
+ */
19
+ async function createStatisticsStates(adapter) {
20
+ adapter.log.debug('statisticsStates: Initialisierung der Tagesstatistik (Temperatur) gestartet.');
21
+
22
+ // Oberstruktur
23
+ await adapter.setObjectNotExistsAsync('analytics', {
24
+ type: 'channel',
25
+ common: { name: 'Analysen & Auswertungen (Statistik, Historie, Berichte)' },
26
+ native: {},
27
+ });
28
+
29
+ await adapter.setObjectNotExistsAsync('analytics.statistics', {
30
+ type: 'channel',
31
+ common: { name: 'Statistische Auswertungen' },
32
+ native: {},
33
+ });
34
+
35
+ await adapter.setObjectNotExistsAsync('analytics.statistics.temperature', {
36
+ type: 'channel',
37
+ common: { name: 'Temperaturstatistik' },
38
+ native: {},
39
+ });
40
+
41
+ await adapter.setObjectNotExistsAsync('analytics.statistics.temperature.today', {
42
+ type: 'channel',
43
+ common: { name: 'Tagesstatistik (Temperaturen)' },
44
+ native: {},
45
+ });
46
+
47
+ // Definierte Sensoren
48
+ const sensors = [
49
+ { id: 'outside', name: 'Außentemperatur' },
50
+ { id: 'ground', name: 'Bodentemperatur' },
51
+ { id: 'surface', name: 'Pooloberfläche' },
52
+ { id: 'flow', name: 'Vorlauf' },
53
+ { id: 'return', name: 'Rücklauf' },
54
+ { id: 'collector', name: 'Kollektor (Solar)' },
55
+ ];
56
+
57
+ for (const sensor of sensors) {
58
+ const basePath = `analytics.statistics.temperature.today.${sensor.id}`;
59
+
60
+ await adapter.setObjectNotExistsAsync(basePath, {
61
+ type: 'channel',
62
+ common: { name: `${sensor.name} (Tagesstatistik)` },
63
+ native: {},
64
+ });
65
+
66
+ const stateDefs = [
67
+ { id: 'temp_min', name: 'Niedrigste Temperatur', type: 'number', role: 'value.temperature', unit: '°C' },
68
+ { id: 'temp_max', name: 'Höchste Temperatur', type: 'number', role: 'value.temperature', unit: '°C' },
69
+ { id: 'temp_min_time', name: 'Zeitpunkt Minimum', type: 'string', role: 'value.time' },
70
+ { id: 'temp_max_time', name: 'Zeitpunkt Maximum', type: 'string', role: 'value.time' },
71
+ { id: 'temp_avg', name: 'Durchschnittstemperatur', type: 'number', role: 'value.temperature', unit: '°C' },
72
+ { id: 'data_points_count', name: 'Anzahl Messwerte', type: 'number', role: 'value' },
73
+ { id: 'last_update', name: 'Letzte Aktualisierung', type: 'string', role: 'value.time' },
74
+ { id: 'summary_json', name: 'Tageszusammenfassung (JSON)', type: 'string', role: 'json' },
75
+ { id: 'summary_html', name: 'Tageszusammenfassung (HTML)', type: 'string', role: 'html' },
76
+ ];
77
+
78
+ for (const def of stateDefs) {
79
+ await adapter.setObjectNotExistsAsync(`${basePath}.${def.id}`, {
80
+ type: 'state',
81
+ common: {
82
+ name: def.name,
83
+ type: def.type,
84
+ role: def.role,
85
+ unit: def.unit || undefined,
86
+ read: true,
87
+ write: false,
88
+ def: def.type === 'number' ? null : '',
89
+ persist: true,
90
+ },
91
+ native: {},
92
+ });
93
+ }
94
+ }
95
+
96
+ // Gesamt-Ausgabe (Outputs)
97
+ const outputBase = 'analytics.statistics.temperature.today.outputs';
98
+ await adapter.setObjectNotExistsAsync(outputBase, {
99
+ type: 'channel',
100
+ common: { name: 'Gesamtausgaben (alle Sensoren)' },
101
+ native: {},
102
+ });
103
+
104
+ const outputs = [
105
+ {
106
+ id: 'summary_all_json',
107
+ name: 'Gesamtzusammenfassung aller Sensoren (JSON)',
108
+ role: 'json',
109
+ },
110
+ {
111
+ id: 'summary_all_html',
112
+ name: 'Gesamtzusammenfassung aller Sensoren (HTML)',
113
+ role: 'html',
114
+ },
115
+ ];
116
+
117
+ for (const out of outputs) {
118
+ await adapter.setObjectNotExistsAsync(`${outputBase}.${out.id}`, {
119
+ type: 'state',
120
+ common: {
121
+ name: out.name,
122
+ type: 'string',
123
+ role: out.role,
124
+ read: true,
125
+ write: false,
126
+ def: '',
127
+ persist: true,
128
+ },
129
+ native: {},
130
+ });
131
+ }
132
+
133
+ adapter.log.debug('statisticsStates: Tagesstatistik (Temperatur) erfolgreich angelegt.');
134
+ }
135
+
136
+ module.exports = {
137
+ createStatisticsStates,
138
+ };
package/main.js CHANGED
@@ -8,6 +8,7 @@ const utils = require('@iobroker/adapter-core');
8
8
  const temperatureHelper = require('./lib/helpers/temperatureHelper');
9
9
  const timeHelper = require('./lib/helpers/timeHelper');
10
10
  const runtimeHelper = require('./lib/helpers/runtimeHelper');
11
+ const statisticsHelper = require('./lib/helpers/statisticsHelper');
11
12
  const pumpHelper = require('./lib/helpers/pumpHelper');
12
13
  const pumpHelper2 = require('./lib/helpers/pumpHelper2');
13
14
  const pumpHelper3 = require('./lib/helpers/pumpHelper3');
@@ -29,6 +30,7 @@ const { createSolarStates } = require('./lib/stateDefinitions/solarStates');
29
30
  const { createGeneralStates } = require('./lib/stateDefinitions/generalStates');
30
31
  const { createTimeStates } = require('./lib/stateDefinitions/timeStates');
31
32
  const { createRuntimeStates } = require('./lib/stateDefinitions/runtimeStates');
33
+ const { createStatisticsStates } = require('./lib/stateDefinitions/statisticsStates');
32
34
  const { createSpeechStates } = require('./lib/stateDefinitions/speechStates');
33
35
  const { createConsumptionStates } = require('./lib/stateDefinitions/consumptionStates');
34
36
  const { createStatusStates } = require('./lib/stateDefinitions/statusStates');
@@ -69,6 +71,9 @@ class Poolcontrol extends utils.Adapter {
69
71
  // --- Laufzeitsteuerung ---
70
72
  await createRuntimeStates(this);
71
73
 
74
+ // Statistik-States (Temperaturen)
75
+ await createStatisticsStates(this);
76
+
72
77
  // --- Sprachausgaben ---
73
78
  await createSpeechStates(this);
74
79
 
@@ -87,7 +92,7 @@ class Poolcontrol extends utils.Adapter {
87
92
  // --- Control States ---
88
93
  await createControlStates(this);
89
94
 
90
- // --- DebugLog Staets ---
95
+ // --- DebugLog States ---
91
96
  await createDebugLogStates(this);
92
97
 
93
98
  // --- Migration Helper zuletzt starten ---
@@ -97,6 +102,7 @@ class Poolcontrol extends utils.Adapter {
97
102
  temperatureHelper.init(this);
98
103
  timeHelper.init(this);
99
104
  runtimeHelper.init(this);
105
+ statisticsHelper.init(this);
100
106
  pumpHelper.init(this);
101
107
  pumpHelper2.init(this);
102
108
  pumpHelper3.init(this);
@@ -122,6 +128,9 @@ class Poolcontrol extends utils.Adapter {
122
128
  if (runtimeHelper.cleanup) {
123
129
  runtimeHelper.cleanup();
124
130
  }
131
+ if (statisticsHelper.cleanup) {
132
+ statisticsHelper.cleanup();
133
+ }
125
134
  if (pumpHelper.cleanup) {
126
135
  pumpHelper.cleanup();
127
136
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.poolcontrol",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Steuerung & Automatisierung für den Pool (Pumpe, Heizung, Ventile, Sensoren).",
5
5
  "author": "DasBo1975 <dasbo1975@outlook.de>",
6
6
  "homepage": "https://github.com/DasBo1975/ioBroker.poolcontrol",