commit faa518ccd8122f5507226c965096c8a7b184bde4 Author: jhartworks Date: Wed Oct 21 13:12:13 2026 +0200 initial commit diff --git a/Energy Counter Child/form.json b/Energy Counter Child/form.json new file mode 100644 index 0000000..9c90e10 --- /dev/null +++ b/Energy Counter Child/form.json @@ -0,0 +1,47 @@ +{ + "elements": [ + { + "type": "Label", + "caption": "Values are calculated and reset only by the associated main module. This form controls visibility only; hidden values remain available in the background." + }, + { + "type": "ExpansionPanel", + "caption": "Display variables", + "expanded": true, + "items": [ + { + "type": "CheckBox", + "name": "ShowTotalEnergy", + "caption": "Show total energy" + }, + { + "type": "CheckBox", + "name": "ShowTotalCost", + "caption": "Show total cost" + }, + { + "type": "CheckBox", + "name": "ShowDayEnergy", + "caption": "Show daily energy" + }, + { + "type": "CheckBox", + "name": "ShowDayCost", + "caption": "Show daily cost" + }, + { + "type": "CheckBox", + "name": "ShowMonthEnergy", + "caption": "Show monthly energy" + }, + { + "type": "CheckBox", + "name": "ShowMonthCost", + "caption": "Show monthly cost" + } + ] + } + ], + "actions": [], + "status": [] +} diff --git a/Energy Counter Child/locale.json b/Energy Counter Child/locale.json new file mode 100644 index 0000000..72e3332 --- /dev/null +++ b/Energy Counter Child/locale.json @@ -0,0 +1,21 @@ +{ + "translations": { + "de": { + "Energy Counter Display": "Energiezähler Anzeige", + "Values are calculated and reset only by the associated main module. This form controls visibility only; hidden values remain available in the background.": "Die Werte werden ausschließlich durch das zugehörige Hauptmodul berechnet und zurückgesetzt. Hier wird nur ihre Sichtbarkeit gesteuert; ausgeblendete Werte bleiben im Hintergrund vorhanden.", + "Display variables": "Anzuzeigende Variablen", + "Show total energy": "Gesamtenergie anzeigen", + "Show total cost": "Gesamtkosten anzeigen", + "Show daily energy": "Tagesenergie anzeigen", + "Show daily cost": "Tageskosten anzeigen", + "Show monthly energy": "Monatsenergie anzeigen", + "Show monthly cost": "Monatskosten anzeigen", + "Total Energy": "Gesamtenergie", + "Total Cost": "Gesamtkosten", + "Daily Energy": "Tagesenergie", + "Daily Cost": "Tageskosten", + "Monthly Energy": "Monatsenergie", + "Monthly Cost": "Monatskosten" + } + } +} diff --git a/Energy Counter Child/module.json b/Energy Counter Child/module.json new file mode 100644 index 0000000..73f748f --- /dev/null +++ b/Energy Counter Child/module.json @@ -0,0 +1,14 @@ +{ + "id": "{C96F6499-8F3E-4EBF-AF8D-2C45E989D2F6}", + "name": "EnergyCounterChild", + "type": 3, + "vendor": "J.H. Artworks", + "aliases": [ + "Energy Counter Display" + ], + "url": "https://jh-artworks.com", + "parentRequirements": [], + "childRequirements": [], + "implemented": [], + "prefix": "ECC" +} diff --git a/Energy Counter Child/module.php b/Energy Counter Child/module.php new file mode 100644 index 0000000..0f80529 --- /dev/null +++ b/Energy Counter Child/module.php @@ -0,0 +1,81 @@ +RegisterPropertyInteger('ParentInstanceID', 0); + $this->RegisterPropertyString('CounterKey', ''); + + $this->RegisterPropertyBoolean('ShowTotalEnergy', true); + $this->RegisterPropertyBoolean('ShowTotalCost', true); + $this->RegisterPropertyBoolean('ShowDayEnergy', true); + $this->RegisterPropertyBoolean('ShowDayCost', true); + $this->RegisterPropertyBoolean('ShowMonthEnergy', true); + $this->RegisterPropertyBoolean('ShowMonthCost', true); + + $this->EnsureProfiles(); + $this->RegisterValueVariables(); + } + + public function ApplyChanges() + { + parent::ApplyChanges(); + + $this->EnsureProfiles(); + $this->RegisterValueVariables(); + $this->ApplyVisibility(); + $this->SetStatus(102); + } + + private function RegisterValueVariables() + { + $this->RegisterVariableFloat('TotalEnergy', $this->Translate('Total Energy'), self::ENERGY_PROFILE, 10); + $this->RegisterVariableFloat('TotalCost', $this->Translate('Total Cost'), self::COST_PROFILE, 20); + $this->RegisterVariableFloat('DayEnergy', $this->Translate('Daily Energy'), self::ENERGY_PROFILE, 30); + $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); + } + + private function ApplyVisibility() + { + $visibility = [ + 'TotalEnergy' => $this->ReadPropertyBoolean('ShowTotalEnergy'), + 'TotalCost' => $this->ReadPropertyBoolean('ShowTotalCost'), + 'DayEnergy' => $this->ReadPropertyBoolean('ShowDayEnergy'), + 'DayCost' => $this->ReadPropertyBoolean('ShowDayCost'), + 'MonthEnergy' => $this->ReadPropertyBoolean('ShowMonthEnergy'), + 'MonthCost' => $this->ReadPropertyBoolean('ShowMonthCost') + ]; + + foreach ($visibility as $ident => $visible) { + $variableID = $this->GetIDForIdent($ident); + if ($variableID > 0) { + IPS_SetHidden($variableID, !$visible); + } + } + } + + private function EnsureProfiles() + { + if (!IPS_VariableProfileExists(self::ENERGY_PROFILE)) { + IPS_CreateVariableProfile(self::ENERGY_PROFILE, 2); + IPS_SetVariableProfileText(self::ENERGY_PROFILE, '', ' kWh'); + IPS_SetVariableProfileDigits(self::ENERGY_PROFILE, 3); + } + + if (!IPS_VariableProfileExists(self::COST_PROFILE)) { + IPS_CreateVariableProfile(self::COST_PROFILE, 2); + IPS_SetVariableProfileText(self::COST_PROFILE, '', ' €'); + IPS_SetVariableProfileDigits(self::COST_PROFILE, 2); + } + } +} diff --git a/Energy Counter Main/form.json b/Energy Counter Main/form.json new file mode 100644 index 0000000..7ce9e57 --- /dev/null +++ b/Energy Counter Main/form.json @@ -0,0 +1,106 @@ +{ + "elements": [ + { + "type": "SelectCategory", + "name": "TargetCategoryID", + "caption": "Category for counter child instances" + }, + { + "type": "NumberSpinner", + "name": "GlobalPricePerKWh", + "caption": "Global electricity tariff per kWh (€)", + "digits": 4 + }, + { + "type": "List", + "name": "Counters", + "caption": "Counters (meter values must be cumulative kWh values)", + "rowCount": 6, + "add": true, + "delete": true, + "columns": [ + { + "caption": "Counter name", + "name": "CounterName", + "width": "250px", + "add": "New counter", + "edit": { + "type": "ValidationTextBox" + } + }, + { + "caption": "Meter value variable", + "name": "SourceVariableID", + "width": "300px", + "add": 0, + "edit": { + "type": "SelectVariable", + "validVariableTypes": [1, 2] + } + }, + { + "caption": "Use custom tariff", + "name": "UseOwnTariff", + "width": "170px", + "add": false, + "edit": { + "type": "CheckBox" + } + }, + { + "caption": "Custom tariff per kWh (€)", + "name": "PricePerKWh", + "width": "150px", + "add": 0, + "edit": { + "type": "NumberSpinner", + "digits": 4 + } + } + ] + }, + { + "type": "Label", + "caption": "Unless a custom tariff is enabled, the counter uses the global electricity tariff. Meter values are evaluated continuously; daily and monthly values reset automatically. Manual resets affect calculated values only, never the source variable." + } + ], + "actions": [ + { + "type": "Button", + "caption": "Synchronize child instances", + "onClick": "ECM_SynchronizeChildren($id);" + }, + { + "type": "Button", + "caption": "Update values now", + "onClick": "ECM_UpdateValues($id);" + }, + { + "type": "Button", + "caption": "Reset total values", + "onClick": "ECM_ResetTotalEnergy($id);" + }, + { + "type": "Button", + "caption": "Reset daily values", + "onClick": "ECM_ResetDayEnergy($id);" + }, + { + "type": "Button", + "caption": "Reset monthly values", + "onClick": "ECM_ResetMonthEnergy($id);" + } + ], + "status": [ + { + "code": 102, + "icon": "active", + "caption": "Active" + }, + { + "code": 201, + "icon": "error", + "caption": "Category missing or invalid" + } + ] +} diff --git a/Energy Counter Main/locale.json b/Energy Counter Main/locale.json new file mode 100644 index 0000000..4a303c0 --- /dev/null +++ b/Energy Counter Main/locale.json @@ -0,0 +1,23 @@ +{ + "translations": { + "de": { + "Energy Counter Evaluation": "Energiezähler Auswertung", + "Category for counter child instances": "Kategorie für die Zähler-Childinstanzen", + "Global electricity tariff per kWh (€)": "Globaler Stromtarif je kWh (€)", + "Counters (meter values must be cumulative kWh values)": "Zähler (Zählerstände müssen kumulierte kWh-Werte sein)", + "Counter name": "Name des Zählers", + "New counter": "Neuer Zähler", + "Meter value variable": "Zählerstand-Variable", + "Use custom tariff": "Eigener Tarif verwenden", + "Custom tariff per kWh (€)": "Eigener Tarif je kWh (€)", + "Unless a custom tariff is enabled, the counter uses the global electricity tariff. Meter values are evaluated continuously; daily and monthly values reset automatically. Manual resets affect calculated values only, never the source variable.": "Ist kein eigener Tarif aktiviert, verwendet der Zähler den globalen Stromtarif. Der Zählerstand wird fortlaufend ausgewertet; Tages- und Monatswerte werden automatisch zurückgesetzt. Manuelle Resets wirken nur auf die berechneten Werte, nie auf die Quellvariable.", + "Synchronize child instances": "Childinstanzen synchronisieren", + "Update values now": "Werte jetzt aktualisieren", + "Reset total values": "Gesamtwerte zurücksetzen", + "Reset daily values": "Tageswerte zurücksetzen", + "Reset monthly values": "Monatswerte zurücksetzen", + "Active": "Aktiv", + "Category missing or invalid": "Kategorie fehlt oder ist ungültig" + } + } +} diff --git a/Energy Counter Main/module.json b/Energy Counter Main/module.json new file mode 100644 index 0000000..2be4dc1 --- /dev/null +++ b/Energy Counter Main/module.json @@ -0,0 +1,14 @@ +{ + "id": "{3BEE9E77-1A50-4D12-99B8-E3547443882E}", + "name": "EnergyCounterMain", + "type": 3, + "vendor": "J.H. Artworks", + "aliases": [ + "Energy Counter Evaluation" + ], + "url": "https://jh-artworks.com", + "parentRequirements": [], + "childRequirements": [], + "implemented": [], + "prefix": "ECM" +} diff --git a/Energy Counter Main/module.php b/Energy Counter Main/module.php new file mode 100644 index 0000000..ea2ebee --- /dev/null +++ b/Energy Counter Main/module.php @@ -0,0 +1,368 @@ +RegisterPropertyInteger('TargetCategoryID', 0); + $this->RegisterPropertyFloat('GlobalPricePerKWh', 0.0); + $this->RegisterPropertyString('Counters', '[]'); + + // Die Berechnungszustände liegen bewusst im Hauptmodul. Childinstanzen + // enthalten ausschließlich die (bei Bedarf ausgeblendeten) Anzeigevariablen. + $this->RegisterAttributeString('CounterState', '{}'); + $this->RegisterAttributeString('CounterChildren', '{}'); + $this->RegisterAttributeString('RegisteredSourceIDs', '[]'); + + $this->RegisterTimer('Update', 0, 'ECM_UpdateValues(' . $this->InstanceID . ');'); + } + + public function ApplyChanges() + { + parent::ApplyChanges(); + + $this->SetTimerInterval('Update', 60 * 1000); + $this->SynchronizeChildren(); + $this->UpdateSourceMessages(); + $this->UpdateValues(); + + $categoryID = $this->ReadPropertyInteger('TargetCategoryID'); + $this->SetStatus(($categoryID > 0 && IPS_ObjectExists($categoryID)) ? 102 : 201); + } + + public function MessageSink($TimeStamp, $SenderID, $Message, $Data) + { + if ($Message === VM_UPDATE) { + $this->UpdateValues(); + } + } + + /** Erstellt bzw. aktualisiert für jeden Tabellen-Eintrag eine Childinstanz. */ + public function SynchronizeChildren() + { + if (!$this->EnterLock()) { + return; + } + + try { + $categoryID = $this->ReadPropertyInteger('TargetCategoryID'); + if ($categoryID <= 0 || !IPS_ObjectExists($categoryID)) { + $this->SetStatus(201); + return; + } + + $children = $this->ReadJsonAttribute('CounterChildren', []); + foreach ($this->GetCounters() as $counter) { + $key = $counter['Key']; + $childID = isset($children[$key]) ? (int) $children[$key] : 0; + + if ($childID <= 0 || !$this->IsManagedChild($childID)) { + $childID = $this->FindManagedChild($categoryID, $key); + } + + if ($childID <= 0) { + $existingID = @IPS_GetObjectIDByIdent($key, $categoryID); + if ($existingID !== false) { + $this->Log('Zähler "' . $counter['Name'] . '": der Ident ' . $key . ' ist in der Zielkategorie bereits durch Objekt ' . $existingID . ' belegt.'); + continue; + } + $childID = IPS_CreateInstance(self::CHILD_MODULE_ID); + IPS_SetParent($childID, $categoryID); + IPS_SetIdent($childID, $key); + } elseif (IPS_GetObject($childID)['ParentID'] !== $categoryID) { + $existingID = @IPS_GetObjectIDByIdent($key, $categoryID); + if ($existingID !== false && $existingID !== $childID) { + $this->Log('Zähler "' . $counter['Name'] . '": die Childinstanz kann nicht verschoben werden, weil der Ident ' . $key . ' in der Zielkategorie belegt ist.'); + continue; + } + IPS_SetParent($childID, $categoryID); + } + + IPS_SetName($childID, $counter['Name']); + $this->ConfigureChild($childID, $key); + $children[$key] = $childID; + } + + $this->WriteAttributeString('CounterChildren', json_encode($children)); + $this->SetStatus(102); + } catch (\Throwable $exception) { + $this->Log('Childinstanzen konnten nicht synchronisiert werden: ' . $exception->getMessage()); + $this->SetStatus(201); + } finally { + $this->LeaveLock(); + } + } + + /** Liest alle Quellzähler aus und schreibt die sechs Werte in ihre Childinstanz. */ + public function UpdateValues() + { + if (!$this->EnterLock()) { + return; + } + + try { + $states = $this->ReadJsonAttribute('CounterState', []); + $children = $this->ReadJsonAttribute('CounterChildren', []); + $today = date('Y-m-d'); + $month = date('Y-m'); + + foreach ($this->GetCounters() as $counter) { + $key = $counter['Key']; + $sourceID = $counter['VariableID']; + if (!IPS_VariableExists($sourceID)) { + $this->Log('Zähler "' . $counter['Name'] . '": Quellvariable ' . $sourceID . ' existiert nicht.'); + continue; + } + + $sourceValue = GetValue($sourceID); + if (!is_numeric($sourceValue)) { + $this->Log('Zähler "' . $counter['Name'] . '": Quellvariable enthält keinen numerischen Wert.'); + continue; + } + + $state = $this->NormalizeState($states[$key] ?? [], $today, $month); + $currentValue = (float) $sourceValue; + + // Die erste Messung setzt nur die Referenz. Dadurch wird kein bereits + // vorhandener Zählerstand irrtümlich als neuer Verbrauch gewertet. + if (!$state['initialized']) { + $state['initialized'] = true; + $state['lastRaw'] = $currentValue; + } else { + $delta = $currentValue - $state['lastRaw']; + if ($delta >= 0) { + $state['totalEnergy'] += $delta; + $state['dayEnergy'] += $delta; + $state['monthEnergy'] += $delta; + } else { + // Ein zurückgesetzter/überlaufener Hardwarezähler darf den + // bereits berechneten Verbrauch nicht negativ verändern. + $this->Log('Zähler "' . $counter['Name'] . '": fallender Zählerstand erkannt; neue Referenz gesetzt.'); + } + $state['lastRaw'] = $currentValue; + } + + $states[$key] = $state; + $childID = isset($children[$key]) ? (int) $children[$key] : 0; + if ($childID > 0 && IPS_InstanceExists($childID)) { + $this->WriteChildValues($childID, $state, $counter['PricePerKWh']); + } + } + + $this->WriteAttributeString('CounterState', json_encode($states)); + } finally { + $this->LeaveLock(); + } + } + + /** Setzt ausschließlich die im Hauptmodul berechneten Gesamtwerte zurück. */ + public function ResetTotalEnergy() + { + $this->ResetEnergy('totalEnergy'); + } + + /** Setzt ausschließlich die im Hauptmodul berechneten Tageswerte zurück. */ + public function ResetDayEnergy() + { + $this->ResetEnergy('dayEnergy'); + } + + /** Setzt ausschließlich die im Hauptmodul berechneten Monatswerte zurück. */ + public function ResetMonthEnergy() + { + $this->ResetEnergy('monthEnergy'); + } + + private function ResetEnergy(string $field) + { + // Vor dem Reset wird ein möglicherweise noch nicht verarbeiteter Anstieg + // übernommen. Der externe Zählerstand selbst bleibt stets unverändert. + $this->UpdateValues(); + if (!$this->EnterLock()) { + return; + } + + try { + $states = $this->ReadJsonAttribute('CounterState', []); + $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[$field] = 0.0; + $states[$key] = $state; + + $childID = isset($children[$key]) ? (int) $children[$key] : 0; + if ($childID > 0 && IPS_InstanceExists($childID)) { + $this->WriteChildValues($childID, $state, $counter['PricePerKWh']); + } + } + $this->WriteAttributeString('CounterState', json_encode($states)); + } finally { + $this->LeaveLock(); + } + } + + private function UpdateSourceMessages() + { + $previousSources = $this->ReadJsonAttribute('RegisteredSourceIDs', []); + foreach ($previousSources as $sourceID) { + if (IPS_VariableExists((int) $sourceID)) { + $this->UnregisterMessage((int) $sourceID, VM_UPDATE); + } + } + + $sources = []; + foreach ($this->GetCounters() as $counter) { + $sourceID = $counter['VariableID']; + if (IPS_VariableExists($sourceID) && !in_array($sourceID, $sources, true)) { + $this->RegisterMessage($sourceID, VM_UPDATE); + $sources[] = $sourceID; + } + } + $this->WriteAttributeString('RegisteredSourceIDs', json_encode($sources)); + } + + private function GetCounters(): array + { + $configuredCounters = json_decode($this->ReadPropertyString('Counters'), true); + if (!is_array($configuredCounters)) { + return []; + } + + $counters = []; + $usedSources = []; + foreach ($configuredCounters as $configuredCounter) { + if (!is_array($configuredCounter)) { + continue; + } + + // Die englischen Konfigurationsschlüssel sind die dauerhaften + // Schnittstellennamen. Die Fallbacks halten bereits angelegte + // Instanzen mit dem Formular der ersten Version funktionsfähig. + $name = trim((string) ($configuredCounter['CounterName'] ?? $configuredCounter['Name'] ?? '')); + $sourceID = (int) ($configuredCounter['SourceVariableID'] ?? $configuredCounter['VariableID'] ?? 0); + if ($name === '' || $sourceID <= 0) { + continue; + } + if (in_array($sourceID, $usedSources, true)) { + $this->Log('Zähler "' . $name . '": dieselbe Quellvariable wurde mehrfach konfiguriert und wird nur einmal verwendet.'); + continue; + } + $usedSources[] = $sourceID; + + $globalPrice = max(0.0, $this->ReadPropertyFloat('GlobalPricePerKWh')); + // Der globale Tarif ist der Standard. Ein Zeilentarif ist nur dann + // wirksam, wenn er ausdrücklich über den Schalter aktiviert wurde. + $hasOwnTariff = (bool) ($configuredCounter['UseOwnTariff'] ?? false); + $price = $hasOwnTariff + ? max(0.0, (float) ($configuredCounter['PricePerKWh'] ?? 0)) + : $globalPrice; + $counters[] = [ + // Die Quellvariable ist der stabile Schlüssel. Ein Umbenennen des + // Zählers erhält damit die Childinstanz und ihre Historie. + 'Key' => 'counter_' . $sourceID, + 'Name' => $name, + 'VariableID' => $sourceID, + 'PricePerKWh' => $price + ]; + } + + return $counters; + } + + private function NormalizeState(array $state, string $today, string $month): array + { + $normalized = [ + 'initialized' => (bool) ($state['initialized'] ?? false), + 'lastRaw' => (float) ($state['lastRaw'] ?? 0), + 'totalEnergy' => max(0.0, (float) ($state['totalEnergy'] ?? 0)), + 'dayEnergy' => max(0.0, (float) ($state['dayEnergy'] ?? 0)), + 'monthEnergy' => max(0.0, (float) ($state['monthEnergy'] ?? 0)), + 'dayStamp' => (string) ($state['dayStamp'] ?? $today), + 'monthStamp' => (string) ($state['monthStamp'] ?? $month) + ]; + + if ($normalized['dayStamp'] !== $today) { + $normalized['dayEnergy'] = 0.0; + $normalized['dayStamp'] = $today; + } + if ($normalized['monthStamp'] !== $month) { + $normalized['monthEnergy'] = 0.0; + $normalized['monthStamp'] = $month; + } + + return $normalized; + } + + private function WriteChildValues(int $childID, array $state, float $pricePerKWh) + { + $values = [ + 'TotalEnergy' => $state['totalEnergy'], + 'TotalCost' => $state['totalEnergy'] * $pricePerKWh, + 'DayEnergy' => $state['dayEnergy'], + 'DayCost' => $state['dayEnergy'] * $pricePerKWh, + 'MonthEnergy' => $state['monthEnergy'], + 'MonthCost' => $state['monthEnergy'] * $pricePerKWh + ]; + + foreach ($values as $ident => $value) { + $variableID = @IPS_GetObjectIDByIdent($ident, $childID); + if ($variableID !== false && IPS_VariableExists($variableID)) { + SetValue($variableID, round((float) $value, 4)); + } + } + } + + private function FindManagedChild(int $categoryID, string $key): int + { + $childID = @IPS_GetObjectIDByIdent($key, $categoryID); + return ($childID !== false && $this->IsManagedChild($childID)) ? $childID : 0; + } + + private function IsManagedChild(int $childID): bool + { + if (!IPS_InstanceExists($childID)) { + return false; + } + + $instance = IPS_GetInstance($childID); + return ($instance['ModuleInfo']['ModuleID'] ?? '') === self::CHILD_MODULE_ID; + } + + private function ConfigureChild(int $childID, string $key) + { + $configuration = json_decode(IPS_GetConfiguration($childID), true); + if (!is_array($configuration)) { + $configuration = []; + } + $configuration['ParentInstanceID'] = $this->InstanceID; + $configuration['CounterKey'] = $key; + IPS_SetConfiguration($childID, json_encode($configuration)); + IPS_ApplyChanges($childID); + } + + private function ReadJsonAttribute(string $name, array $default): array + { + $value = json_decode($this->ReadAttributeString($name), true); + return is_array($value) ? $value : $default; + } + + private function EnterLock(): bool + { + return IPS_SemaphoreEnter('EnergyCounterMain_' . $this->InstanceID, 1000); + } + + private function LeaveLock() + { + IPS_SemaphoreLeave('EnergyCounterMain_' . $this->InstanceID); + } + + private function Log(string $message) + { + IPS_LogMessage('EnergyCounterMain', $message); + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..530dc8f --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# EnergyCounter + +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. + +## Einrichtung + +1. Eine Instanz von **EnergyCounterMain** anlegen und eine Zielkategorie wählen. +2. Den globalen Stromtarif eintragen. In der Tabelle für jeden Zähler einen Namen und eine numerische Zählerstand-Variable (kWh, kumuliert) eintragen. Ein abweichender Tarif wird nur verwendet, wenn in dessen Zeile **Eigener Tarif verwenden** aktiviert ist. +3. Übernehmen. Für jeden Tabellen-Eintrag wird eine Childinstanz in der Zielkategorie erstellt. +4. Bei Bedarf in jeder Childinstanz die nicht benötigten Werte ausblenden. + +Die Quellvariable wird nie verändert. Beim ersten Auslesen wird ihr Wert als Referenz übernommen; die berechneten Gesamtwerte beginnen daher bei `0 kWh`. Sinkt ein Hardwarezählerstand, wird er als Zählerreset behandelt, ohne bereits ermittelte Verbrauchswerte zu verringern. + +Entfernte Tabellen-Einträge löschen keine Childinstanzen oder historischen Werte automatisch. Das verhindert unbeabsichtigten Datenverlust; nicht mehr benötigte Childinstanzen können bei Bedarf manuell gelöscht werden. diff --git a/library.json b/library.json new file mode 100644 index 0000000..d577063 --- /dev/null +++ b/library.json @@ -0,0 +1,13 @@ +{ + "id": "{A4B3E7AA-6AE9-4C5F-BD8C-9107E1E4469A}", + "author": "J.H. Artworks", + "name": "EnergyCounter", + "url": "https://jh-artworks.com", + "compatibility": { + "version": "6.0", + "date": 1491343200 + }, + "version": "1.1", + "build": 2, + "date": 0 +}