no message

This commit is contained in:
2025-11-28 07:10:09 +01:00
parent 4b10bd4df5
commit 99e65337ef

View File

@@ -8,10 +8,8 @@ class VGT_Sub extends IPSModule
{
parent::Create();
// Konfig: Device-ID
$this->RegisterPropertyString("DeviceID", "");
// 6 editable values
$this->RegisterVariableFloat("PowerProduction", "Power Production", "", 10);
$this->EnableAction("PowerProduction");
@@ -30,52 +28,49 @@ class VGT_Sub extends IPSModule
$this->RegisterVariableInteger("MaxSOC", "Max SOC", "", 60);
$this->EnableAction("MaxSOC");
// Remote-control incoming (readonly)
$this->RegisterVariableFloat("RC_PowerSetpoint", "RC Power Setpoint", "", 70);
$this->RegisterVariableString("RC_Strategy", "RC Strategy", "", 80);
// Parent MQTT Splitter
$this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}');
}
public function ApplyChanges()
{
parent::ApplyChanges();
// reconnect parent
$this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}');
$device = $this->ReadPropertyString("DeviceID");
// subscribe to required topics
$topics = [
"feedback-request/" . $device,
"remote-control-request/" . $device
];
foreach ($topics as $t) {
foreach ($topics as $topic) {
$this->SendDataToParent(json_encode([
"DataID" => "{043EA491-0325-4ADD-8FC2-A30C8EEB4D3F}",
"PacketType" => 8, // SUBSCRIBE
"PacketType" => 8, // SUBSCRIBE
"QualityOfService" => 0,
"Retain" => false,
"Topic" => $t
"Topic" => $topic,
"Payload" => "" // <-- WICHTIG !!!
]));
}
}
public function RequestAction($Ident, $Value)
{
SetValue($this->GetIDForIdent($Ident), $Value);
}
public function ReceiveData($JSONString)
{
$data = json_decode($JSONString);
// expected structure:
// { "Topic": "...", "Payload": "..." }
if (!isset($data->Topic) || !isset($data->Payload)) {
return;
}
@@ -94,9 +89,7 @@ class VGT_Sub extends IPSModule
}
}
// --------------------------------------------------------------------------
// Feedback Request Response
// --------------------------------------------------------------------------
private function HandleFeedbackRequest()
{
$response = [
@@ -109,13 +102,10 @@ class VGT_Sub extends IPSModule
];
$topic = "feedback-response/" . $this->ReadPropertyString("DeviceID");
$this->SendToMQTT($topic, json_encode($response));
}
// --------------------------------------------------------------------------
// Remote-Control → write incoming values & respond
// --------------------------------------------------------------------------
private function HandleRemoteControlRequest(string $payload)
{
$data = json_decode($payload, true);
@@ -131,19 +121,16 @@ class VGT_Sub extends IPSModule
SetValue($this->GetIDForIdent("RC_Strategy"), $data["strategy"]);
}
// send back same JSON
$topic = "remote-control-response/" . $this->ReadPropertyString("DeviceID");
$this->SendToMQTT($topic, json_encode($data));
}
// --------------------------------------------------------------------------
// FINAL MQTT PUBLISH FORMAT (correct for your splitter!)
// --------------------------------------------------------------------------
private function SendToMQTT(string $topic, string $payload)
{
$this->SendDataToParent(json_encode([
"DataID" => "{043EA491-0325-4ADD-8FC2-A30C8EEB4D3F}",
"PacketType" => 3, // PUBLISH
"PacketType" => 3, // PUBLISH
"QualityOfService" => 0,
"Retain" => false,
"Topic" => $topic,
@@ -151,6 +138,7 @@ class VGT_Sub extends IPSModule
]));
}
public function GetConfigurationForm()
{
return json_encode([