no message

This commit is contained in:
belevo\mh
2026-02-09 09:16:21 +01:00
parent e12c192e2d
commit e22ebf328a
2 changed files with 50 additions and 4 deletions

View File

@@ -26,8 +26,8 @@ class Bat_EV_SDL_V2 extends IPSModule
// Variablen
$this->RegisterVariableFloat("Nennleistung_Soll_EV", "Nennleistung Soll EV", "", 2);
$this->RegisterVariableFloat("Nennleistung_Soll_SDL", "Nennleistung Soll SDL", "", 3);
$this->RegisterVariableFloat("Aktuelle_Leistung_EV", "Aktuelle Leistung EV", "", 4);
$this->RegisterVariableFloat("Aktuelle_Leistung_SDL", "Aktuelle Leistung SDL", "", 5);
$this->RegisterVariableFloat("Aktuelle_Leistung_EV", "Aktuelle Leistung EV", "", 5);
$this->RegisterVariableFloat("Aktuelle_Leistung_SDL", "Aktuelle Leistung SDL", "", 4);
$this->RegisterVariableFloat("P_SDL_laden", "P SDL laden max (W)", "", 21);
$this->RegisterVariableFloat("P_SDL_entladen", "P SDL entladen max (W)", "", 22);
$this->RegisterVariableFloat("P_EV_laden", "P EV laden max (W)", "", 31);

View File

@@ -91,11 +91,57 @@ class Batterie extends IPSModule
break;
}
$this->RegisterMessageWatchMaxValues();
}
private function RegisterMessageWatchMaxValues()
{
// alte Watcher entfernen (falls sich die ausgewählten Variablen geändert haben)
$old = json_decode($this->GetBuffer("WatchMaxIDs") ?: "[]", true);
if (is_array($old)) {
foreach ($old as $oid) {
$oid = (int)$oid;
if ($oid > 0 && IPS_VariableExists($oid)) {
$this->UnregisterMessage($oid, VM_UPDATE);
}
}
}
// neue IDs aus den Properties holen (SelectVariable => Variable-ID)
$idMaxBat = (int)$this->ReadPropertyInteger("MaxBatterieleistung");
$idMaxNach = (int)$this->ReadPropertyInteger("MaxNachladen");
$new = [];
foreach ([$idMaxBat, $idMaxNach] as $id) {
if ($id > 0 && IPS_VariableExists($id)) {
$this->RegisterMessage($id, VM_UPDATE);
$new[] = $id;
}
}
$this->SetBuffer("WatchMaxIDs", json_encode($new));
}
public function MessageSink($TimeStamp, $SenderID, $Message, $Data)
{
if ($Message !== VM_UPDATE) {
return;
}
$watch = json_decode($this->GetBuffer("WatchMaxIDs") ?: "[]", true);
if (!is_array($watch)) {
return;
}
if (in_array((int)$SenderID, array_map('intval', $watch), true)) {
// sofort neu berechnen
$this->GetCurrentData($this->GetValue("Is_Peak_Shaving"));
}
}
private function GeneratePowerSteps($additionalValue)
{