RegisterPropertyString("broker_address", ""); $this->RegisterPropertyInteger("broker_port", 1883); $this->RegisterPropertyString("username", ""); $this->RegisterPropertyString("password", ""); $this->RegisterPropertyString("Topic", ""); // Nachricht-Payload-Parameter $this->RegisterPropertyInteger("msg_id", 1); $this->RegisterPropertyString("src", "user1"); $this->RegisterPropertyString("method", "Switch.Set"); $this->RegisterPropertyBoolean("switch_bool", "true"); } public function ApplyChanges() { parent::ApplyChanges(); } public function RequestAction($Ident, $Value) { switch ($Ident) { case "GetAction": $this->GetAction(); break; default: throw new Exception("Invalid action"); } } private function GetAction() { // Eigenschaften lesen $broker = $this->ReadPropertyString("broker_address"); $port = $this->ReadPropertyInteger("broker_port"); $user = $this->ReadPropertyString("username"); $pass = $this->ReadPropertyString("password"); $topic = $this->ReadPropertyString("Topic"); $msg_id = $this->ReadPropertyInteger("msg_id"); $src = $this->ReadPropertyString("src"); $method = $this->ReadPropertyString("method"); $switch_bool = $this->ReadPropertyString("switch_bool"); // JSON-Payload erstellen $payload = [ "id" => 0, "src" => $src, "method" => $method, "params" => [ "id" => $msg_id, "on" => $switch_bool ] ]; $json = json_encode($payload); // Sende an MQTTClient (Symcon MQTTClient muss existieren!) $clientID = @IPS_GetInstanceIDByName("MQTTClient", 0); // Name anpassen, falls nötig if ($clientID && IPS_InstanceExists($clientID)) { // Prüfe ob kompatibler MQTTClient if (IPS_GetInstance($clientID)['ModuleInfo']['ModuleID'] == "{C03937E3-5F86-EACA-B4A2-39A24ACF945A}") { // Senden mit interner Funktion MQTTClient_Publish($clientID, $topic, $json, 0, false); IPS_LogMessage("ShellySwitchSender", "📤 Gesendet an '$topic': $json"); return; } } // Fallback: Logging für manuelle MQTT-Sendung IPS_LogMessage("ShellySwitchSender", "⚠️ Kein gültiger MQTTClient gefunden. Bitte in der Instanz 'MQTTClient' benennen."); } } ?>