Shelly QTT hinzugefügt
This commit is contained in:
@@ -0,0 +1,50 @@
|
|||||||
|
{
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"type": "ValidationTextBox",
|
||||||
|
"name": "broker_address",
|
||||||
|
"caption": "Broker-Adresse"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "NumberSpinner",
|
||||||
|
"name": "broker_port",
|
||||||
|
"caption": "Broker-Port"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "ValidationTextBox",
|
||||||
|
"name": "username",
|
||||||
|
"caption": "Benutzername"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "PasswordTextBox",
|
||||||
|
"name": "password",
|
||||||
|
"caption": "Passwort"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "ValidationTextBox",
|
||||||
|
"name": "Topic",
|
||||||
|
"caption": "MQTT Topic"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "NumberSpinner",
|
||||||
|
"name": "msg_id",
|
||||||
|
"caption": "Message ID"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "ValidationTextBox",
|
||||||
|
"name": "src",
|
||||||
|
"caption": "Source"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "ValidationTextBox",
|
||||||
|
"name": "method",
|
||||||
|
"caption": "Method"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SelectVariable",
|
||||||
|
"name": "switch_bool",
|
||||||
|
"caption": "Variable mit dem zu regelnden Shelly Kontakt"
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"id": "{C03937E3-5F86-EACA-B4A2-39A24ACF945A}",
|
||||||
|
"name": "Symcon_Publish_to_Shelly_MQTT",
|
||||||
|
"type": 3,
|
||||||
|
"vendor": "Belevo AG",
|
||||||
|
"aliases": [],
|
||||||
|
"parentRequirements": [],
|
||||||
|
"childRequirements": [],
|
||||||
|
"implemented": [],
|
||||||
|
"prefix": "GEF",
|
||||||
|
"url": ""
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Symcon_Publish_to_Shelly_MQTT extends IPSModule
|
||||||
|
{
|
||||||
|
public function Create()
|
||||||
|
{
|
||||||
|
parent::Create();
|
||||||
|
|
||||||
|
// MQTT-Verbindungsparameter
|
||||||
|
$this->RegisterPropertyString("broker_address", "");
|
||||||
|
$this->RegisterPropertyInteger("broker_port", 1883);
|
||||||
|
$this->RegisterPropertyString("username", "");
|
||||||
|
$this->RegisterPropertyString("password", "");
|
||||||
|
$this->RegisterPropertyString("Topic", "");
|
||||||
|
|
||||||
|
// Nachricht-Payload-Parameter
|
||||||
|
$this->RegisterPropertyInteger("msg_id", 1);
|
||||||
|
$this->RegisterPropertyString("src", "user1");
|
||||||
|
$this->RegisterPropertyString("method", "Switch.Set");
|
||||||
|
$this->RegisterPropertyBoolean("switch_bool", "");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ApplyChanges()
|
||||||
|
{
|
||||||
|
parent::ApplyChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function RequestAction($Ident, $Value)
|
||||||
|
{
|
||||||
|
switch ($Ident) {
|
||||||
|
case "GetAction":
|
||||||
|
$this->GetAction();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception("Invalid action");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function GetAction()
|
||||||
|
{
|
||||||
|
// Eigenschaften lesen
|
||||||
|
$broker = $this->ReadPropertyString("broker_address");
|
||||||
|
$port = $this->ReadPropertyInteger("broker_port");
|
||||||
|
$user = $this->ReadPropertyString("username");
|
||||||
|
$pass = $this->ReadPropertyString("password");
|
||||||
|
$topic = $this->ReadPropertyString("Topic");
|
||||||
|
|
||||||
|
$msg_id = $this->ReadPropertyInteger("msg_id");
|
||||||
|
$src = $this->ReadPropertyString("src");
|
||||||
|
$method = $this->ReadPropertyString("method");
|
||||||
|
$switch_bool = $this->ReadPropertyString("switch_bool");
|
||||||
|
// JSON-Payload erstellen
|
||||||
|
$payload = [
|
||||||
|
"id" => 0,
|
||||||
|
"src" => $src,
|
||||||
|
"method" => $method,
|
||||||
|
"params" => [
|
||||||
|
"id" => $msg_id,
|
||||||
|
"on" => $switch_bool
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$json = json_encode($payload);
|
||||||
|
|
||||||
|
// Sende an MQTTClient (Symcon MQTTClient muss existieren!)
|
||||||
|
$clientID = @IPS_GetInstanceIDByName("MQTTClient", 0); // Name anpassen, falls nötig
|
||||||
|
if ($clientID && IPS_InstanceExists($clientID)) {
|
||||||
|
// Prüfe ob kompatibler MQTTClient
|
||||||
|
if (IPS_GetInstance($clientID)['ModuleInfo']['ModuleID'] == "{C03937E3-5F86-EACA-B4A2-39A24ACF945A}") {
|
||||||
|
// Senden mit interner Funktion
|
||||||
|
MQTTClient_Publish($clientID, $topic, $json, 0, false);
|
||||||
|
IPS_LogMessage("ShellySwitchSender", "📤 Gesendet an '$topic': $json");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback: Logging für manuelle MQTT-Sendung
|
||||||
|
IPS_LogMessage("ShellySwitchSender", "⚠️ Kein gültiger MQTTClient gefunden. Bitte in der Instanz 'MQTTClient' benennen.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user