no message

This commit is contained in:
2025-11-13 09:04:15 +01:00
parent c1e989ef3c
commit d3bf44dc65
2 changed files with 68 additions and 43 deletions

View File

@@ -3,11 +3,11 @@
"name": "Int_VGT",
"type": 3,
"vendor": "Belevo",
"aliases": ["INT VGT Integration"],
"aliases": [],
"parentRequirements": [
"{7F8A48DD-F8AD-4F9C-8E6B-9E4D92DDB8F9}"
"{EE0D345A-CF31-428A-A613-06B90F6C5C57}"
],
"childRequirements": [],
"implemented": ["MQTT"],
"prefix": "INTVGT"
"implemented": [],
"prefix": "VGT"
}

View File

@@ -7,72 +7,97 @@ class Int_VGT extends IPSModule
public function Create()
{
parent::Create();
$this->RegisterPropertyString("DeviceID", "");
$this->RegisterPropertyString('DeviceID', '');
// Variable für empfangene Remote-Control-Daten
$this->RegisterVariableString('RemoteControlPayload', 'Remote Control Payload', '', 1);
// Splitter (MQTT Server)
$this->ConnectParent("{EE0D345A-CF31-428A-A613-06B90F6C5C57}");
}
public function ApplyChanges()
{
parent::ApplyChanges();
// mit dem Parent verbinden (MQTT Server)
$this->ConnectParent("{7F8A48DD-F8AD-4F9C-8E6B-9E4D92DDB8F9}");
$device = $this->ReadPropertyString('DeviceID');
if ($this->ReadPropertyString("DeviceID") == "") {
$this->SetStatus(104);
} else {
$this->SetStatus(102);
if ($device == '') {
return;
}
// Routen abonnieren
$this->SendDebug("Subscribe", "Subscribing to feedback-request/$device", 0);
$this->SendDebug("Subscribe", "Subscribing to /remote-control-response/$device", 0);
// Subscription 1
$this->SendDataToParent(json_encode([
"DataID" => "{A339BCF8-68B7-4A41-A4EF-6A9C55A2B4E3}",
"Topic" => "feedback-request/$device",
"Retain" => false
]));
// Subscription 2
$this->SendDataToParent(json_encode([
"DataID" => "{A339BCF8-68B7-4A41-A4EF-6A9C55A2B4E3}",
"Topic" => "/remote-control-response/$device",
"Retain" => false
]));
}
public function ReceiveData(string $JSONString)
// Wird aufgerufen wenn MQTT-Daten reinkommen
public function ReceiveData($JSONString)
{
$data = json_decode($JSONString, true);
$topic = $data['Topic'] ?? '';
$payload = $data['Payload'] ?? '';
$topic = $data["Topic"] ?? "";
$payload = $data["Payload"] ?? "";
IPS_LogMessage("Int_VGT", "RX: $topic$payload");
$this->HandleIncoming($topic, $payload);
}
private function HandleIncoming(string $topic, string $payload)
{
$device = $this->ReadPropertyString("DeviceID");
$device = $this->ReadPropertyString('DeviceID');
// 1⃣ REQUEST von Client → fixe Antwort senden
if ($topic === "feedback-request/$device") {
$this->SendDebug("Receive", "Feedback request received", 0);
$resp = json_encode([
"status" => "ok",
"ts" => time()
]);
$response = [
"power_production" => 123,
"is_ready" => true,
"is_running" => true,
"state_of_charge" => 50,
"min_soc" => 10,
"max_soc" => 90
];
$this->Publish("feedback-response/$device", $resp);
$this->Publish("feedback-response/$device", json_encode($response));
return;
}
if ($topic === "remote-control-response/$device") {
$this->Publish("remote-control-feedback/$device", $payload);
// 2⃣ REMOTE CONTROL PAYLOAD speichern & weiterreichen
if ($topic === "/remote-control-response/$device") {
$this->SetValue('RemoteControlPayload', $payload);
$this->HandleRemoteControl($payload);
}
}
private function Publish(string $topic, string $payload)
{
$msg = [
"DataID" => "{043EA491-84DA-4DFD-B9D4-44B4E63F23D1}",
$this->SendDebug("Publish", "Topic: $topic Payload: $payload", 0);
$this->SendDataToParent(json_encode([
"DataID" => "{7F7632D9-A122-4C43-8C21-A4943C1BFB79}", // Publish MQTT
"Topic" => $topic,
"Payload" => $payload
];
IPS_LogMessage("Int_VGT", "TX: $topic$payload");
$this->SendDataToParent(json_encode($msg));
"Payload" => $payload,
"Retain" => false
]));
}
public function RequestAction($Ident, $Value)
// Leere Methode — kannst du später programmieren
protected function HandleRemoteControl(string $payload)
{
return;
// Erforderlich auch wenn leer
$this->SendDebug("RemoteControl", "Received RC payload: $payload", 0);
// → HIER deinen Code später einfügen
}
}
?>