no message
This commit is contained in:
@@ -73,15 +73,16 @@ class Shelly_Parser_MQTT extends IPSModule
|
|||||||
* ---------------------------------------------------------*/
|
* ---------------------------------------------------------*/
|
||||||
public function RequestAction($Ident, $Value)
|
public function RequestAction($Ident, $Value)
|
||||||
{
|
{
|
||||||
$this->SetValue($Ident, $Value);
|
// Ident ist z.B. "BE_1_3_14_output"
|
||||||
|
|
||||||
// Output: <deviceID>_output
|
|
||||||
if (str_ends_with($Ident, '_output')) {
|
if (str_ends_with($Ident, '_output')) {
|
||||||
|
|
||||||
$deviceID = substr($Ident, 0, -strlen('_output'));
|
$deviceID = substr($Ident, 0, -strlen('_output'));
|
||||||
|
|
||||||
$topic = $deviceID . '/rpc/Switch.Set';
|
// lokale Variable aktualisieren
|
||||||
|
$varID = $this->EnsureBooleanVariable($deviceID, $Ident, 'Output');
|
||||||
|
SetValue($varID, (bool)$Value);
|
||||||
|
|
||||||
|
// Shelly schalten
|
||||||
|
$topic = $deviceID . '/rpc/Switch.Set';
|
||||||
$payload = json_encode([
|
$payload = json_encode([
|
||||||
'id' => 0,
|
'id' => 0,
|
||||||
'on' => (bool)$Value
|
'on' => (bool)$Value
|
||||||
@@ -91,7 +92,6 @@ class Shelly_Parser_MQTT extends IPSModule
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------
|
/* ---------------------------------------------------------
|
||||||
* RECEIVE MQTT DATA
|
* RECEIVE MQTT DATA
|
||||||
* ---------------------------------------------------------*/
|
* ---------------------------------------------------------*/
|
||||||
@@ -141,14 +141,10 @@ class Shelly_Parser_MQTT extends IPSModule
|
|||||||
{
|
{
|
||||||
$value = ($payload === 'true' || $payload === '1');
|
$value = ($payload === 'true' || $payload === '1');
|
||||||
|
|
||||||
$this->SetValue(
|
$varID = $this->EnsureBooleanVariable($deviceID, $deviceID . '_online', 'Online');
|
||||||
$this->EnsureBooleanVariable($deviceID, $deviceID . '_online', 'Online'),
|
SetValue($varID, $value);
|
||||||
$value
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------
|
/* ---------------------------------------------------------
|
||||||
* RPC-EVENTS
|
* RPC-EVENTS
|
||||||
* ---------------------------------------------------------*/
|
* ---------------------------------------------------------*/
|
||||||
@@ -161,59 +157,55 @@ class Shelly_Parser_MQTT extends IPSModule
|
|||||||
|
|
||||||
// Shelly prüfen
|
// Shelly prüfen
|
||||||
$src = $json['src'] ?? '';
|
$src = $json['src'] ?? '';
|
||||||
if (!str_starts_with($src, 'shelly')) {
|
if (!is_string($src) || !str_starts_with($src, 'shelly')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Typ extrahieren
|
// Typ extrahieren (z.B. "1minig3", "1g4", "plusplugs", ...)
|
||||||
$type = ShellyParser::ExtractType($src);
|
$type = ShellyParser::ExtractType($src);
|
||||||
$this->SetValue(
|
$typeID = $this->EnsureStringVariable($deviceID, $deviceID . '_type', 'Typ');
|
||||||
$this->EnsureStringVariable($deviceID, $deviceID . '_type', 'Typ'),
|
SetValue($typeID, $type);
|
||||||
$type
|
|
||||||
);
|
|
||||||
|
|
||||||
// Parameter extrahieren
|
// Parameter extrahieren
|
||||||
$params = $json['params'] ?? [];
|
$params = $json['params'] ?? [];
|
||||||
|
if (!is_array($params)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$mapped = ShellyParser::MapParams($params);
|
$mapped = ShellyParser::MapParams($params);
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
if (array_key_exists('output', $mapped)) {
|
if (array_key_exists('output', $mapped)) {
|
||||||
$varID = $this->EnsureBooleanVariable(
|
$outID = $this->EnsureBooleanVariable(
|
||||||
$deviceID,
|
$deviceID,
|
||||||
$deviceID . '_output',
|
$deviceID . '_output',
|
||||||
'Output'
|
'Output'
|
||||||
);
|
);
|
||||||
$this->EnableAction($deviceID . '_output');
|
$this->EnableAction($deviceID . '_output');
|
||||||
SetValue($varID, $mapped['output']);
|
SetValue($outID, (bool)$mapped['output']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Input (GEN4 / PRO)
|
// Input (GEN4 / PRO)
|
||||||
if (array_key_exists('input', $mapped)) {
|
if (array_key_exists('input', $mapped)) {
|
||||||
SetValue(
|
$inID = $this->EnsureBooleanVariable(
|
||||||
$this->EnsureBooleanVariable(
|
|
||||||
$deviceID,
|
$deviceID,
|
||||||
$deviceID . '_input',
|
$deviceID . '_input',
|
||||||
'Input'
|
'Input'
|
||||||
),
|
|
||||||
$mapped['input']
|
|
||||||
);
|
);
|
||||||
|
SetValue($inID, (bool)$mapped['input']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Temperatur
|
// Temperatur (falls gefunden)
|
||||||
if (array_key_exists('temperature', $mapped)) {
|
if (array_key_exists('temperature', $mapped)) {
|
||||||
SetValue(
|
$tempID = $this->EnsureFloatVariable(
|
||||||
$this->EnsureFloatVariable(
|
|
||||||
$deviceID,
|
$deviceID,
|
||||||
$deviceID . '_temperature',
|
$deviceID . '_temperature',
|
||||||
'Temperatur'
|
'Temperatur'
|
||||||
),
|
|
||||||
$mapped['temperature']
|
|
||||||
);
|
);
|
||||||
|
SetValue($tempID, (float)$mapped['temperature']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------
|
/* ---------------------------------------------------------
|
||||||
* Helper für Variablen
|
* Helper für Variablen
|
||||||
* ---------------------------------------------------------*/
|
* ---------------------------------------------------------*/
|
||||||
@@ -222,7 +214,8 @@ class Shelly_Parser_MQTT extends IPSModule
|
|||||||
$folderID = $this->GetDeviceFolder($deviceID);
|
$folderID = $this->GetDeviceFolder($deviceID);
|
||||||
|
|
||||||
foreach (IPS_GetChildrenIDs($folderID) as $cid) {
|
foreach (IPS_GetChildrenIDs($folderID) as $cid) {
|
||||||
if (IPS_GetObject($cid)['ObjectIdent'] === $ident) {
|
$obj = IPS_GetObject($cid);
|
||||||
|
if ($obj['ObjectIdent'] === $ident && $obj['ObjectType'] === OBJECTTYPE_VARIABLE) {
|
||||||
return $cid;
|
return $cid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -237,7 +230,8 @@ class Shelly_Parser_MQTT extends IPSModule
|
|||||||
$folderID = $this->GetDeviceFolder($deviceID);
|
$folderID = $this->GetDeviceFolder($deviceID);
|
||||||
|
|
||||||
foreach (IPS_GetChildrenIDs($folderID) as $cid) {
|
foreach (IPS_GetChildrenIDs($folderID) as $cid) {
|
||||||
if (IPS_GetObject($cid)['ObjectIdent'] === $ident) {
|
$obj = IPS_GetObject($cid);
|
||||||
|
if ($obj['ObjectIdent'] === $ident && $obj['ObjectType'] === OBJECTTYPE_VARIABLE) {
|
||||||
return $cid;
|
return $cid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -252,7 +246,8 @@ class Shelly_Parser_MQTT extends IPSModule
|
|||||||
$folderID = $this->GetDeviceFolder($deviceID);
|
$folderID = $this->GetDeviceFolder($deviceID);
|
||||||
|
|
||||||
foreach (IPS_GetChildrenIDs($folderID) as $cid) {
|
foreach (IPS_GetChildrenIDs($folderID) as $cid) {
|
||||||
if (IPS_GetObject($cid)['ObjectIdent'] === $ident) {
|
$obj = IPS_GetObject($cid);
|
||||||
|
if ($obj['ObjectIdent'] === $ident && $obj['ObjectType'] === OBJECTTYPE_VARIABLE) {
|
||||||
return $cid;
|
return $cid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -262,17 +257,22 @@ class Shelly_Parser_MQTT extends IPSModule
|
|||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------
|
||||||
|
* Geräte-Ordner
|
||||||
|
* ---------------------------------------------------------*/
|
||||||
private function GetDeviceFolder(string $deviceID): int
|
private function GetDeviceFolder(string $deviceID): int
|
||||||
{
|
{
|
||||||
$folderIdent = 'folder_' . $deviceID;
|
$folderIdent = 'folder_' . $deviceID;
|
||||||
|
|
||||||
$folderID = @IPS_GetObjectIDByIdent($folderIdent);
|
// nur unter dieser Instanz suchen
|
||||||
if ($folderID !== false) {
|
foreach (IPS_GetChildrenIDs($this->InstanceID) as $cid) {
|
||||||
return $folderID;
|
$obj = IPS_GetObject($cid);
|
||||||
|
if ($obj['ObjectIdent'] === $folderIdent && $obj['ObjectType'] === OBJECTTYPE_CATEGORY) {
|
||||||
|
return $cid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// neu anlegen
|
||||||
$folderID = IPS_CreateCategory();
|
$folderID = IPS_CreateCategory();
|
||||||
IPS_SetParent($folderID, $this->InstanceID);
|
IPS_SetParent($folderID, $this->InstanceID);
|
||||||
IPS_SetName($folderID, $deviceID);
|
IPS_SetName($folderID, $deviceID);
|
||||||
@@ -280,8 +280,5 @@ class Shelly_Parser_MQTT extends IPSModule
|
|||||||
|
|
||||||
return $folderID;
|
return $folderID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user