no message

This commit is contained in:
dh
2025-11-14 10:45:23 +01:00
parent 964c882a6d
commit 25225734f3
2 changed files with 83 additions and 86 deletions
+4 -8
View File
@@ -40,9 +40,7 @@ class ShellyParser
foreach ($params as $key => $value) { foreach ($params as $key => $value) {
// ----------------------------- // OUTPUTS (switch:0.output)
// OUTPUTS (switch:0 → output)
// -----------------------------
if (str_starts_with($key, 'switch:') && is_array($value)) { if (str_starts_with($key, 'switch:') && is_array($value)) {
$index = (int)substr($key, 7); $index = (int)substr($key, 7);
@@ -51,15 +49,13 @@ class ShellyParser
$mapped['outputs'][$index] = (bool)$value['output']; $mapped['outputs'][$index] = (bool)$value['output'];
} }
// Gen4 Input in switch // Gen4 / Pro input in switch
if (isset($value['input'])) { if (isset($value['input'])) {
$mapped['inputs'][$index] = (bool)$value['input']; $mapped['inputs'][$index] = (bool)$value['input'];
} }
} }
// ----------------------------- // INPUTS (input:0.state)
// INPUTS (input:0 → state)
// -----------------------------
if (str_starts_with($key, 'input:') && is_array($value)) { if (str_starts_with($key, 'input:') && is_array($value)) {
$index = (int)substr($key, 6); $index = (int)substr($key, 6);
@@ -70,7 +66,7 @@ class ShellyParser
} }
} }
// Temperatur (verschachtelt) // Temperatur tief suchen
self::ExtractRecursive($params, $mapped); self::ExtractRecursive($params, $mapped);
return $mapped; return $mapped;
+17 -16
View File
@@ -75,24 +75,23 @@ class Shelly_Parser_MQTT extends IPSModule
{ {
IPS_LogMessage("ShellyDebug", "RequestAction($Ident → $Value)"); IPS_LogMessage("ShellyDebug", "RequestAction($Ident → $Value)");
// Dynamischer Output? z.B. BE_1_3_14_output_0 // Prüfen ob es eine Output-Variable ist
if (str_contains($Ident, '_output_')) { if (str_contains($Ident, '_output_')) {
// 1) Variable im Geräte-Ordner finden & setzen // lokale Variable setzen
$varID = $this->FindVariableByIdent($Ident); $varID = $this->FindVariableByIdent($Ident);
if ($varID) { if ($varID) {
SetValue($varID, $Value); SetValue($varID, $Value);
} }
// 2) Device + Switch-Index extrahieren // device + index extrahieren
$parts = explode('_output_', $Ident); list($deviceID, $suffix) = explode('_output_', $Ident);
$deviceID = $parts[0]; $index = intval($suffix);
$index = intval($parts[1]);
// 3) Shelly-konformes Topic // Shelly-RPC Topic (wie im IPS-Shelly Modul)
$topic = $deviceID . '/rpc'; $topic = $deviceID . '/rpc';
// 4) Shelly-konformes Payload gemäß API-Dokumentation // Shelly-RPC-kompatibles JSON
$payload = json_encode([ $payload = json_encode([
"id" => 1, "id" => 1,
"src" => "ips", "src" => "ips",
@@ -105,9 +104,8 @@ class Shelly_Parser_MQTT extends IPSModule
IPS_LogMessage("ShellyDebug", "SEND → $topic : $payload"); IPS_LogMessage("ShellyDebug", "SEND → $topic : $payload");
// 5) Absenden // absenden
$this->Publish($topic, $payload); $this->Publish($topic, $payload);
return; return;
} }
@@ -202,7 +200,7 @@ class Shelly_Parser_MQTT extends IPSModule
$varID = $this->EnsureBooleanVariable($deviceID, $ident, $name); $varID = $this->EnsureBooleanVariable($deviceID, $ident, $name);
// Für Schalten in RequestAction // damit RequestAction überhaupt ausgeführt wird
IPS_SetVariableCustomAction($varID, $this->InstanceID); IPS_SetVariableCustomAction($varID, $this->InstanceID);
SetValue($varID, $value); SetValue($varID, $value);
@@ -221,6 +219,7 @@ class Shelly_Parser_MQTT extends IPSModule
SetValue($varID, $value); SetValue($varID, $value);
} }
// ----------------------------------- // -----------------------------------
// TEMPERATUR // TEMPERATUR
// ----------------------------------- // -----------------------------------
@@ -238,24 +237,25 @@ class Shelly_Parser_MQTT extends IPSModule
{ {
$folderID = $this->GetDeviceFolder($deviceID); $folderID = $this->GetDeviceFolder($deviceID);
// Suche richtige Variable im Ordner // vorhandene Variable finden
foreach (IPS_GetChildrenIDs($folderID) as $cid) { foreach (IPS_GetChildrenIDs($folderID) as $cid) {
$obj = IPS_GetObject($cid); $obj = IPS_GetObject($cid);
if ($obj['ObjectIdent'] === $ident) { if ($obj['ObjectIdent'] === $ident) {
return $cid; // bestehende Variable gefunden return $cid;
} }
} }
// Neue Variable anlegen // neue Variable erzeugen
$varID = IPS_CreateVariable(0); // 0 = Boolean $varID = IPS_CreateVariable(0); // Boolean
IPS_SetName($varID, $name);
IPS_SetIdent($varID, $ident); IPS_SetIdent($varID, $ident);
IPS_SetName($varID, $name);
IPS_SetParent($varID, $folderID); IPS_SetParent($varID, $folderID);
return $varID; return $varID;
} }
private function EnsureFloatVariable(string $deviceID, string $ident, string $name): int private function EnsureFloatVariable(string $deviceID, string $ident, string $name): int
{ {
$folderID = $this->GetDeviceFolder($deviceID); $folderID = $this->GetDeviceFolder($deviceID);
@@ -336,5 +336,6 @@ class Shelly_Parser_MQTT extends IPSModule
return 0; return 0;
} }
} }
?> ?>