RegisterPropertyString("DeviceID", ""); // Editable Variablen (werden in feedback-response gesendet) $this->RegisterVariableFloat("PowerProduction", "Power Production", "", 10); $this->EnableAction("PowerProduction"); $this->RegisterVariableFloat("StateOfCharge", "State of Charge", "", 20); $this->EnableAction("StateOfCharge"); $this->RegisterVariableBoolean("IsRunning", "Is Running", "", 30); $this->EnableAction("IsRunning"); $this->RegisterVariableBoolean("IsReady", "Is Ready", "", 40); $this->EnableAction("IsReady"); $this->RegisterVariableInteger("MinSOC", "Min SOC", "", 50); $this->EnableAction("MinSOC"); $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(); // 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; } $topic = $data->Topic; $payload = $data->Payload; $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 = [ "power_production" => GetValue($this->GetIDForIdent("PowerProduction")), "state_of_charge" => GetValue($this->GetIDForIdent("StateOfCharge")), "is_running" => GetValue($this->GetIDForIdent("IsRunning")), "is_ready" => GetValue($this->GetIDForIdent("IsReady")), "min_soc" => GetValue($this->GetIDForIdent("MinSOC")), "max_soc" => GetValue($this->GetIDForIdent("MaxSOC")) ]; $this->SendToMQTT( "feedback-response/" . $this->ReadPropertyString("DeviceID"), json_encode($response) ); } private function HandleRemoteControlRequest(string $payload) { $data = json_decode($payload, true); if (!is_array($data)) { return; } // Werte setzen if (isset($data["power_setpoint"])) { SetValue($this->GetIDForIdent("RC_PowerSetpoint"), $data["power_setpoint"]); } if (isset($data["strategy"])) { SetValue($this->GetIDForIdent("RC_Strategy"), $data["strategy"]); } // 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, // Publish "QualityOfService" => 0, "Retain" => false, "Topic" => $topic, "Payload" => $payload ])); } public function GetConfigurationForm() { return json_encode([ "elements" => [ [ "type" => "ValidationTextBox", "name" => "DeviceID", "caption" => "Device ID" ] ] ]); } } ?>