Files
Symcon_Belevo_Energiemanage…/Int_VGT/module.php
2025-11-13 09:07:09 +01:00

104 lines
3.1 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. 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', '');
// Variable für empfangene Remote-Control-Daten
$this->RegisterVariableString('RemoteControlPayload', 'Remote Control Payload', '', 1);
// Splitter (MQTT Server)
$this->ConnectParent("{A5D7A5C5-F2BD-4DA3-9C28-DB6C24A34F3C}");
}
public function ApplyChanges()
{
parent::ApplyChanges();
$device = $this->ReadPropertyString('DeviceID');
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
]));
}
// Wird aufgerufen wenn MQTT-Daten reinkommen
public function ReceiveData($JSONString)
{
$data = json_decode($JSONString, true);
$topic = $data['Topic'] ?? '';
$payload = $data['Payload'] ?? '';
$device = $this->ReadPropertyString('DeviceID');
// 1⃣ REQUEST von Client → fixe Antwort senden
if ($topic === "feedback-request/$device") {
$this->SendDebug("Receive", "Feedback request received", 0);
$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", json_encode($response));
return;
}
// 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)
{
$this->SendDebug("Publish", "Topic: $topic Payload: $payload", 0);
$this->SendDataToParent(json_encode([
"DataID" => "{7F7632D9-A122-4C43-8C21-A4943C1BFB79}", // Publish MQTT
"Topic" => $topic,
"Payload" => $payload,
"Retain" => false
]));
}
// Leere Methode — kannst du später programmieren
protected function HandleRemoteControl(string $payload)
{
$this->SendDebug("RemoteControl", "Received RC payload: $payload", 0);
// → HIER deinen Code später einfügen
}
}