no message

This commit is contained in:
2025-11-14 10:01:17 +01:00
parent 1e23cf94c6
commit 7de43a4240

View File

@@ -73,25 +73,45 @@ class Shelly_Parser_MQTT extends IPSModule
* ---------------------------------------------------------*/
public function RequestAction($Ident, $Value)
{
// Ident ist z.B. "BE_1_3_14_output"
// Lokale Variable aktualisieren
$varID = @IPS_GetObjectIDByIdent($Ident, $this->InstanceID);
if (!$varID) {
// Falls Variable im Ordner liegt:
foreach (IPS_GetChildrenIDs($this->InstanceID) as $folder) {
foreach (IPS_GetChildrenIDs($folder) as $cid) {
if (IPS_GetObject($cid)['ObjectIdent'] === $Ident) {
$varID = $cid;
break 2;
}
}
}
}
if ($varID) {
SetValue($varID, $Value);
}
// Prüfen ob das ein Output ist
if (str_ends_with($Ident, '_output')) {
$deviceID = substr($Ident, 0, -strlen('_output'));
// lokale Variable aktualisieren
$varID = $this->EnsureBooleanVariable($deviceID, $Ident, 'Output');
SetValue($varID, (bool)$Value);
// Shelly schalten
$topic = $deviceID . '/rpc/Switch.Set';
$payload = json_encode([
'id' => 0,
'on' => (bool)$Value
]);
$this->Publish($topic, $payload);
if ($this->ReadPropertyBoolean('Debug')) {
IPS_LogMessage("Shelly_Parser_MQTT", "Switching $deviceID -> $Value");
}
}
}
/* ---------------------------------------------------------
* RECEIVE MQTT DATA
* ---------------------------------------------------------*/
@@ -176,15 +196,12 @@ class Shelly_Parser_MQTT extends IPSModule
// Output
if (array_key_exists('output', $mapped)) {
$outID = $this->EnsureBooleanVariable(
$deviceID,
$deviceID . '_output',
'Output'
);
$this->EnableAction($deviceID . '_output');
$outID = $this->EnsureBooleanVariable($deviceID, $deviceID . '_output', 'Output');
IPS_SetVariableCustomAction($outID, $this->InstanceID);
SetValue($outID, (bool)$mapped['output']);
}
// Input (GEN4 / PRO)
if (array_key_exists('input', $mapped)) {
$inID = $this->EnsureBooleanVariable(
@@ -213,18 +230,24 @@ class Shelly_Parser_MQTT extends IPSModule
{
$folderID = $this->GetDeviceFolder($deviceID);
// Suche richtige Variable im Ordner
foreach (IPS_GetChildrenIDs($folderID) as $cid) {
$obj = IPS_GetObject($cid);
if ($obj['ObjectIdent'] === $ident && $obj['ObjectType'] === OBJECTTYPE_VARIABLE) {
return $cid;
if ($obj['ObjectIdent'] === $ident) {
return $cid; // bestehende Variable gefunden
}
}
$id = $this->RegisterVariableBoolean($ident, $name);
IPS_SetParent($id, $folderID);
return $id;
// Neue Variable anlegen
$varID = IPS_CreateVariable(0); // 0 = Boolean
IPS_SetName($varID, $name);
IPS_SetIdent($varID, $ident);
IPS_SetParent($varID, $folderID);
return $varID;
}
private function EnsureFloatVariable(string $deviceID, string $ident, string $name): int
{
$folderID = $this->GetDeviceFolder($deviceID);