diff --git a/VGT_Sub/module.json b/VGT_Sub/module.json index ebe1cb5..14d84f7 100644 --- a/VGT_Sub/module.json +++ b/VGT_Sub/module.json @@ -3,7 +3,7 @@ "name": "VGT_Sub", "type": 3, "vendor": "Belevo", - "aliases": ["VGT MQTT Client"], + "aliases": ["VGT MQTT Device"], "prefix": "VGT", "parentRequirements": [], "childRequirements": [], diff --git a/VGT_Sub/module.php b/VGT_Sub/module.php index 15c92b3..9d1d03c 100644 --- a/VGT_Sub/module.php +++ b/VGT_Sub/module.php @@ -8,13 +8,17 @@ class VGT_Sub extends IPSModule { parent::Create(); + // DeviceID $this->RegisterPropertyString('DeviceID', ''); + // Eingehende MQTT-Nachrichten $this->RegisterVariableString("InputJSON", "MQTT Input", "", 1); $this->EnableAction("InputJSON"); + // Ausgehende MQTT-Nachrichten $this->RegisterVariableString("OutputJSON", "MQTT Output", "", 2); + // Statusvariablen $this->RegisterVariableFloat('PowerProduction', 'Power Production', '', 10); $this->EnableAction('PowerProduction'); @@ -33,6 +37,7 @@ class VGT_Sub extends IPSModule $this->RegisterVariableFloat('MaxSoc', 'Max SoC', '', 15); $this->EnableAction('MaxSoc'); + // Remote-Control $this->RegisterVariableInteger('PowerSetpoint', 'Power Setpoint', '', 20); IPS_SetVariableCustomAction($this->GetIDForIdent('PowerSetpoint'), 0); @@ -43,6 +48,7 @@ class VGT_Sub extends IPSModule public function RequestAction($Ident, $Value) { if ($Ident === "InputJSON") { + SetValueString($this->GetIDForIdent("InputJSON"), $Value); $this->ProcessIncoming($Value); return; } @@ -53,21 +59,29 @@ class VGT_Sub extends IPSModule private function ProcessIncoming($jsonString) { $data = @json_decode($jsonString, true); - if (!is_array($data) || !isset($data['topic']) || !isset($data['payload'])) { + if (!is_array($data)) { return; } - $topic = $data['topic']; + if (!isset($data['topic']) || !isset($data['payload'])) { + return; + } + + $topic = $data['topic']; $payload = $data['payload']; $device = $this->ReadPropertyString('DeviceID'); + // Feedback Request if ($topic === "feedback-request/$device") { $this->SendFeedback($device); + return; } + // Remote Control Request if ($topic === "remote-control-request/$device") { - $this->ProcessRemote($device, $payload); + $this->ProcessRemoteControl($device, $payload); + return; } } @@ -91,7 +105,7 @@ class VGT_Sub extends IPSModule ); } - private function ProcessRemote($device, $payload) + private function ProcessRemoteControl($device, $payload) { $json = @json_decode($payload, true); if (!is_array($json)) {