no message

This commit is contained in:
dh
2025-11-14 10:30:57 +01:00
parent a6759ec95e
commit 964c882a6d
2 changed files with 76 additions and 56 deletions
+5 -4
View File
@@ -31,7 +31,7 @@ class ShellyParser
* - temperature (float, inkl. tC) * - temperature (float, inkl. tC)
*/ */
public static function MapParams(array $params): array public static function MapParams(array $params): array
{ {
$mapped = [ $mapped = [
'outputs' => [], // switch:x → output 'outputs' => [], // switch:x → output
'inputs' => [], // input:x → state oder switch:x.input 'inputs' => [], // input:x → state oder switch:x.input
@@ -51,7 +51,7 @@ class ShellyParser
$mapped['outputs'][$index] = (bool)$value['output']; $mapped['outputs'][$index] = (bool)$value['output'];
} }
// Gen4 / Pro Geräte haben input im switch // Gen4 Input in switch
if (isset($value['input'])) { if (isset($value['input'])) {
$mapped['inputs'][$index] = (bool)$value['input']; $mapped['inputs'][$index] = (bool)$value['input'];
} }
@@ -70,11 +70,12 @@ class ShellyParser
} }
} }
// Temperatur-Suche (verschachtelt) // Temperatur (verschachtelt)
self::ExtractRecursive($params, $mapped); self::ExtractRecursive($params, $mapped);
return $mapped; return $mapped;
} }
+26 -7
View File
@@ -73,22 +73,26 @@ class Shelly_Parser_MQTT extends IPSModule
* ---------------------------------------------------------*/ * ---------------------------------------------------------*/
public function RequestAction($Ident, $Value) public function RequestAction($Ident, $Value)
{ {
IPS_LogMessage("ShellyDebug", "RequestAction($Ident → $Value)");
// Dynamischer Output? z.B. BE_1_3_14_output_0
if (str_contains($Ident, '_output_')) { if (str_contains($Ident, '_output_')) {
// Lokale Variable setzen // 1) Variable im Geräte-Ordner finden & setzen
$varID = $this->FindVariableByIdent($Ident); $varID = $this->FindVariableByIdent($Ident);
if ($varID) { if ($varID) {
SetValue($varID, $Value); SetValue($varID, $Value);
} }
// device + index ermitteln // 2) Device + Switch-Index extrahieren
$parts = explode('_output_', $Ident); $parts = explode('_output_', $Ident);
$deviceID = $parts[0]; $deviceID = $parts[0];
$index = (int)$parts[1]; $index = intval($parts[1]);
// GEN3 / GEN4 / PRO → Switch.Set muss im rpc-Root gesendet werden // 3) Shelly-konformes Topic
$topic = $deviceID . '/rpc'; $topic = $deviceID . '/rpc';
// 4) Shelly-konformes Payload gemäß API-Dokumentation
$payload = json_encode([ $payload = json_encode([
"id" => 1, "id" => 1,
"src" => "ips", "src" => "ips",
@@ -99,13 +103,16 @@ class Shelly_Parser_MQTT extends IPSModule
] ]
]); ]);
IPS_LogMessage("ShellyDebug", "SEND → $topic : $payload");
// 5) Absenden
$this->Publish($topic, $payload); $this->Publish($topic, $payload);
IPS_LogMessage("Shelly_Parser_MQTT", "SEND → $topic : $payload");
return; return;
} }
}
throw new Exception("Unknown Ident: " . $Ident);
}
/* --------------------------------------------------------- /* ---------------------------------------------------------
@@ -195,7 +202,7 @@ class Shelly_Parser_MQTT extends IPSModule
$varID = $this->EnsureBooleanVariable($deviceID, $ident, $name); $varID = $this->EnsureBooleanVariable($deviceID, $ident, $name);
// Aktionsskript aktivieren für Schalten // Für Schalten in RequestAction
IPS_SetVariableCustomAction($varID, $this->InstanceID); IPS_SetVariableCustomAction($varID, $this->InstanceID);
SetValue($varID, $value); SetValue($varID, $value);
@@ -317,5 +324,17 @@ class Shelly_Parser_MQTT extends IPSModule
return 0; return 0;
} }
private function FindVariableByIdent(string $Ident)
{
foreach (IPS_GetChildrenIDs($this->InstanceID) as $folder) {
foreach (IPS_GetChildrenIDs($folder) as $cid) {
if (IPS_GetObject($cid)['ObjectIdent'] === $Ident) {
return $cid;
}
}
}
return 0;
}
} }
?> ?>