no message
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class Belevo_PV_Visu extends IPSModule
|
||||
{
|
||||
public function Create()
|
||||
{
|
||||
parent::Create();
|
||||
// vier Properties, in denen später die vier Zähler-Variablen gewählt werden
|
||||
// Properties für die vier Zähler-Variablen
|
||||
$this->RegisterPropertyInteger('VarProduction', 0);
|
||||
$this->RegisterPropertyInteger('VarConsumption', 0);
|
||||
$this->RegisterPropertyInteger('VarFeedIn', 0);
|
||||
@@ -14,83 +14,69 @@ class Belevo_PV_Visu extends IPSModule
|
||||
$this->SetVisualizationType(3);
|
||||
}
|
||||
|
||||
public function GetConfigurationForm(): string
|
||||
{
|
||||
return json_encode([
|
||||
'elements' => [
|
||||
[
|
||||
'type' => 'SelectVariable',
|
||||
'name' => 'VarProduction',
|
||||
'caption' => 'Produktion (kWh)'
|
||||
],
|
||||
[
|
||||
'type' => 'SelectVariable',
|
||||
'name' => 'VarConsumption',
|
||||
'caption' => 'Verbrauch (kWh)'
|
||||
],
|
||||
[
|
||||
'type' => 'SelectVariable',
|
||||
'name' => 'VarFeedIn',
|
||||
'caption' => 'Einspeisung (kWh)'
|
||||
],
|
||||
[
|
||||
'type' => 'SelectVariable',
|
||||
'name' => 'VarGrid',
|
||||
'caption' => 'Bezug Netz (kWh)'
|
||||
]
|
||||
],
|
||||
'actions' => []
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* Wird aufgerufen, wenn IPS das statische form.json nicht findet
|
||||
* (hier leer, denn wir nutzen form.json im Root)
|
||||
*/
|
||||
// public function GetConfigurationForm(): string
|
||||
// {
|
||||
// return '';
|
||||
// }
|
||||
|
||||
/**
|
||||
* Wird automatisch aufgerufen, wenn die Visu die Tile anfordert
|
||||
* Liefert das HTML-Template für die WebFront-Tile
|
||||
*/
|
||||
public function GetVisualizationTile(int $InstanceID): string
|
||||
{
|
||||
$file = __DIR__ . '/module.html';
|
||||
if (!file_exists($file)) {
|
||||
$this->LogMessage("module.html nicht gefunden in $file", KL_ERROR);
|
||||
return '';
|
||||
}
|
||||
// Übersetzungen einbinden
|
||||
return $this->Translate(file_get_contents($file));
|
||||
}
|
||||
|
||||
/**
|
||||
* JS-requestAction ruft das auf, um frische Daten anzufordern
|
||||
* Callback aus dem HTML: Daten neu berechnen und senden
|
||||
*/
|
||||
public function RequestAction(string $Ident, $Value): void
|
||||
{
|
||||
if ($Ident === 'update') {
|
||||
$this->Update();
|
||||
$this->UpdateData();
|
||||
} else {
|
||||
throw new Exception('Unknown Ident');
|
||||
throw new Exception("Unknown Ident");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Berechnet die Tages-Summen und sendet sie an die Visu
|
||||
* Tägliche Summen holen, Quoten berechnen und ans Frontend senden
|
||||
*/
|
||||
private function Update(): void
|
||||
protected function UpdateData(): void
|
||||
{
|
||||
$start = strtotime('today 00:00');
|
||||
$end = time();
|
||||
$prod = $this->GetDailyTotal($this->ReadPropertyInteger('VarProduction'), $start, $end);
|
||||
$cons = $this->GetDailyTotal($this->ReadPropertyInteger('VarConsumption'), $start, $end);
|
||||
$feed = $this->GetDailyTotal($this->ReadPropertyInteger('VarFeedIn'), $start, $end);
|
||||
$grid = $this->GetDailyTotal($this->ReadPropertyInteger('VarGrid'), $start, $end);
|
||||
|
||||
// Quoten berechnen
|
||||
$prodCons = $prod > 0 ? ($cons / $prod) * 100 : 0;
|
||||
$prodFeed = $prod > 0 ? ($feed / $prod) * 100 : 0;
|
||||
$consPV = $cons > 0 ? (min($cons, $prod) / $cons) * 100 : 0;
|
||||
$consGrid = $cons > 0 ? ($grid / $cons) * 100 : 0;
|
||||
$prodID = $this->ReadPropertyInteger('VarProduction');
|
||||
$consID = $this->ReadPropertyInteger('VarConsumption');
|
||||
$feedID = $this->ReadPropertyInteger('VarFeedIn');
|
||||
$gridID = $this->ReadPropertyInteger('VarGrid');
|
||||
|
||||
$prod = $this->GetDailyTotal($prodID, $start, $end);
|
||||
$cons = $this->GetDailyTotal($consID, $start, $end);
|
||||
$feed = $this->GetDailyTotal($feedID, $start, $end);
|
||||
$grid = $this->GetDailyTotal($gridID, $start, $end);
|
||||
|
||||
// Quoten in Prozent
|
||||
$prodCons = ($prod > 0) ? ($cons / $prod) * 100 : 0;
|
||||
$prodFeed = ($prod > 0) ? ($feed / $prod) * 100 : 0;
|
||||
$consPV = ($cons > 0) ? min($prod, $cons) / $cons * 100 : 0;
|
||||
$consGrid = ($cons > 0) ? ($grid / $cons) * 100 : 0;
|
||||
|
||||
$data = [
|
||||
'prodCons' => round($prodCons, 2),
|
||||
'prodFeed' => round($prodFeed, 2),
|
||||
'consPV' => round($consPV, 2),
|
||||
'consGrid' => round($consGrid, 2),
|
||||
'prodCons' => round($prodCons, 1),
|
||||
'prodFeed' => round($prodFeed, 1),
|
||||
'consPV' => round($consPV, 1),
|
||||
'consGrid' => round($consGrid, 1),
|
||||
'value' => [
|
||||
'prod' => round($prod, 2),
|
||||
'cons' => round($cons, 2),
|
||||
@@ -98,29 +84,28 @@ class Belevo_PV_Visu extends IPSModule
|
||||
'grid' => round($grid, 2)
|
||||
]
|
||||
];
|
||||
|
||||
$this->UpdateVisualizationValue($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ruft den Tages-Gesamtwert aus dem Archiv ab (tägliche Aggregation)
|
||||
* Aggregierte Tageswerte aus dem Archiv
|
||||
*/
|
||||
private function GetDailyTotal(int $varID, int $start, int $end): float
|
||||
{
|
||||
if ($varID <= 0) {
|
||||
return 0.0;
|
||||
}
|
||||
// Erste Archive-Instanz finden
|
||||
// Erstes Archivmodul finden
|
||||
$archives = IPS_GetInstanceListByModuleID('{43192F11-5B02-4B5D-9B53-8B4DBD4769E9}');
|
||||
if (empty($archives)) {
|
||||
return 0.0;
|
||||
}
|
||||
$archiveID = $archives[0];
|
||||
// AC_GetAggregatedValues( InstanzID, VarID, AggregationLevel(1=Täglich), Start, Ende, Limit=1 )
|
||||
$values = AC_GetAggregatedValues($archiveID, $varID, 1, $start, $end, 1);
|
||||
if (empty($values)) {
|
||||
return 0.0;
|
||||
}
|
||||
// Bei Counter-Variablen enthält 'Avg' die Summe der Deltas
|
||||
return (float)$values[0]['Avg'];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user