From d7738445c8ea3411442a66c1b08d4818cd590b32 Mon Sep 17 00:00:00 2001 From: DanielHaefliger Date: Fri, 28 Nov 2025 07:37:27 +0100 Subject: [PATCH] no message --- VGT_Sub/module.php | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/VGT_Sub/module.php b/VGT_Sub/module.php index d058982..d5c5d63 100644 --- a/VGT_Sub/module.php +++ b/VGT_Sub/module.php @@ -8,8 +8,10 @@ class VGT_Sub extends IPSModule { parent::Create(); + // Konfig $this->RegisterPropertyString("DeviceID", ""); + // Editable Variablen (werden in feedback-response gesendet) $this->RegisterVariableFloat("PowerProduction", "Power Production", "", 10); $this->EnableAction("PowerProduction"); @@ -28,29 +30,37 @@ class VGT_Sub extends IPSModule $this->RegisterVariableInteger("MaxSOC", "Max SOC", "", 60); $this->EnableAction("MaxSOC"); + // Remote-Control Input Variablen (nur lesen) $this->RegisterVariableFloat("RC_PowerSetpoint", "RC Power Setpoint", "", 70); $this->RegisterVariableString("RC_Strategy", "RC Strategy", "", 80); + // Parent verbinden $this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}'); } + public function ApplyChanges() { parent::ApplyChanges(); - // Child darf NICHT subscriben! + // Sicherstellen, dass Parent gesetzt ist $this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}'); } + public function RequestAction($Ident, $Value) { SetValue($this->GetIDForIdent($Ident), $Value); } + + // Eingehende Daten vom MQTT-Client public function ReceiveData($JSONString) { $data = json_decode($JSONString); + // Format wird vom MQTT-Client-Splitter geliefert: + // { "Topic": "...", "Payload": "..." } if (!isset($data->Topic) || !isset($data->Payload)) { return; } @@ -60,15 +70,18 @@ class VGT_Sub extends IPSModule $device = $this->ReadPropertyString("DeviceID"); + // Feedback-Request if ($topic === "feedback-request/" . $device) { $this->HandleFeedbackRequest(); } + // Remote-Control Request if ($topic === "remote-control-request/" . $device) { $this->HandleRemoteControlRequest($payload); } } + private function HandleFeedbackRequest() { $response = [ @@ -80,9 +93,13 @@ class VGT_Sub extends IPSModule "max_soc" => GetValue($this->GetIDForIdent("MaxSOC")) ]; - $this->SendToMQTT("feedback-response/" . $this->ReadPropertyString("DeviceID"), json_encode($response)); + $this->SendToMQTT( + "feedback-response/" . $this->ReadPropertyString("DeviceID"), + json_encode($response) + ); } + private function HandleRemoteControlRequest(string $payload) { $data = json_decode($payload, true); @@ -90,6 +107,7 @@ class VGT_Sub extends IPSModule return; } + // Werte setzen if (isset($data["power_setpoint"])) { SetValue($this->GetIDForIdent("RC_PowerSetpoint"), $data["power_setpoint"]); } @@ -98,14 +116,20 @@ class VGT_Sub extends IPSModule SetValue($this->GetIDForIdent("RC_Strategy"), $data["strategy"]); } - $this->SendToMQTT("remote-control-response/" . $this->ReadPropertyString("DeviceID"), json_encode($data)); + // Antwort zurück + $this->SendToMQTT( + "remote-control-response/" . $this->ReadPropertyString("DeviceID"), + json_encode($data) + ); } + + // MQTT Publish (korrektes Format für deinen MQTT-Client-Splitter) private function SendToMQTT(string $topic, string $payload) { $this->SendDataToParent(json_encode([ "DataID" => "{043EA491-0325-4ADD-8FC2-A30C8EEB4D3F}", - "PacketType" => 3, + "PacketType" => 3, // Publish "QualityOfService" => 0, "Retain" => false, "Topic" => $topic, @@ -113,11 +137,16 @@ class VGT_Sub extends IPSModule ])); } + public function GetConfigurationForm() { return json_encode([ "elements" => [ - [ "type" => "ValidationTextBox", "name" => "DeviceID", "caption" => "Device ID" ] + [ + "type" => "ValidationTextBox", + "name" => "DeviceID", + "caption" => "Device ID" + ] ] ]); }