From 20a43c89c6f9e06b90ffb43a07a54a647bcd0793 Mon Sep 17 00:00:00 2001 From: DanielHaefliger Date: Fri, 28 Nov 2025 08:55:37 +0100 Subject: [PATCH] no message --- VGT_Sub/module.json | 29 ++++-------- VGT_Sub/module.php | 109 ++++++++++++-------------------------------- 2 files changed, 39 insertions(+), 99 deletions(-) diff --git a/VGT_Sub/module.json b/VGT_Sub/module.json index 7326b39..3c89b03 100644 --- a/VGT_Sub/module.json +++ b/VGT_Sub/module.json @@ -1,21 +1,12 @@ { - "id": "{0F001E51-E914-6444-B635-D46DDE0C3810}", - "name": "VGT_Sub", - "type": 3, - "vendor": "Belevo", - "aliases": [ - "VGT MQTT Client" - ], - "prefix": "VGT", - - "parentRequirements": [ - "{F5F433EB-61AB-470F-8964-A6322A9B88F9}" - ], - - "childRequirements": [], - "implemented": [ - "{018EF6B5-AB94-40C6-AA53-46943E824ACF}" - ], - - "version": "1.0" + "id": "{0F001E51-E914-6444-B635-D46DDE0C3810}", + "name": "VGT_Sub", + "type": 3, + "vendor": "Belevo", + "aliases": ["VGT MQTT Client"], + "prefix": "VGT", + "parentRequirements": [], + "childRequirements": [], + "implemented": ["{018EF6B5-AB94-40C6-AA53-46943E824ACF}"], + "version": "1.0" } diff --git a/VGT_Sub/module.php b/VGT_Sub/module.php index b979900..6887100 100644 --- a/VGT_Sub/module.php +++ b/VGT_Sub/module.php @@ -7,10 +7,8 @@ class VGT_Sub extends IPSModule public function Create() { parent::Create(); - $this->RegisterPropertyString('DeviceID', ''); - // Status Variablen (bearbeitbar) $this->RegisterVariableFloat('PowerProduction', 'Power Production', '', 10); $this->EnableAction('PowerProduction'); @@ -29,71 +27,37 @@ class VGT_Sub extends IPSModule $this->RegisterVariableFloat('MaxSoc', 'Max SoC', '', 15); $this->EnableAction('MaxSoc'); - // Remote-Control Variablen (readonly) - $this->RegisterVariableInteger('PowerSetpoint', 'Power Setpoint', '', 30); + $this->RegisterVariableInteger('PowerSetpoint', 'Power Setpoint', '', 20); IPS_SetVariableCustomAction($this->GetIDForIdent('PowerSetpoint'), 0); - $this->RegisterVariableString('Strategy', 'Strategy', '', 31); + $this->RegisterVariableString('Strategy', 'Strategy', '', 21); IPS_SetVariableCustomAction($this->GetIDForIdent('Strategy'), 0); } - public function ApplyChanges() - { - parent::ApplyChanges(); - - // RICHTIGER Parent: Offizieller MQTT Client - $this->ConnectParent('{3CFF0FD9-A6AF-4A9A-8C41-62E71D93AF40}'); - - $this->SubscribeTopics(); - } - - private function SubscribeTopics() - { - $device = $this->ReadPropertyString('DeviceID'); - if ($device == '') { - return; - } - - $topics = [ - "feedback-request/$device", - "remote-control-request/$device" - ]; - - foreach ($topics as $topic) { - - $this->SendDebug("SUBSCRIBE", $topic, 0); - - $this->SendDataToParent(json_encode([ - "DataID" => "{3CFF0FD9-A6AF-4A9A-8C41-62E71D93AF40}", - "PacketType" => 8, // Subscribe - "Topic" => $topic, - "QoS" => 0 - ])); - } - } - - public function ReceiveData($JSONString) + public function ForwardData($JSONString) { $data = json_decode($JSONString, true); - $topic = $data['Topic'] ?? ''; - $payload = $data['Payload'] ?? ''; - - $this->SendDebug("RX TOPIC", $topic, 0); - $this->SendDebug("RX PAYLOAD", $payload, 0); + if (!isset($data['Topic']) || !isset($data['Payload'])) { + return ''; + } + $topic = $data['Topic']; + $payload = $data['Payload']; $device = $this->ReadPropertyString('DeviceID'); if ($topic === "feedback-request/$device") { - $this->HandleFeedbackRequest($device); + $this->handleFeedback($device); } if ($topic === "remote-control-request/$device") { - $this->HandleRemoteControlRequest($device, $payload); + $this->handleRemote($device, $payload); } + + return ''; } - private function HandleFeedbackRequest($device) + private function handleFeedback($device) { $response = [ "power_production" => GetValue($this->GetIDForIdent('PowerProduction')), @@ -104,49 +68,33 @@ class VGT_Sub extends IPSModule "max_soc" => GetValue($this->GetIDForIdent('MaxSoc')) ]; - $json = json_encode($response); - $topic = "feedback-response/$device"; - - $this->SendDebug("TX FEEDBACK", $json, 0); - - $this->SendDataToParent(json_encode([ - "DataID" => "{3CFF0FD9-A6AF-4A9A-8C41-62E71D93AF40}", - "PacketType" => 3, // Publish - "Topic" => $topic, - "Payload" => $json, - "QoS" => 0, - "Retain" => false - ])); + $this->publish("feedback-response/$device", json_encode($response)); } - private function HandleRemoteControlRequest($device, $payload) + private function handleRemote($device, $payload) { - $json = @json_decode($payload, true); - if (!is_array($json)) { - $this->SendDebug("ERROR", "Ungültiges JSON empfangen!", 0); + $in = json_decode($payload, true); + if (!is_array($in)) { return; } - if (isset($json['power_setpoint'])) { - SetValue($this->GetIDForIdent('PowerSetpoint'), (int)$json['power_setpoint']); + if (isset($in['power_setpoint'])) { + SetValue($this->GetIDForIdent('PowerSetpoint'), (int)$in['power_setpoint']); } - if (isset($json['strategy'])) { - SetValueString($this->GetIDForIdent('Strategy'), (string)$json['strategy']); + if (isset($in['strategy'])) { + SetValueString($this->GetIDForIdent('Strategy'), (string)$in['strategy']); } - $replyTopic = "remote-control-response/$device"; - $replyPayload = json_encode($json); - - $this->SendDebug("TX REMOTE", $replyPayload, 0); + $this->publish("remote-control-response/$device", json_encode($in)); + } + private function publish($topic, $payload) + { $this->SendDataToParent(json_encode([ - "DataID" => "{3CFF0FD9-A6AF-4A9A-8C41-62E71D93AF40}", - "PacketType" => 3, // Publish - "Topic" => $replyTopic, - "Payload" => $replyPayload, - "QoS" => 0, - "Retain" => false + "DataID" => "{018EF6B5-AB94-40C6-AA53-46943E824ACF}", + "Topic" => $topic, + "Payload" => $payload ])); } @@ -155,4 +103,5 @@ class VGT_Sub extends IPSModule SetValue($this->GetIDForIdent($Ident), $Value); } } + ?> \ No newline at end of file