no message

This commit is contained in:
dh
2025-11-14 10:20:13 +01:00
parent 35d07da440
commit a6759ec95e
+19 -10
View File
@@ -73,32 +73,41 @@ class Shelly_Parser_MQTT extends IPSModule
* ---------------------------------------------------------*/ * ---------------------------------------------------------*/
public function RequestAction($Ident, $Value) public function RequestAction($Ident, $Value)
{ {
// Output? z.B. BE_1_3_14_output_0
if (str_contains($Ident, '_output_')) { 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); $parts = explode('_output_', $Ident);
$deviceID = $parts[0]; $deviceID = $parts[0];
$index = (int)$parts[1]; $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([ $payload = json_encode([
'id' => $index, "id" => 1,
'on' => (bool)$Value "src" => "ips",
"method" => "Switch.Set",
"params" => [
"id" => $index,
"on" => (bool)$Value
]
]); ]);
$this->Publish($topic, $payload); $this->Publish($topic, $payload);
IPS_LogMessage("Shelly_Parser_MQTT", "SEND → $topic : $payload");
return; return;
} }
// andere Variablen (falls nötig)
throw new Exception("Unknown Ident $Ident");
} }
/* --------------------------------------------------------- /* ---------------------------------------------------------
* RECEIVE MQTT DATA * RECEIVE MQTT DATA
* ---------------------------------------------------------*/ * ---------------------------------------------------------*/
@@ -295,7 +304,7 @@ class Shelly_Parser_MQTT extends IPSModule
return $folderID; return $folderID;
} }
private function FindDeviceFolder(string $Ident): int private function FindDeviceFolder(string $Ident): int
{ {
foreach (IPS_GetChildrenIDs($this->InstanceID) as $folder) { foreach (IPS_GetChildrenIDs($this->InstanceID) as $folder) {