diff --git a/Shelly_Parser_MQTT/module.php b/Shelly_Parser_MQTT/module.php index e794d2d..d6da48d 100644 --- a/Shelly_Parser_MQTT/module.php +++ b/Shelly_Parser_MQTT/module.php @@ -73,32 +73,41 @@ class Shelly_Parser_MQTT extends IPSModule * ---------------------------------------------------------*/ public function RequestAction($Ident, $Value) { - // Output? z.B. BE_1_3_14_output_0 if (str_contains($Ident, '_output_')) { - SetValue(IPS_GetObjectIDByIdent($Ident, $this->FindDeviceFolder($Ident)), $Value); + // Lokale Variable setzen + $varID = $this->FindVariableByIdent($Ident); + if ($varID) { + SetValue($varID, $Value); + } - // Device & Index extrahieren + // device + index ermitteln $parts = explode('_output_', $Ident); $deviceID = $parts[0]; $index = (int)$parts[1]; - $topic = $deviceID . '/rpc/Switch.Set'; + // GEN3 / GEN4 / PRO → Switch.Set muss im rpc-Root gesendet werden + $topic = $deviceID . '/rpc'; $payload = json_encode([ - 'id' => $index, - 'on' => (bool)$Value + "id" => 1, + "src" => "ips", + "method" => "Switch.Set", + "params" => [ + "id" => $index, + "on" => (bool)$Value + ] ]); $this->Publish($topic, $payload); + + IPS_LogMessage("Shelly_Parser_MQTT", "SEND → $topic : $payload"); return; } - - // andere Variablen (falls nötig) - throw new Exception("Unknown Ident $Ident"); } + /* --------------------------------------------------------- * RECEIVE MQTT DATA * ---------------------------------------------------------*/ @@ -295,7 +304,7 @@ class Shelly_Parser_MQTT extends IPSModule return $folderID; } - + private function FindDeviceFolder(string $Ident): int { foreach (IPS_GetChildrenIDs($this->InstanceID) as $folder) {