diff --git a/Energy Counter Child/form.json b/Energy Counter Child/form.json index d5e5f44..d39b6da 100644 --- a/Energy Counter Child/form.json +++ b/Energy Counter Child/form.json @@ -38,6 +38,16 @@ "type": "CheckBox", "name": "ShowMonthCost", "caption": "Show monthly cost" + }, + { + "type": "CheckBox", + "name": "ShowYearEnergy", + "caption": "Show yearly energy" + }, + { + "type": "CheckBox", + "name": "ShowYearCost", + "caption": "Show yearly cost" } ] } diff --git a/Energy Counter Child/locale.json b/Energy Counter Child/locale.json index 04e977a..827204e 100644 --- a/Energy Counter Child/locale.json +++ b/Energy Counter Child/locale.json @@ -11,12 +11,16 @@ "Show daily cost": "Tageskosten anzeigen", "Show monthly energy": "Monatsenergie anzeigen", "Show monthly cost": "Monatskosten anzeigen", + "Show yearly energy": "Jahresenergie anzeigen", + "Show yearly cost": "Jahreskosten anzeigen", "Total Energy": "Gesamtenergie", "Total Cost": "Gesamtkosten", "Daily Energy": "Tagesenergie", "Daily Cost": "Tageskosten", "Monthly Energy": "Monatsenergie", - "Monthly Cost": "Monatskosten" + "Monthly Cost": "Monatskosten", + "Yearly Energy": "Jahresenergie", + "Yearly Cost": "Jahreskosten" } } } diff --git a/Energy Counter Child/module.php b/Energy Counter Child/module.php index 30fabd4..57cbff5 100644 --- a/Energy Counter Child/module.php +++ b/Energy Counter Child/module.php @@ -21,6 +21,8 @@ class EnergyCounterChild extends IPSModule $this->RegisterPropertyBoolean('ShowDayCost', true); $this->RegisterPropertyBoolean('ShowMonthEnergy', true); $this->RegisterPropertyBoolean('ShowMonthCost', true); + $this->RegisterPropertyBoolean('ShowYearEnergy', true); + $this->RegisterPropertyBoolean('ShowYearCost', true); $this->EnsureProfiles(); $this->RegisterValueVariables(); @@ -63,6 +65,8 @@ class EnergyCounterChild extends IPSModule $this->RegisterVariableFloat('DayCost', $this->Translate('Daily Cost'), self::COST_PROFILE, 40); $this->RegisterVariableFloat('MonthEnergy', $this->Translate('Monthly Energy'), self::ENERGY_PROFILE, 50); $this->RegisterVariableFloat('MonthCost', $this->Translate('Monthly Cost'), self::COST_PROFILE, 60); + $this->RegisterVariableFloat('YearEnergy', $this->Translate('Yearly Energy'), self::ENERGY_PROFILE, 70); + $this->RegisterVariableFloat('YearCost', $this->Translate('Yearly Cost'), self::COST_PROFILE, 80); } private function ApplyVisibility() @@ -73,7 +77,9 @@ class EnergyCounterChild extends IPSModule 'DayEnergy' => $this->ReadPropertyBoolean('ShowDayEnergy'), 'DayCost' => $this->ReadPropertyBoolean('ShowDayCost'), 'MonthEnergy' => $this->ReadPropertyBoolean('ShowMonthEnergy'), - 'MonthCost' => $this->ReadPropertyBoolean('ShowMonthCost') + 'MonthCost' => $this->ReadPropertyBoolean('ShowMonthCost'), + 'YearEnergy' => $this->ReadPropertyBoolean('ShowYearEnergy'), + 'YearCost' => $this->ReadPropertyBoolean('ShowYearCost') ]; foreach ($visibility as $ident => $visible) { diff --git a/Energy Counter Main/form.json b/Energy Counter Main/form.json index 7ce9e57..e7cbb84 100644 --- a/Energy Counter Main/form.json +++ b/Energy Counter Main/form.json @@ -89,6 +89,11 @@ "type": "Button", "caption": "Reset monthly values", "onClick": "ECM_ResetMonthEnergy($id);" + }, + { + "type": "Button", + "caption": "Reset yearly values", + "onClick": "ECM_ResetYearEnergy($id);" } ], "status": [ diff --git a/Energy Counter Main/locale.json b/Energy Counter Main/locale.json index 4a303c0..9fdbc31 100644 --- a/Energy Counter Main/locale.json +++ b/Energy Counter Main/locale.json @@ -16,6 +16,7 @@ "Reset total values": "Gesamtwerte zurücksetzen", "Reset daily values": "Tageswerte zurücksetzen", "Reset monthly values": "Monatswerte zurücksetzen", + "Reset yearly values": "Jahreswerte zurücksetzen", "Active": "Aktiv", "Category missing or invalid": "Kategorie fehlt oder ist ungültig" } diff --git a/Energy Counter Main/module.php b/Energy Counter Main/module.php index cb4bddb..0b73ac7 100644 --- a/Energy Counter Main/module.php +++ b/Energy Counter Main/module.php @@ -109,6 +109,7 @@ class EnergyCounterMain extends IPSModule $children = $this->ReadJsonAttribute('CounterChildren', []); $today = date('Y-m-d'); $month = date('Y-m'); + $year = date('Y'); foreach ($this->GetCounters() as $counter) { $key = $counter['Key']; @@ -124,7 +125,7 @@ class EnergyCounterMain extends IPSModule continue; } - $state = $this->NormalizeState($states[$key] ?? [], $today, $month); + $state = $this->NormalizeState($states[$key] ?? [], $today, $month, $year); $currentValue = (float) $sourceValue; // Die erste Messung setzt nur die Referenz. Dadurch wird kein bereits @@ -138,6 +139,7 @@ class EnergyCounterMain extends IPSModule $state['totalEnergy'] += $delta; $state['dayEnergy'] += $delta; $state['monthEnergy'] += $delta; + $state['yearEnergy'] += $delta; } else { // Ein zurückgesetzter/überlaufener Hardwarezähler darf den // bereits berechneten Verbrauch nicht negativ verändern. @@ -177,6 +179,12 @@ class EnergyCounterMain extends IPSModule $this->ResetEnergy('monthEnergy'); } + /** Setzt ausschließlich die im Hauptmodul berechneten Jahreswerte zurück. */ + public function ResetYearEnergy() + { + $this->ResetEnergy('yearEnergy'); + } + /** * Übernimmt den aktuellen Rohzählerstand als Gesamtenergie eines einzelnen * Counters. Diese Methode wird über den Initialisierungsbutton des Childs @@ -211,7 +219,7 @@ class EnergyCounterMain extends IPSModule } $states = $this->ReadJsonAttribute('CounterState', []); - $state = $this->NormalizeState($states[$counterKey] ?? [], date('Y-m-d'), date('Y-m')); + $state = $this->NormalizeState($states[$counterKey] ?? [], date('Y-m-d'), date('Y-m'), date('Y')); $currentValue = (float) $sourceValue; $state['initialized'] = true; $state['lastRaw'] = $currentValue; @@ -245,7 +253,7 @@ class EnergyCounterMain extends IPSModule $children = $this->ReadJsonAttribute('CounterChildren', []); foreach ($this->GetCounters() as $counter) { $key = $counter['Key']; - $state = $this->NormalizeState($states[$key] ?? [], date('Y-m-d'), date('Y-m')); + $state = $this->NormalizeState($states[$key] ?? [], date('Y-m-d'), date('Y-m'), date('Y')); $state[$field] = 0.0; $states[$key] = $state; @@ -328,7 +336,7 @@ class EnergyCounterMain extends IPSModule return $counters; } - private function NormalizeState(array $state, string $today, string $month): array + private function NormalizeState(array $state, string $today, string $month, string $year): array { $normalized = [ 'initialized' => (bool) ($state['initialized'] ?? false), @@ -336,8 +344,10 @@ class EnergyCounterMain extends IPSModule 'totalEnergy' => max(0.0, (float) ($state['totalEnergy'] ?? 0)), 'dayEnergy' => max(0.0, (float) ($state['dayEnergy'] ?? 0)), 'monthEnergy' => max(0.0, (float) ($state['monthEnergy'] ?? 0)), + 'yearEnergy' => max(0.0, (float) ($state['yearEnergy'] ?? 0)), 'dayStamp' => (string) ($state['dayStamp'] ?? $today), - 'monthStamp' => (string) ($state['monthStamp'] ?? $month) + 'monthStamp' => (string) ($state['monthStamp'] ?? $month), + 'yearStamp' => (string) ($state['yearStamp'] ?? $year) ]; if ($normalized['dayStamp'] !== $today) { @@ -348,6 +358,10 @@ class EnergyCounterMain extends IPSModule $normalized['monthEnergy'] = 0.0; $normalized['monthStamp'] = $month; } + if ($normalized['yearStamp'] !== $year) { + $normalized['yearEnergy'] = 0.0; + $normalized['yearStamp'] = $year; + } return $normalized; } @@ -360,7 +374,9 @@ class EnergyCounterMain extends IPSModule 'DayEnergy' => $state['dayEnergy'], 'DayCost' => $state['dayEnergy'] * $pricePerKWh, 'MonthEnergy' => $state['monthEnergy'], - 'MonthCost' => $state['monthEnergy'] * $pricePerKWh + 'MonthCost' => $state['monthEnergy'] * $pricePerKWh, + 'YearEnergy' => $state['yearEnergy'], + 'YearCost' => $state['yearEnergy'] * $pricePerKWh ]; foreach ($values as $ident => $value) { diff --git a/README.md b/README.md index 55b977b..d9eb4ac 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ Die Bibliothek enthält zwei Symcon-Module: -- **EnergyCounterMain**: Konfiguration aller Zähler, Ermittlung von Energie und Kosten, automatische Tages-/Monatsresets sowie manuelle Resets. -- **EnergyCounterChild**: Wird vom Hauptmodul unter der gewählten Kategorie angelegt. Sein Formular steuert ausschließlich, welche der sechs berechneten Variablen sichtbar sind. +- **EnergyCounterMain**: Konfiguration aller Zähler, Ermittlung von Energie und Kosten, automatische Tages-/Monats-/Jahresresets sowie manuelle Resets. +- **EnergyCounterChild**: Wird vom Hauptmodul unter der gewählten Kategorie angelegt. Sein Formular steuert ausschließlich, welche der acht berechneten Variablen sichtbar sind. ## Einrichtung diff --git a/library.json b/library.json index 092dd93..ffa5782 100644 --- a/library.json +++ b/library.json @@ -7,7 +7,7 @@ "version": "6.0", "date": 1491343200 }, - "version": "1.2", - "build": 3, + "version": "1.3", + "build": 4, "date": 0 }