Files
Symcon_Belevo_Energiemanage…/Int_VGT/module.php
2025-11-13 08:29:49 +01:00

79 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
class Int_VGT extends IPSModule
{
public function Create()
{
parent::Create();
$this->RegisterPropertyString("DeviceID", "");
}
public function ApplyChanges()
{
parent::ApplyChanges();
// mit dem Parent verbinden (MQTT Server)
$this->ConnectParent("{7F8A48DD-F8AD-4F9C-8E6B-9E4D92DDB8F9}");
if ($this->ReadPropertyString("DeviceID") == "") {
$this->SetStatus(104);
} else {
$this->SetStatus(102);
}
}
public function ReceiveData(string $JSONString)
{
$data = json_decode($JSONString, true);
$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");
if ($topic === "feedback-request/$device") {
$resp = json_encode([
"status" => "ok",
"ts" => time()
]);
$this->Publish("feedback-response/$device", $resp);
}
if ($topic === "remote-control-response/$device") {
$this->Publish("remote-control-feedback/$device", $payload);
}
}
private function Publish(string $topic, string $payload)
{
$msg = [
"DataID" => "{043EA491-84DA-4DFD-B9D4-44B4E63F23D1}",
"Topic" => $topic,
"Payload" => $payload
];
IPS_LogMessage("Int_VGT", "TX: $topic$payload");
$this->SendDataToParent(json_encode($msg));
}
public function RequestAction($Ident, $Value)
{
return;
// Erforderlich auch wenn leer
}
}
?>