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

110 lines
3.3 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);
// MQTT Splitter (richtiger Parent)
$this->ConnectParent("{A5D7A5C5-F2BD-4DA3-9C28-DB6C24A34F3C}");
}
public function ApplyChanges()
{
parent::ApplyChanges();
$device = $this->ReadPropertyString('DeviceID');
if ($device == '') {
return;
}
// DEBUG: Was wird abonniert?
$this->SendDebug("Subscribe", "Subscribing to feedback-request/$device", 0);
$this->SendDebug("Subscribe", "Subscribing to remote-control-response/$device", 0);
// Subscription: Feedback-Request
$this->SendDataToParent(json_encode([
"DataID" => "{A339BCF8-68B7-4A41-A4EF-6A9C55A2B4E3}",
"Topic" => "feedback-request/$device",
"Retain" => false
]));
// Subscription: Remote-Control-Response
$this->SendDataToParent(json_encode([
"DataID" => "{A339BCF8-68B7-4A41-A4EF-6A9C55A2B4E3}",
"Topic" => "remote-control-response/$device",
"Retain" => false
]));
}
// Wird aufgerufen wenn MQTT-Daten hereinkommen
public function ReceiveData($JSONString)
{
$data = json_decode($JSONString, true);
$topic = $data['Topic'] ?? '';
$payload = $data['Payload'] ?? '';
$device = $this->ReadPropertyString('DeviceID');
// 1⃣ Client fragt Feedback an → Modul sendet feste Antwort zurück
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-Response empfangen
if ($topic === "remote-control-response/$device") {
$this->SendDebug("Receive", "Remote control payload received", 0);
// In Variable speichern
$this->SetValue('RemoteControlPayload', $payload);
// Optional weiterverarbeiten
$this->HandleRemoteControl($payload);
}
}
private function Publish(string $topic, string $payload)
{
$this->SendDebug("Publish", "Topic: $topic Payload: $payload", 0);
// MQTT Publish an Splitter senden
$this->SendDataToParent(json_encode([
"DataID" => "{7F7632D9-A122-4C43-8C21-A4943C1BFB79}",
"Topic" => $topic,
"Payload" => $payload,
"Retain" => false
]));
}
// Methode für spätere Aktion
protected function HandleRemoteControl(string $payload)
{
$this->SendDebug("RemoteControl", "Processing payload: $payload", 0);
// → Hier kann später custom Code rein
}
}