no message

This commit is contained in:
dh
2025-06-18 11:00:19 +02:00
parent e009b20d98
commit 40f3d04f21
5 changed files with 106 additions and 137 deletions
+37 -48
View File
@@ -1,92 +1,81 @@
# Belevo_PV_Visu # Belevo_PV_Visu
Visualisierung des Eigenverbrauchs: Tages-Quoten für PV-Produktion vs. Einspeisung und Verbrauch vs. Netz-Bezug in IP-Symcon WebFront. Visualisierung des Eigenverbrauchs: Tages-Quoten für PV-Produktion vs. Einspeisung und
Verbrauch vs. Netz-Bezug in IP-Symcon WebFront.
### Inhaltsverzeichnis ### Inhaltsverzeichnis
1. [Funktionsumfang](#1-funktionsumfang) 1. [Funktionsumfang](#1-funktionsumfang)
2. [Voraussetzungen](#2-voraussetzungen) 2. [Voraussetzungen](#2-voraussetzungen)
3. [Software-Installation](#3-software-installation) 3. [Software-Installation](#3-software-installation)
4. [Einrichten der Instanzen in IP-Symcon](#4-einrichten-der-instanzen-in-ip-symcon) 4. [Instanz einrichten](#4-instanz-einrichten)
5. [Statusvariablen und Profile](#5-statusvariablen-und-profile) 5. [WebFront](#5-webfront)
6. [WebFront](#6-webfront) 6. [PHP-Befehlsreferenz](#6-php-befehlsreferenz)
7. [PHP-Befehlsreferenz](#7-php-befehlsreferenz)
--- ---
### 1. Funktionsumfang ### 1. Funktionsumfang
* Anzeige von Tages-Quoten (in %) - Anzeige von Tages-Quoten (in %)
* **Produktion** aufgeteilt in *Eigenverbrauch* vs. *Einspeisung* - **Produktion** → Eigenverbrauch vs. Einspeisung
* **Verbrauch** aufgeteilt in *PV-Anteil* vs. *Netz-Anteil* - **Verbrauch** → PV-Anteil vs. Netz-Anteil
* Zwei untereinander angeordnete Balkendiagramme - Zwei untereinander angeordnete Balkendiagramme
* Automatische Tages-Aggregation der Zählerwerte (kWh) - Absolute Tages-Summen (kWh) in Beschriftung
* Live-Update beim Laden der WebFront-Tile - Live-Update beim Laden der Tile
--- ---
### 2. Voraussetzungen ### 2. Voraussetzungen
- IP-Symcon **ab Version 7.1** - IP-Symcon **ab Version 7.1**
- Aktiviertes **Archiv-Modul** (für Aggregation) - Aktiviertes **Archiv-Modul**
- Vier Zähler-Variablen (Produktion, Verbrauch, Einspeisung, Netz-Bezug) mit kWh-Zählerprofil - Vier Zähler-Variablen (kWh-Profile) für Produktion, Verbrauch, Einspeisung und Netz-Bezug
--- ---
### 3. Software-Installation ### 3. Software-Installation
1. **Über den Module Store** 1. **Module Store**
- In der IPS-Konsole unter **Module → Modul Store** nach **Belevo_PV_Visu** suchen und installieren. - In der IPS-Konsole unter **Module → Modul Store** nach **Belevo_PV_Visu** suchen und installieren.
2. **Manuell per URL** 2. **Manuell per Repository**
- In **Module → Einstellungen → Repositories** folgende Git-URL hinzufügen: - Unter **Module → Einstellungen → Repositories** URL hinzufügen:
``` ```
https://github.com/DeinRepo/Belevo_PV_Visu.git https://github.com/DeinRepo/Belevo_PV_Visu.git
``` ```
- Anschließend **Module neu einlesen** und installieren. - Danach **Module neu einlesen**.
--- ---
### 4. Einrichten der Instanzen in IP-Symcon ### 4. Instanz einrichten
Unter **Instanz hinzufügen** findet man das Modul über den Schnellfilter **“Belevo_PV_Visu”**. 1. **Instanz hinzufügen** → Schnellfilter **“Belevo_PV_Visu”**
2. Im Konfig-Dialog vier Variablen auswählen:
__Konfigurationsseite__: | Property | Beschreibung |
|----------------|-------------------------------------|
| VarProduction | PV-Produktionszähler (kWh) |
| VarConsumption | Gesamtverbrauchszähler (kWh) |
| VarFeedIn | Einspeisezähler (kWh) |
| VarGrid | Netz-Bezugszähler (kWh) |
| Name | Beschreibung | 3. Speichern – die Tile zeigt sofort die aktuellen Werte an.
|------------------|----------------------------------------------------|
| **VarProduction**| Variable mit dem PV-Produktionszähler (kWh) |
| **VarConsumption**| Variable mit dem Gesamtverbrauchszähler (kWh) |
| **VarFeedIn** | Variable mit dem Einspeisezähler (kWh) |
| **VarGrid** | Variable mit dem Netz-Bezugszähler (kWh) |
> Nach dem Speichern der Konfiguration stehen die Variablen zur Live-Auswertung in der WebFront-Tile zur Verfügung.
--- ---
### 5. Statusvariablen und Profile ### 5. WebFront
Dieses Modul legt **keine** eigenen Statusvariablen an, sondern nutzt ausschließlich die vom Anwender ausgewählten Zähler. Profiles müssen für die Quoten-Balken nicht angelegt werden – sämtliche Formatierung erfolgt in der HTML-SDK. - **Tile-Typ:** „Belevo_PV_Visu“
- **Oberes Balken­diagramm:** Produktion (Grün)
- Eigenverbrauch (dunkelgrün)
- Einspeisung (hellgrün)
- **Unteres Balken­diagramm:** Verbrauch (Orange/Rot)
- PV-Anteil (orange)
- Netz-Anteil (rot)
--- ---
### 6. WebFront ### 6. PHP-Befehlsreferenz
* **Tile-Typ:** „Belevo_PV_Visu“
* Zwei Balkendiagramme untereinander
1. **Produktion** – Grün-Töne (Eigenverbrauch/Einspeisung)
2. **Verbrauch** – Orange/Rot-Töne (PV-Anteil/Netz-Anteil)
* Beschriftung zeigt absolute Tages-Summen (kWh)
* Prozentwerte als Breite der jeweiligen Balken
<img src="https://www.symcon.de/service/dokumentation/konzepte/visualisierung/webfront/#tiles" alt="WebFront Tiles" width="600"/>
---
### 7. PHP-Befehlsreferenz
Zur manuellen Aktualisierung der Visualisierung kann folgender Aufruf in einem Script verwendet werden:
```php ```php
// Aktualisiert die WebFront-Tile 'Belevo_PV_Visu' der Instanz $InstanceID // Manuelles Update der Tile anstoßen
IPS_RequestAction($InstanceID, 'update', true); IPS_RequestAction($InstanceID, 'update', true);
Dieser Befehl löst das Neuberechnen der Tages-Aggregation aus und aktualisiert die Anzeige im WebFront.
+2 -1
View File
@@ -20,5 +20,6 @@
"name": "VarGrid", "name": "VarGrid",
"caption": "Bezug Netz (kWh)" "caption": "Bezug Netz (kWh)"
} }
] ],
"actions": []
} }
+17 -23
View File
@@ -1,64 +1,58 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf-8">
<style> <style>
.bar-container { .bar-container {
width: 100%; width: 100%;
background-color: #eee; background: #eee;
border-radius: 5px; border-radius: 4px;
overflow: hidden; overflow: hidden;
height: 20px; height: 18px;
margin-bottom: 5px; margin-bottom: 8px;
} }
.bar { .bar { height: 100%; float: left; }
height: 100%; .bar-cons { background: #4CAF50; }
float: left; .bar-feed { background: #8BC34A; }
} .bar-pv { background: #FF9800; }
.bar-cons { background-color: #4CAF50; } .bar-grid { background: #FF5722; }
.bar-feed { background-color: #8BC34A; } .label {
.bar-pv { background-color: #FF9800; }
.bar-grid { background-color: #FF5722; }
.value-label {
font-size: 0.9em; font-size: 0.9em;
margin: 4px 0; margin: 4px 0;
} }
</style> </style>
</head> </head>
<body> <body>
<div class="value-label" id="prodLabel"></div> <div class="label" id="prodLabel"></div>
<div class="bar-container"> <div class="bar-container">
<div class="bar bar-cons" id="barCons"></div> <div class="bar bar-cons" id="barCons"></div>
<div class="bar bar-feed" id="barFeed"></div> <div class="bar bar-feed" id="barFeed"></div>
</div> </div>
<div class="value-label" id="consLabel"></div> <div class="label" id="consLabel"></div>
<div class="bar-container"> <div class="bar-container">
<div class="bar bar-pv" id="barPV"></div> <div class="bar bar-pv" id="barPV"></div>
<div class="bar bar-grid" id="barGrid"></div> <div class="bar bar-grid" id="barGrid"></div>
</div> </div>
<script> <script>
// Daten in die Balken und Beschriftungen einfüllen
function Apply(data) { function Apply(data) {
document.getElementById('prodLabel').innerText = document.getElementById('prodLabel').innerText =
"Produktion: " + data.value.prod + " kWh"; "Produktion: " + data.value.prod + " kWh";
document.getElementById('barCons').style.width = data.prodCons + "%"; document.getElementById('barCons').style.width = data.prodCons + "%";
document.getElementById('barFeed').style.width = data.prodFeed + "%"; document.getElementById('barFeed').style.width = data.prodFeed + "%";
document.getElementById('consLabel').innerText = document.getElementById('consLabel').innerText =
"Verbrauch: " + data.value.cons + " kWh"; "Verbrauch: " + data.value.cons + " kWh";
document.getElementById('barPV').style.width = data.consPV + "%"; document.getElementById('barPV').style.width = data.consPV + "%";
document.getElementById('barGrid').style.width = data.consGrid + "%"; document.getElementById('barGrid').style.width = data.consGrid + "%";
} }
// HTML-SDK: hier kommen die Nachrichten vom Modul an
function handleMessage(msg) { function handleMessage(msg) {
if (msg) { if (msg) Apply(msg);
Apply(msg);
}
} }
// beim Laden gleich initial Daten anfordern // Initial-Update anstoßen
requestAction('update', true); requestAction('update', true);
</script> </script>
</body> </body>
+11 -11
View File
@@ -1,12 +1,12 @@
{ {
"id": "{BD6A4CE3-E911-76B3-A91D-AB9926E86FB2}", "id": "{466A36DA-3C90-06E8-1D57-161D921B45EE}",
"name": "Belevo_PV_Visu", "name": "Belevo_PV_Visu",
"type": 3, "type": 3,
"vendor": "Belevo AG", "vendor": "BelevoAG",
"aliases": [], "aliases": [],
"parentRequirements": [], "parentRequirements": [],
"childRequirements": [], "childRequirements": [],
"implemented": [], "implemented": [],
"prefix": "GEF", "prefix": "GEF",
"url": "" "url": ""
} }
+39 -54
View File
@@ -1,11 +1,11 @@
<?php <?php declare(strict_types=1);
class Belevo_PV_Visu extends IPSModule class Belevo_PV_Visu extends IPSModule
{ {
public function Create() public function Create()
{ {
parent::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('VarProduction', 0);
$this->RegisterPropertyInteger('VarConsumption', 0); $this->RegisterPropertyInteger('VarConsumption', 0);
$this->RegisterPropertyInteger('VarFeedIn', 0); $this->RegisterPropertyInteger('VarFeedIn', 0);
@@ -14,83 +14,69 @@ class Belevo_PV_Visu extends IPSModule
$this->SetVisualizationType(3); $this->SetVisualizationType(3);
} }
public function GetConfigurationForm(): string /**
{ * Wird aufgerufen, wenn IPS das statische form.json nicht findet
return json_encode([ * (hier leer, denn wir nutzen form.json im Root)
'elements' => [ */
[ // public function GetConfigurationForm(): string
'type' => 'SelectVariable', // {
'name' => 'VarProduction', // return '';
'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 automatisch aufgerufen, wenn die Visu die Tile anfordert * Liefert das HTML-Template für die WebFront-Tile
*/ */
public function GetVisualizationTile(int $InstanceID): string public function GetVisualizationTile(int $InstanceID): string
{ {
$file = __DIR__ . '/module.html'; $file = __DIR__ . '/module.html';
if (!file_exists($file)) { if (!file_exists($file)) {
$this->LogMessage("module.html nicht gefunden in $file", KL_ERROR);
return ''; return '';
} }
// Übersetzungen einbinden
return $this->Translate(file_get_contents($file)); 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 public function RequestAction(string $Ident, $Value): void
{ {
if ($Ident === 'update') { if ($Ident === 'update') {
$this->Update(); $this->UpdateData();
} else { } 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'); $start = strtotime('today 00:00');
$end = time(); $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 $prodID = $this->ReadPropertyInteger('VarProduction');
$prodCons = $prod > 0 ? ($cons / $prod) * 100 : 0; $consID = $this->ReadPropertyInteger('VarConsumption');
$prodFeed = $prod > 0 ? ($feed / $prod) * 100 : 0; $feedID = $this->ReadPropertyInteger('VarFeedIn');
$consPV = $cons > 0 ? (min($cons, $prod) / $cons) * 100 : 0; $gridID = $this->ReadPropertyInteger('VarGrid');
$consGrid = $cons > 0 ? ($grid / $cons) * 100 : 0;
$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 = [ $data = [
'prodCons' => round($prodCons, 2), 'prodCons' => round($prodCons, 1),
'prodFeed' => round($prodFeed, 2), 'prodFeed' => round($prodFeed, 1),
'consPV' => round($consPV, 2), 'consPV' => round($consPV, 1),
'consGrid' => round($consGrid, 2), 'consGrid' => round($consGrid, 1),
'value' => [ 'value' => [
'prod' => round($prod, 2), 'prod' => round($prod, 2),
'cons' => round($cons, 2), 'cons' => round($cons, 2),
@@ -98,29 +84,28 @@ class Belevo_PV_Visu extends IPSModule
'grid' => round($grid, 2) 'grid' => round($grid, 2)
] ]
]; ];
$this->UpdateVisualizationValue($data); $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 private function GetDailyTotal(int $varID, int $start, int $end): float
{ {
if ($varID <= 0) { if ($varID <= 0) {
return 0.0; return 0.0;
} }
// Erste Archive-Instanz finden // Erstes Archivmodul finden
$archives = IPS_GetInstanceListByModuleID('{43192F11-5B02-4B5D-9B53-8B4DBD4769E9}'); $archives = IPS_GetInstanceListByModuleID('{43192F11-5B02-4B5D-9B53-8B4DBD4769E9}');
if (empty($archives)) { if (empty($archives)) {
return 0.0; return 0.0;
} }
$archiveID = $archives[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); $values = AC_GetAggregatedValues($archiveID, $varID, 1, $start, $end, 1);
if (empty($values)) { if (empty($values)) {
return 0.0; return 0.0;
} }
// Bei Counter-Variablen enthält 'Avg' die Summe der Deltas
return (float)$values[0]['Avg']; return (float)$values[0]['Avg'];
} }
} }