no message

This commit is contained in:
2025-11-27 14:41:28 +01:00
parent 4d093bcb4d
commit 2914c0bdc8

View File

@@ -8,32 +8,32 @@ class VGT_Sub extends IPSModule
{ {
parent::Create(); parent::Create();
// Device $this->RegisterPropertyString("DeviceID", "");
$this->RegisterPropertyString('DeviceID', '');
// --- Variablen anlegen --- // --- Variablen für Feedback ---
$this->RegisterVariableFloat('PowerProduction', 'Power Production', '', 10); $this->RegisterVariableFloat("PowerProduction", "Power Production", "", 10);
$this->RegisterVariableFloat('StateOfCharge', 'State of Charge', '', 11); $this->RegisterVariableBoolean("IsReady", "Is Ready", "", 11);
$this->RegisterVariableBoolean('IsRunning', 'Is Running', '', 12); $this->RegisterVariableBoolean("IsRunning", "Is Running", "", 12);
$this->RegisterVariableBoolean('IsReady', 'Is Ready', '', 13); $this->RegisterVariableFloat("StateOfCharge", "State of Charge", "", 13);
$this->RegisterVariableFloat("MinSOC", "Min SOC", "", 14);
$this->RegisterVariableFloat("MaxSOC", "Max SOC", "", 15);
$this->RegisterVariableFloat('MinSOC', 'Min SOC', '', 20); // --- Variablen für Remote Control ---
$this->RegisterVariableFloat('MaxSOC', 'Max SOC', '', 21); $this->RegisterVariableFloat("PowerSetpoint", "Power Setpoint", "", 20);
$this->RegisterVariableString("Strategy", "Strategy", "", 21);
$this->RegisterVariableFloat('PowerSetpoint', 'Power Setpoint', '', 30); // Debug-Variablen
$this->RegisterVariableString('Strategy', 'Strategy', '', 31); $this->RegisterVariableString("FeedbackRequestPayload", "Feedback Request", "", 90);
$this->RegisterVariableString("RemoteControlPayload", "Remote Control Request", "", 91);
$this->RegisterVariableString('FeedbackRequestPayload', 'Feedback Request', '', 80); // MQTT Splitter (NUR dieser ist korrekt)
$this->RegisterVariableString('RemoteControlPayload', 'Remote Control Request', '', 81); $this->ConnectParent("{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}");
// MQTT Splitter
$this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}');
} }
public function ApplyChanges() public function ApplyChanges()
{ {
parent::ApplyChanges(); parent::ApplyChanges();
$this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}'); $this->ConnectParent("{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}");
} }
public function RequestAction($Ident, $Value) public function RequestAction($Ident, $Value)
@@ -41,22 +41,13 @@ class VGT_Sub extends IPSModule
SetValue($this->GetIDForIdent($Ident), $Value); SetValue($this->GetIDForIdent($Ident), $Value);
} }
public function GetConfigurationForm()
{
return json_encode([
"elements" => [
[ "type" => "ValidationTextBox", "name" => "DeviceID", "caption" => "Device ID" ]
]
]);
}
/* ========================================================= /* =====================================================================================
* MQTT Subscribe (kompatibel zu MQTT-Splitter) * MQTT Funktionen
* ========================================================= */ * ===================================================================================== */
private function Subscribe(string $topic) private function Subscribe(string $topic)
{ {
if (!$this->HasActiveParent()) return;
$this->SendDataToParent(json_encode([ $this->SendDataToParent(json_encode([
"DataID" => "{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}", "DataID" => "{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}",
"Buffer" => [ "Buffer" => [
@@ -66,13 +57,8 @@ class VGT_Sub extends IPSModule
])); ]));
} }
/* =========================================================
* MQTT Publish (kompatibel zu MQTT-Splitter)
* ========================================================= */
private function Publish(string $topic, string $payload) private function Publish(string $topic, string $payload)
{ {
if (!$this->HasActiveParent()) return;
$this->SendDataToParent(json_encode([ $this->SendDataToParent(json_encode([
"DataID" => "{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}", "DataID" => "{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}",
"Buffer" => [ "Buffer" => [
@@ -85,85 +71,75 @@ class VGT_Sub extends IPSModule
])); ]));
} }
/* =========================================================
* MQTT RECEIVE /* =====================================================================================
* ========================================================= */ * ReceiveData erkennt NUR das tatsächliche Splitter-Format
* ===================================================================================== */
public function ReceiveData($JSONString) public function ReceiveData($JSONString)
{ {
$data = json_decode($JSONString, true); $data = json_decode($JSONString, true);
if (!isset($data['Buffer'])) return; if (!isset($data["Buffer"])) return;
$buf = $data['Buffer']; $buf = $data["Buffer"];
$device = $this->ReadPropertyString('DeviceID');
// Wenn der MQTT-Splitter ready ist → abonnieren /* CONNECTED? → Dann subscriben */
if (isset($buf['Message']) && $buf['Message'] === "MQTT_CONNECTED") { if (isset($buf["Message"]) && $buf["Message"] === "MQTT_CONNECTED") {
if ($device !== '') {
$this->Subscribe("feedback-request/$device"); $dev = $this->ReadPropertyString("DeviceID");
$this->Subscribe("remote-control-request/$device"); if ($dev) {
$this->Subscribe("feedback-request/$dev");
$this->Subscribe("remote-control-request/$dev");
} }
return; return;
} }
// echte MQTT Nachrichten /* Normale MQTT Message */
if (!isset($buf['Topic']) || !isset($buf['Payload'])) return; if (!isset($buf["Topic"]) || !isset($buf["Payload"])) return;
$topic = $buf['Topic']; $topic = $buf["Topic"];
$payload = $buf['Payload']; $payload = $buf["Payload"];
/* --------------------------------------------------------- $device = $this->ReadPropertyString("DeviceID");
/* =====================================================================================
* FEEDBACK REQUEST * FEEDBACK REQUEST
* --------------------------------------------------------- */ * ===================================================================================== */
if ($topic === "feedback-request/$device") { if ($topic === "feedback-request/$device") {
$this->SetValue('FeedbackRequestPayload', $payload); $this->SetValue("FeedbackRequestPayload", $payload);
$power = GetValueFloat($this->GetIDForIdent('PowerProduction'));
$soc = GetValueFloat($this->GetIDForIdent('StateOfCharge'));
$run = GetValueBoolean($this->GetIDForIdent('IsRunning'));
$min = GetValueFloat($this->GetIDForIdent('MinSOC'));
$max = GetValueFloat($this->GetIDForIdent('MaxSOC'));
$isReady = ($run && $soc > $min && $soc < $max);
SetValueBoolean($this->GetIDForIdent('IsReady'), $isReady);
$response = [ $response = [
"power_production" => $power, "power_production" => GetValueFloat($this->GetIDForIdent("PowerProduction")),
"state_of_charge" => $soc, "is_ready" => GetValueBoolean($this->GetIDForIdent("IsReady")),
"is_running" => $run, "is_running" => GetValueBoolean($this->GetIDForIdent("IsRunning")),
"is_ready" => $isReady, "state_of_charge" => GetValueFloat($this->GetIDForIdent("StateOfCharge")),
"min_soc" => $min, "min_soc" => GetValueFloat($this->GetIDForIdent("MinSOC")),
"max_soc" => $max "max_soc" => GetValueFloat($this->GetIDForIdent("MaxSOC")),
]; ];
$this->Publish("feedbackresponse/$device", json_encode($response)); $this->Publish("feedback-response/$device", json_encode($response));
return; return;
} }
/* --------------------------------------------------------- /* =====================================================================================
* REMOTE CONTROL REQUEST * REMOTE CONTROL REQUEST
* --------------------------------------------------------- */ * ===================================================================================== */
if ($topic === "remote-control-request/$device") { if ($topic === "remote-control-request/$device") {
$this->SetValue('RemoteControlPayload', $payload); $this->SetValue("RemoteControlPayload", $payload);
$json = json_decode($payload, true); $json = json_decode($payload, true);
if (!is_array($json)) return; if (!is_array($json)) return;
if (isset($json["power_setpoint"])) { if (isset($json["power_setpoint"])) {
SetValueFloat( SetValueFloat($this->GetIDForIdent("PowerSetpoint"), floatval($json["power_setpoint"]));
$this->GetIDForIdent('PowerSetpoint'),
floatval($json["power_setpoint"])
);
} }
if (isset($json["strategy"])) { if (isset($json["strategy"])) {
SetValueString( SetValueString($this->GetIDForIdent("Strategy"), strval($json["strategy"]));
$this->GetIDForIdent('Strategy'),
strval($json["strategy"])
);
} }
$this->Publish("remote-control-response/$device", json_encode($json));
return; return;
} }
} }