iobroker.pv-notifications 1.0.98 → 1.0.99

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/README.md CHANGED
@@ -339,13 +339,15 @@ sadam6752@gmail.com
339
339
  ### **WORK IN PROGRESS**
340
340
  -->
341
341
 
342
- ### 1.0.98 (2026-03-01)
342
+ ### 1.0.99 (2026-03-01)
343
343
 
344
- * (FIX) Weekly/monthly stats now read directly from external states using getForeignStateAsync (not from internal states)
344
+ * (FIX) Weekly stats auto-saved every Sunday at 23:55 (before sourceanalytix reset at 00:00)
345
+ * (FIX) Monthly stats auto-saved on last day of month at 23:55 (before sourceanalytix reset at 00:00)
346
+ * (ADD) User can freely configure send time for weekly/monthly stats via statsWeekDay, statsWeekTime, monthlyStatsDay, monthlyStatsTime
345
347
 
346
- ### 1.0.97 (2026-03-01)
348
+ ### 1.0.98 (2026-03-01)
347
349
 
348
- * (FIX) Weekly/monthly statistics now read from internal states (statistics.currentTotalProduction, etc.) instead of external config
350
+ * (FIX) Weekly/monthly stats now read directly from external states using getForeignStateAsync (not from internal states)
349
351
 
350
352
  ### 1.0.93 (2026-02-27)
351
353
 
package/io-package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "pv-notifications",
4
- "version": "1.0.98",
4
+ "version": "1.0.99",
5
5
  "titleLang": {
6
6
  "en": "PV Notifications",
7
7
  "de": "PV-Benachrichtigungen",
package/main.js CHANGED
@@ -1266,18 +1266,20 @@ ${statusText}`;
1266
1266
  }
1267
1267
 
1268
1268
  /**
1269
- * Reset weekly statistics
1269
+ * Reset weekly statistics - AUTOMATISCH am Sonntag um 23:55 (vor sourceanalytix Reset)
1270
1270
  */
1271
1271
  async resetWeeklyStats() {
1272
- const jsDay = new Date().getDay(); // JavaScript: 0=So, 1=Mo, ..., 6=Sa
1273
- // Umwandeln in ioBroker-Format: 0=Mo, 1=Di, ..., 6=So
1274
- const today = jsDay === 0 ? 6 : jsDay - 1;
1272
+ const now = new Date();
1273
+ const jsDay = now.getDay(); // JavaScript: 0=So, 1=Mo, ..., 6=Sa
1274
+ const hours = now.getHours();
1275
+ const minutes = now.getMinutes();
1275
1276
 
1276
- if (today === this.config.statsWeekDay && today !== this.stats.lastWeekReset) {
1277
- this.log.info('Resetting weekly statistics');
1277
+ // Automatische Speicherung: Jeden Sonntag um 23:55 (vor Mitternacht)
1278
+ // JavaScript: 0 = Sonntag → genau das wollen wir!
1279
+ if (jsDay === 0 && hours === 23 && minutes === 55) {
1280
+ this.log.info('Auto-saving weekly statistics (Sunday 23:55, before sourceanalytix reset)');
1278
1281
 
1279
- // Aktuelle Daten aus internen States lesen (aktualisiert in Echtzeit)
1280
- // Fallback: Wenn interne States leer, direkt aus externen States lesen
1282
+ // Aktuelle Daten aus externen States lesen (direkter Zugriff)
1281
1283
  const totalProd = await this.getForeignStateAsync(this.config.totalProduction);
1282
1284
  const consumption = await this.getForeignStateAsync(this.config.consumption);
1283
1285
  const feedIn = await this.getForeignStateAsync(this.config.feedIn);
@@ -1293,32 +1295,33 @@ ${statusText}`;
1293
1295
  // Wöchentliche Statistik zurücksetzen
1294
1296
  this.stats.weekFullCycles = 0;
1295
1297
  this.stats.weekEmptyCycles = 0;
1296
- this.stats.lastWeekReset = today;
1297
1298
 
1298
1299
  this.saveStatistics();
1299
- this.log.info(`Weekly stats saved: Production=${this.stats.lastWeekProduction} kWh`);
1300
+ this.log.info(`Weekly stats saved: Production=${this.stats.lastWeekProduction} kWh, FeedIn=${this.stats.lastWeekFeedIn} kWh`);
1300
1301
  // KEIN Senden hier - Senden erfolgt nur in startScheduledTasks() zur konfigurierten Zeit
1301
1302
  }
1302
1303
  }
1303
1304
 
1304
1305
  /**
1305
- * Monatsstatistik zurücksetzen
1306
+ * Monatsstatistik zurücksetzen - AUTOMATISCH am letzten Tag des Monats um 23:55 (vor sourceanalytix Reset)
1306
1307
  */
1307
1308
  async resetMonthlyStats() {
1308
1309
  if (!this.config.monthlyStatsEnabled) {
1309
1310
  return;
1310
1311
  }
1311
1312
 
1312
- const today = new Date().getDate();
1313
1313
  const now = new Date();
1314
+ const today = now.getDate();
1314
1315
  const hours = now.getHours();
1315
1316
  const minutes = now.getMinutes();
1316
- const [statHours, statMinutes] = this.config.monthlyStatsTime.split(':').map(Number);
1317
1317
 
1318
- // Daten am konfigurierten Tag zur konfigurierten Zeit speichern (nicht vorher)
1319
- if (today === this.config.monthlyStatsDay && this.stats.lastMonthReset !== today &&
1320
- (hours > statHours || (hours === statHours && minutes >= statMinutes))) {
1321
- this.log.info('Resetting monthly statistics');
1318
+ // Letzten Tag des aktuellen Monats berechnen
1319
+ // new Date(Jahr, Monat+1, 0) gibt den letzten Tag des aktuellen Monats zurück
1320
+ const lastDayOfMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0).getDate();
1321
+
1322
+ // Automatische Speicherung: Letzter Tag des Monats um 23:55 (vor Mitternacht)
1323
+ if (today === lastDayOfMonth && hours === 23 && minutes === 55) {
1324
+ this.log.info(`Auto-saving monthly statistics (last day of month ${today}. ${now.getMonth()+1}.${now.getFullYear()} 23:55, before sourceanalytix reset)`);
1322
1325
 
1323
1326
  // Aktuelle Daten aus externen States lesen (direkter Zugriff)
1324
1327
  const totalProd = await this.getForeignStateAsync(this.config.monthlyProduction);
@@ -1335,7 +1338,7 @@ ${statusText}`;
1335
1338
 
1336
1339
  this.stats.lastMonthReset = today;
1337
1340
  this.saveStatistics();
1338
- this.log.info(`Monthly stats saved: Production=${this.stats.lastMonthProduction} kWh`);
1341
+ this.log.info(`Monthly stats saved: Production=${this.stats.lastMonthProduction} kWh, FeedIn=${this.stats.lastMonthFeedIn} kWh`);
1339
1342
  }
1340
1343
  }
1341
1344
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.pv-notifications",
3
- "version": "1.0.98",
3
+ "version": "1.0.99",
4
4
  "description": "PV-Anlage Batterie-Status Telegram Benachrichtigungen",
5
5
  "author": {
6
6
  "name": "Alex1808 via LLM: Qwen",