added sync from linked variable
This commit is contained in:
1 parent
faa518ccd8
commit
ac0621ffe4
6 files changed
+89
-5
No files matched your search
@@ -42,6 +42,12 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"actions": [],
|
"actions": [
|
||||||
|
{
|
||||||
|
"type": "Button",
|
||||||
|
"caption": "Set total energy to current meter value",
|
||||||
|
"onClick": "ECC_SetTotalEnergyToCurrentSource($id);"
|
||||||
|
}
|
||||||
|
],
|
||||||
"status": []
|
"status": []
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
"de": {
|
"de": {
|
||||||
"Energy Counter Display": "Energiezähler Anzeige",
|
"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.",
|
"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.",
|
||||||
|
"Set total energy to current meter value": "Gesamtenergie auf aktuellen Zählerstand setzen",
|
||||||
"Display variables": "Anzuzeigende Variablen",
|
"Display variables": "Anzuzeigende Variablen",
|
||||||
"Show total energy": "Gesamtenergie anzeigen",
|
"Show total energy": "Gesamtenergie anzeigen",
|
||||||
"Show total cost": "Gesamtkosten anzeigen",
|
"Show total cost": "Gesamtkosten anzeigen",
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class EnergyCounterChild extends IPSModule
|
|||||||
// nicht im Formular angeboten. Die Childinstanz bleibt reine Anzeige.
|
// nicht im Formular angeboten. Die Childinstanz bleibt reine Anzeige.
|
||||||
$this->RegisterPropertyInteger('ParentInstanceID', 0);
|
$this->RegisterPropertyInteger('ParentInstanceID', 0);
|
||||||
$this->RegisterPropertyString('CounterKey', '');
|
$this->RegisterPropertyString('CounterKey', '');
|
||||||
|
$this->RegisterPropertyInteger('SourceVariableID', 0);
|
||||||
|
|
||||||
$this->RegisterPropertyBoolean('ShowTotalEnergy', true);
|
$this->RegisterPropertyBoolean('ShowTotalEnergy', true);
|
||||||
$this->RegisterPropertyBoolean('ShowTotalCost', true);
|
$this->RegisterPropertyBoolean('ShowTotalCost', true);
|
||||||
@@ -35,6 +36,25 @@ class EnergyCounterChild extends IPSModule
|
|||||||
$this->SetStatus(102);
|
$this->SetStatus(102);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Setzt die Gesamtenergie über das Hauptmodul auf den aktuellen Zählerstand. */
|
||||||
|
public function SetTotalEnergyToCurrentSource(): bool
|
||||||
|
{
|
||||||
|
$parentInstanceID = $this->ReadPropertyInteger('ParentInstanceID');
|
||||||
|
$counterKey = $this->ReadPropertyString('CounterKey');
|
||||||
|
if ($parentInstanceID <= 0 || $counterKey === '') {
|
||||||
|
IPS_LogMessage('EnergyCounterChild', 'Gesamtenergie kann nicht gesetzt werden: Zuordnung zum Hauptmodul fehlt.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$function = 'ECM_SetCounterTotalEnergyFromSource';
|
||||||
|
if (!function_exists($function)) {
|
||||||
|
IPS_LogMessage('EnergyCounterChild', 'Gesamtenergie kann nicht gesetzt werden: Hauptmodul-Funktion ist nicht verfügbar.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $function($parentInstanceID, $counterKey);
|
||||||
|
}
|
||||||
|
|
||||||
private function RegisterValueVariables()
|
private function RegisterValueVariables()
|
||||||
{
|
{
|
||||||
$this->RegisterVariableFloat('TotalEnergy', $this->Translate('Total Energy'), self::ENERGY_PROFILE, 10);
|
$this->RegisterVariableFloat('TotalEnergy', $this->Translate('Total Energy'), self::ENERGY_PROFILE, 10);
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ class EnergyCounterMain extends IPSModule
|
|||||||
}
|
}
|
||||||
|
|
||||||
IPS_SetName($childID, $counter['Name']);
|
IPS_SetName($childID, $counter['Name']);
|
||||||
$this->ConfigureChild($childID, $key);
|
$this->ConfigureChild($childID, $key, $counter['VariableID']);
|
||||||
$children[$key] = $childID;
|
$children[$key] = $childID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,6 +177,60 @@ class EnergyCounterMain extends IPSModule
|
|||||||
$this->ResetEnergy('monthEnergy');
|
$this->ResetEnergy('monthEnergy');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Übernimmt den aktuellen Rohzählerstand als Gesamtenergie eines einzelnen
|
||||||
|
* Counters. Diese Methode wird über den Initialisierungsbutton des Childs
|
||||||
|
* aufgerufen, die Zustandsführung bleibt aber im Hauptmodul.
|
||||||
|
*/
|
||||||
|
public function SetCounterTotalEnergyFromSource(string $counterKey): bool
|
||||||
|
{
|
||||||
|
// Noch nicht verarbeitete Änderungen sollen Tages- und Monatswerte
|
||||||
|
// weiterhin korrekt fortschreiben, bevor nur der Gesamtwert gesetzt wird.
|
||||||
|
$this->UpdateValues();
|
||||||
|
if (!$this->EnterLock()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$counter = null;
|
||||||
|
foreach ($this->GetCounters() as $configuredCounter) {
|
||||||
|
if ($configuredCounter['Key'] === $counterKey) {
|
||||||
|
$counter = $configuredCounter;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($counter === null || !IPS_VariableExists($counter['VariableID'])) {
|
||||||
|
$this->Log('Gesamtenergie konnte nicht gesetzt werden: Quellzähler für ' . $counterKey . ' ist nicht verfügbar.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sourceValue = GetValue($counter['VariableID']);
|
||||||
|
if (!is_numeric($sourceValue)) {
|
||||||
|
$this->Log('Gesamtenergie konnte nicht gesetzt werden: Quellzähler für ' . $counter['Name'] . ' enthält keinen numerischen Wert.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$states = $this->ReadJsonAttribute('CounterState', []);
|
||||||
|
$state = $this->NormalizeState($states[$counterKey] ?? [], date('Y-m-d'), date('Y-m'));
|
||||||
|
$currentValue = (float) $sourceValue;
|
||||||
|
$state['initialized'] = true;
|
||||||
|
$state['lastRaw'] = $currentValue;
|
||||||
|
$state['totalEnergy'] = max(0.0, $currentValue);
|
||||||
|
$states[$counterKey] = $state;
|
||||||
|
$this->WriteAttributeString('CounterState', json_encode($states));
|
||||||
|
|
||||||
|
$children = $this->ReadJsonAttribute('CounterChildren', []);
|
||||||
|
$childID = isset($children[$counterKey]) ? (int) $children[$counterKey] : 0;
|
||||||
|
if ($childID > 0 && IPS_InstanceExists($childID)) {
|
||||||
|
$this->WriteChildValues($childID, $state, $counter['PricePerKWh']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} finally {
|
||||||
|
$this->LeaveLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function ResetEnergy(string $field)
|
private function ResetEnergy(string $field)
|
||||||
{
|
{
|
||||||
// Vor dem Reset wird ein möglicherweise noch nicht verarbeiteter Anstieg
|
// Vor dem Reset wird ein möglicherweise noch nicht verarbeiteter Anstieg
|
||||||
@@ -333,7 +387,7 @@ class EnergyCounterMain extends IPSModule
|
|||||||
return ($instance['ModuleInfo']['ModuleID'] ?? '') === self::CHILD_MODULE_ID;
|
return ($instance['ModuleInfo']['ModuleID'] ?? '') === self::CHILD_MODULE_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function ConfigureChild(int $childID, string $key)
|
private function ConfigureChild(int $childID, string $key, int $sourceVariableID)
|
||||||
{
|
{
|
||||||
$configuration = json_decode(IPS_GetConfiguration($childID), true);
|
$configuration = json_decode(IPS_GetConfiguration($childID), true);
|
||||||
if (!is_array($configuration)) {
|
if (!is_array($configuration)) {
|
||||||
@@ -341,6 +395,7 @@ class EnergyCounterMain extends IPSModule
|
|||||||
}
|
}
|
||||||
$configuration['ParentInstanceID'] = $this->InstanceID;
|
$configuration['ParentInstanceID'] = $this->InstanceID;
|
||||||
$configuration['CounterKey'] = $key;
|
$configuration['CounterKey'] = $key;
|
||||||
|
$configuration['SourceVariableID'] = $sourceVariableID;
|
||||||
IPS_SetConfiguration($childID, json_encode($configuration));
|
IPS_SetConfiguration($childID, json_encode($configuration));
|
||||||
IPS_ApplyChanges($childID);
|
IPS_ApplyChanges($childID);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ Die Bibliothek enthält zwei Symcon-Module:
|
|||||||
3. Übernehmen. Für jeden Tabellen-Eintrag wird eine Childinstanz in der Zielkategorie erstellt.
|
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.
|
4. Bei Bedarf in jeder Childinstanz die nicht benötigten Werte ausblenden.
|
||||||
|
|
||||||
|
Über den Button **Gesamtenergie auf aktuellen Zählerstand setzen** in einer Childinstanz kann deren Gesamtenergie einmalig mit dem Wert ihrer verlinkten Quellvariable initialisiert werden. Die Tages- und Monatsenergie bleibt dabei unverändert.
|
||||||
|
|
||||||
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.
|
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.
|
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.
|
||||||
+2
-2
@@ -7,7 +7,7 @@
|
|||||||
"version": "6.0",
|
"version": "6.0",
|
||||||
"date": 1491343200
|
"date": 1491343200
|
||||||
},
|
},
|
||||||
"version": "1.1",
|
"version": "1.2",
|
||||||
"build": 2,
|
"build": 3,
|
||||||
"date": 0
|
"date": 0
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user