added yearly Energy and costs
This commit is contained in:
1 parent
ac0621ffe4
commit
989d58ad1a
8 files changed
+54
-12
No files matched your search
@@ -38,6 +38,16 @@
|
|||||||
"type": "CheckBox",
|
"type": "CheckBox",
|
||||||
"name": "ShowMonthCost",
|
"name": "ShowMonthCost",
|
||||||
"caption": "Show monthly cost"
|
"caption": "Show monthly cost"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "CheckBox",
|
||||||
|
"name": "ShowYearEnergy",
|
||||||
|
"caption": "Show yearly energy"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "CheckBox",
|
||||||
|
"name": "ShowYearCost",
|
||||||
|
"caption": "Show yearly cost"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,12 +11,16 @@
|
|||||||
"Show daily cost": "Tageskosten anzeigen",
|
"Show daily cost": "Tageskosten anzeigen",
|
||||||
"Show monthly energy": "Monatsenergie anzeigen",
|
"Show monthly energy": "Monatsenergie anzeigen",
|
||||||
"Show monthly cost": "Monatskosten anzeigen",
|
"Show monthly cost": "Monatskosten anzeigen",
|
||||||
|
"Show yearly energy": "Jahresenergie anzeigen",
|
||||||
|
"Show yearly cost": "Jahreskosten anzeigen",
|
||||||
"Total Energy": "Gesamtenergie",
|
"Total Energy": "Gesamtenergie",
|
||||||
"Total Cost": "Gesamtkosten",
|
"Total Cost": "Gesamtkosten",
|
||||||
"Daily Energy": "Tagesenergie",
|
"Daily Energy": "Tagesenergie",
|
||||||
"Daily Cost": "Tageskosten",
|
"Daily Cost": "Tageskosten",
|
||||||
"Monthly Energy": "Monatsenergie",
|
"Monthly Energy": "Monatsenergie",
|
||||||
"Monthly Cost": "Monatskosten"
|
"Monthly Cost": "Monatskosten",
|
||||||
|
"Yearly Energy": "Jahresenergie",
|
||||||
|
"Yearly Cost": "Jahreskosten"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,8 @@ class EnergyCounterChild extends IPSModule
|
|||||||
$this->RegisterPropertyBoolean('ShowDayCost', true);
|
$this->RegisterPropertyBoolean('ShowDayCost', true);
|
||||||
$this->RegisterPropertyBoolean('ShowMonthEnergy', true);
|
$this->RegisterPropertyBoolean('ShowMonthEnergy', true);
|
||||||
$this->RegisterPropertyBoolean('ShowMonthCost', true);
|
$this->RegisterPropertyBoolean('ShowMonthCost', true);
|
||||||
|
$this->RegisterPropertyBoolean('ShowYearEnergy', true);
|
||||||
|
$this->RegisterPropertyBoolean('ShowYearCost', true);
|
||||||
|
|
||||||
$this->EnsureProfiles();
|
$this->EnsureProfiles();
|
||||||
$this->RegisterValueVariables();
|
$this->RegisterValueVariables();
|
||||||
@@ -63,6 +65,8 @@ class EnergyCounterChild extends IPSModule
|
|||||||
$this->RegisterVariableFloat('DayCost', $this->Translate('Daily Cost'), self::COST_PROFILE, 40);
|
$this->RegisterVariableFloat('DayCost', $this->Translate('Daily Cost'), self::COST_PROFILE, 40);
|
||||||
$this->RegisterVariableFloat('MonthEnergy', $this->Translate('Monthly Energy'), self::ENERGY_PROFILE, 50);
|
$this->RegisterVariableFloat('MonthEnergy', $this->Translate('Monthly Energy'), self::ENERGY_PROFILE, 50);
|
||||||
$this->RegisterVariableFloat('MonthCost', $this->Translate('Monthly Cost'), self::COST_PROFILE, 60);
|
$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()
|
private function ApplyVisibility()
|
||||||
@@ -73,7 +77,9 @@ class EnergyCounterChild extends IPSModule
|
|||||||
'DayEnergy' => $this->ReadPropertyBoolean('ShowDayEnergy'),
|
'DayEnergy' => $this->ReadPropertyBoolean('ShowDayEnergy'),
|
||||||
'DayCost' => $this->ReadPropertyBoolean('ShowDayCost'),
|
'DayCost' => $this->ReadPropertyBoolean('ShowDayCost'),
|
||||||
'MonthEnergy' => $this->ReadPropertyBoolean('ShowMonthEnergy'),
|
'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) {
|
foreach ($visibility as $ident => $visible) {
|
||||||
|
|||||||
@@ -89,6 +89,11 @@
|
|||||||
"type": "Button",
|
"type": "Button",
|
||||||
"caption": "Reset monthly values",
|
"caption": "Reset monthly values",
|
||||||
"onClick": "ECM_ResetMonthEnergy($id);"
|
"onClick": "ECM_ResetMonthEnergy($id);"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Button",
|
||||||
|
"caption": "Reset yearly values",
|
||||||
|
"onClick": "ECM_ResetYearEnergy($id);"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"status": [
|
"status": [
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
"Reset total values": "Gesamtwerte zurücksetzen",
|
"Reset total values": "Gesamtwerte zurücksetzen",
|
||||||
"Reset daily values": "Tageswerte zurücksetzen",
|
"Reset daily values": "Tageswerte zurücksetzen",
|
||||||
"Reset monthly values": "Monatswerte zurücksetzen",
|
"Reset monthly values": "Monatswerte zurücksetzen",
|
||||||
|
"Reset yearly values": "Jahreswerte zurücksetzen",
|
||||||
"Active": "Aktiv",
|
"Active": "Aktiv",
|
||||||
"Category missing or invalid": "Kategorie fehlt oder ist ungültig"
|
"Category missing or invalid": "Kategorie fehlt oder ist ungültig"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ class EnergyCounterMain extends IPSModule
|
|||||||
$children = $this->ReadJsonAttribute('CounterChildren', []);
|
$children = $this->ReadJsonAttribute('CounterChildren', []);
|
||||||
$today = date('Y-m-d');
|
$today = date('Y-m-d');
|
||||||
$month = date('Y-m');
|
$month = date('Y-m');
|
||||||
|
$year = date('Y');
|
||||||
|
|
||||||
foreach ($this->GetCounters() as $counter) {
|
foreach ($this->GetCounters() as $counter) {
|
||||||
$key = $counter['Key'];
|
$key = $counter['Key'];
|
||||||
@@ -124,7 +125,7 @@ class EnergyCounterMain extends IPSModule
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$state = $this->NormalizeState($states[$key] ?? [], $today, $month);
|
$state = $this->NormalizeState($states[$key] ?? [], $today, $month, $year);
|
||||||
$currentValue = (float) $sourceValue;
|
$currentValue = (float) $sourceValue;
|
||||||
|
|
||||||
// Die erste Messung setzt nur die Referenz. Dadurch wird kein bereits
|
// Die erste Messung setzt nur die Referenz. Dadurch wird kein bereits
|
||||||
@@ -138,6 +139,7 @@ class EnergyCounterMain extends IPSModule
|
|||||||
$state['totalEnergy'] += $delta;
|
$state['totalEnergy'] += $delta;
|
||||||
$state['dayEnergy'] += $delta;
|
$state['dayEnergy'] += $delta;
|
||||||
$state['monthEnergy'] += $delta;
|
$state['monthEnergy'] += $delta;
|
||||||
|
$state['yearEnergy'] += $delta;
|
||||||
} else {
|
} else {
|
||||||
// Ein zurückgesetzter/überlaufener Hardwarezähler darf den
|
// Ein zurückgesetzter/überlaufener Hardwarezähler darf den
|
||||||
// bereits berechneten Verbrauch nicht negativ verändern.
|
// bereits berechneten Verbrauch nicht negativ verändern.
|
||||||
@@ -177,6 +179,12 @@ class EnergyCounterMain extends IPSModule
|
|||||||
$this->ResetEnergy('monthEnergy');
|
$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
|
* Übernimmt den aktuellen Rohzählerstand als Gesamtenergie eines einzelnen
|
||||||
* Counters. Diese Methode wird über den Initialisierungsbutton des Childs
|
* Counters. Diese Methode wird über den Initialisierungsbutton des Childs
|
||||||
@@ -211,7 +219,7 @@ class EnergyCounterMain extends IPSModule
|
|||||||
}
|
}
|
||||||
|
|
||||||
$states = $this->ReadJsonAttribute('CounterState', []);
|
$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;
|
$currentValue = (float) $sourceValue;
|
||||||
$state['initialized'] = true;
|
$state['initialized'] = true;
|
||||||
$state['lastRaw'] = $currentValue;
|
$state['lastRaw'] = $currentValue;
|
||||||
@@ -245,7 +253,7 @@ class EnergyCounterMain extends IPSModule
|
|||||||
$children = $this->ReadJsonAttribute('CounterChildren', []);
|
$children = $this->ReadJsonAttribute('CounterChildren', []);
|
||||||
foreach ($this->GetCounters() as $counter) {
|
foreach ($this->GetCounters() as $counter) {
|
||||||
$key = $counter['Key'];
|
$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;
|
$state[$field] = 0.0;
|
||||||
$states[$key] = $state;
|
$states[$key] = $state;
|
||||||
|
|
||||||
@@ -328,7 +336,7 @@ class EnergyCounterMain extends IPSModule
|
|||||||
return $counters;
|
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 = [
|
$normalized = [
|
||||||
'initialized' => (bool) ($state['initialized'] ?? false),
|
'initialized' => (bool) ($state['initialized'] ?? false),
|
||||||
@@ -336,8 +344,10 @@ class EnergyCounterMain extends IPSModule
|
|||||||
'totalEnergy' => max(0.0, (float) ($state['totalEnergy'] ?? 0)),
|
'totalEnergy' => max(0.0, (float) ($state['totalEnergy'] ?? 0)),
|
||||||
'dayEnergy' => max(0.0, (float) ($state['dayEnergy'] ?? 0)),
|
'dayEnergy' => max(0.0, (float) ($state['dayEnergy'] ?? 0)),
|
||||||
'monthEnergy' => max(0.0, (float) ($state['monthEnergy'] ?? 0)),
|
'monthEnergy' => max(0.0, (float) ($state['monthEnergy'] ?? 0)),
|
||||||
|
'yearEnergy' => max(0.0, (float) ($state['yearEnergy'] ?? 0)),
|
||||||
'dayStamp' => (string) ($state['dayStamp'] ?? $today),
|
'dayStamp' => (string) ($state['dayStamp'] ?? $today),
|
||||||
'monthStamp' => (string) ($state['monthStamp'] ?? $month)
|
'monthStamp' => (string) ($state['monthStamp'] ?? $month),
|
||||||
|
'yearStamp' => (string) ($state['yearStamp'] ?? $year)
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($normalized['dayStamp'] !== $today) {
|
if ($normalized['dayStamp'] !== $today) {
|
||||||
@@ -348,6 +358,10 @@ class EnergyCounterMain extends IPSModule
|
|||||||
$normalized['monthEnergy'] = 0.0;
|
$normalized['monthEnergy'] = 0.0;
|
||||||
$normalized['monthStamp'] = $month;
|
$normalized['monthStamp'] = $month;
|
||||||
}
|
}
|
||||||
|
if ($normalized['yearStamp'] !== $year) {
|
||||||
|
$normalized['yearEnergy'] = 0.0;
|
||||||
|
$normalized['yearStamp'] = $year;
|
||||||
|
}
|
||||||
|
|
||||||
return $normalized;
|
return $normalized;
|
||||||
}
|
}
|
||||||
@@ -360,7 +374,9 @@ class EnergyCounterMain extends IPSModule
|
|||||||
'DayEnergy' => $state['dayEnergy'],
|
'DayEnergy' => $state['dayEnergy'],
|
||||||
'DayCost' => $state['dayEnergy'] * $pricePerKWh,
|
'DayCost' => $state['dayEnergy'] * $pricePerKWh,
|
||||||
'MonthEnergy' => $state['monthEnergy'],
|
'MonthEnergy' => $state['monthEnergy'],
|
||||||
'MonthCost' => $state['monthEnergy'] * $pricePerKWh
|
'MonthCost' => $state['monthEnergy'] * $pricePerKWh,
|
||||||
|
'YearEnergy' => $state['yearEnergy'],
|
||||||
|
'YearCost' => $state['yearEnergy'] * $pricePerKWh
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($values as $ident => $value) {
|
foreach ($values as $ident => $value) {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
Die Bibliothek enthält zwei Symcon-Module:
|
Die Bibliothek enthält zwei Symcon-Module:
|
||||||
|
|
||||||
- **EnergyCounterMain**: Konfiguration aller Zähler, Ermittlung von Energie und Kosten, automatische Tages-/Monatsresets sowie manuelle Resets.
|
- **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 sechs berechneten Variablen sichtbar sind.
|
- **EnergyCounterChild**: Wird vom Hauptmodul unter der gewählten Kategorie angelegt. Sein Formular steuert ausschließlich, welche der acht berechneten Variablen sichtbar sind.
|
||||||
|
|
||||||
## Einrichtung
|
## Einrichtung
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -7,7 +7,7 @@
|
|||||||
"version": "6.0",
|
"version": "6.0",
|
||||||
"date": 1491343200
|
"date": 1491343200
|
||||||
},
|
},
|
||||||
"version": "1.2",
|
"version": "1.3",
|
||||||
"build": 3,
|
"build": 4,
|
||||||
"date": 0
|
"date": 0
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user