no message

This commit is contained in:
2025-11-27 14:32:07 +01:00
parent b5f50e0e24
commit 4d093bcb4d
+29 -46
View File
@@ -8,10 +8,10 @@ class VGT_Sub extends IPSModule
{ {
parent::Create(); parent::Create();
// Device-ID // Device
$this->RegisterPropertyString('DeviceID', ''); $this->RegisterPropertyString('DeviceID', '');
// --- Variablen erstellen --- // --- Variablen anlegen ---
$this->RegisterVariableFloat('PowerProduction', 'Power Production', '', 10); $this->RegisterVariableFloat('PowerProduction', 'Power Production', '', 10);
$this->RegisterVariableFloat('StateOfCharge', 'State of Charge', '', 11); $this->RegisterVariableFloat('StateOfCharge', 'State of Charge', '', 11);
$this->RegisterVariableBoolean('IsRunning', 'Is Running', '', 12); $this->RegisterVariableBoolean('IsRunning', 'Is Running', '', 12);
@@ -20,13 +20,11 @@ class VGT_Sub extends IPSModule
$this->RegisterVariableFloat('MinSOC', 'Min SOC', '', 20); $this->RegisterVariableFloat('MinSOC', 'Min SOC', '', 20);
$this->RegisterVariableFloat('MaxSOC', 'Max SOC', '', 21); $this->RegisterVariableFloat('MaxSOC', 'Max SOC', '', 21);
// Remote Control Variablen
$this->RegisterVariableFloat('PowerSetpoint', 'Power Setpoint', '', 30); $this->RegisterVariableFloat('PowerSetpoint', 'Power Setpoint', '', 30);
$this->RegisterVariableString('Strategy', 'Strategy', '', 31); $this->RegisterVariableString('Strategy', 'Strategy', '', 31);
// Debug / Anzeige $this->RegisterVariableString('FeedbackRequestPayload', 'Feedback Request', '', 80);
$this->RegisterVariableString('FeedbackRequestPayload', 'Feedback Request Payload', '', 90); $this->RegisterVariableString('RemoteControlPayload', 'Remote Control Request', '', 81);
$this->RegisterVariableString('RemoteControlPayload', 'Remote Control Payload', '', 91);
// MQTT Splitter // MQTT Splitter
$this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}'); $this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}');
@@ -35,38 +33,26 @@ class VGT_Sub extends IPSModule
public function ApplyChanges() public function ApplyChanges()
{ {
parent::ApplyChanges(); parent::ApplyChanges();
$this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}'); $this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}');
$dev = $this->ReadPropertyString('DeviceID');
if ($dev !== '') {
$this->Subscribe("feedback-request/$dev");
$this->Subscribe("remote-control-request/$dev");
}
} }
public function RequestAction($Ident, $Value) public function RequestAction($Ident, $Value)
{ {
// Variablen schreibbar machen
SetValue($this->GetIDForIdent($Ident), $Value); SetValue($this->GetIDForIdent($Ident), $Value);
return true;
} }
/* ---------------------------------------------------------
* CONFIG FORM
* ---------------------------------------------------------*/
public function GetConfigurationForm() public function GetConfigurationForm()
{ {
return json_encode([ return json_encode([
"elements" => [ "elements" => [
["type" => "ValidationTextBox", "name" => "DeviceID", "caption" => "Device ID"] [ "type" => "ValidationTextBox", "name" => "DeviceID", "caption" => "Device ID" ]
] ]
]); ]);
} }
/* --------------------------------------------------------- /* =========================================================
* MQTT Subscribe * MQTT Subscribe (kompatibel zu MQTT-Splitter)
* ---------------------------------------------------------*/ * ========================================================= */
private function Subscribe(string $topic) private function Subscribe(string $topic)
{ {
if (!$this->HasActiveParent()) return; if (!$this->HasActiveParent()) return;
@@ -80,6 +66,9 @@ class VGT_Sub extends IPSModule
])); ]));
} }
/* =========================================================
* MQTT Publish (kompatibel zu MQTT-Splitter)
* ========================================================= */
private function Publish(string $topic, string $payload) private function Publish(string $topic, string $payload)
{ {
if (!$this->HasActiveParent()) return; if (!$this->HasActiveParent()) return;
@@ -88,31 +77,27 @@ class VGT_Sub extends IPSModule
"DataID" => "{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}", "DataID" => "{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}",
"Buffer" => [ "Buffer" => [
"Command" => "PUBLISH", "Command" => "PUBLISH",
"Topic" => $topic, "Topic" => $topic,
"Payload" => $payload, "Payload" => $payload,
"Retain" => false, "Retain" => false,
"QualityOfService" => 0 "QualityOfService" => 0
] ]
])); ]));
} }
/* --------------------------------------------------------- /* =========================================================
* RECEIVE MQTT * MQTT RECEIVE
* ---------------------------------------------------------*/ * ========================================================= */
public function ReceiveData($JSONString) public function ReceiveData($JSONString)
{ {
$data = json_decode($JSONString, true); $data = json_decode($JSONString, true);
if (!isset($data['Buffer'])) return;
if (!isset($data['Type'])) return; $buf = $data['Buffer'];
$type = $data['Type'];
$topic = $data['Topic'] ?? '';
$payload = $data['Payload'] ?? '';
$device = $this->ReadPropertyString('DeviceID'); $device = $this->ReadPropertyString('DeviceID');
// Beim Connect Topics neu abonnieren // Wenn der MQTT-Splitter ready ist → abonnieren
if ($type === "MQTT_CONNECTED") { if (isset($buf['Message']) && $buf['Message'] === "MQTT_CONNECTED") {
if ($device !== '') { if ($device !== '') {
$this->Subscribe("feedback-request/$device"); $this->Subscribe("feedback-request/$device");
$this->Subscribe("remote-control-request/$device"); $this->Subscribe("remote-control-request/$device");
@@ -120,27 +105,29 @@ class VGT_Sub extends IPSModule
return; return;
} }
if ($type !== "MESSAGE") return; // echte MQTT Nachrichten
if (!isset($buf['Topic']) || !isset($buf['Payload'])) return;
$topic = $buf['Topic'];
$payload = $buf['Payload'];
/* --------------------------------------------------------- /* ---------------------------------------------------------
* FEEDBACK REQUEST * FEEDBACK REQUEST
* ---------------------------------------------------------*/ * --------------------------------------------------------- */
if ($topic === "feedback-request/$device") { if ($topic === "feedback-request/$device") {
$this->SetValue('FeedbackRequestPayload', $payload); $this->SetValue('FeedbackRequestPayload', $payload);
// Variablen abrufen
$power = GetValueFloat($this->GetIDForIdent('PowerProduction')); $power = GetValueFloat($this->GetIDForIdent('PowerProduction'));
$soc = GetValueFloat($this->GetIDForIdent('StateOfCharge')); $soc = GetValueFloat($this->GetIDForIdent('StateOfCharge'));
$run = GetValueBoolean($this->GetIDForIdent('IsRunning')); $run = GetValueBoolean($this->GetIDForIdent('IsRunning'));
$min = GetValueFloat($this->GetIDForIdent('MinSOC')); $min = GetValueFloat($this->GetIDForIdent('MinSOC'));
$max = GetValueFloat($this->GetIDForIdent('MaxSOC')); $max = GetValueFloat($this->GetIDForIdent('MaxSOC'));
$isReady = ($run && $soc > $min && $soc < $max); $isReady = ($run && $soc > $min && $soc < $max);
SetValueBoolean($this->GetIDForIdent('IsReady'), $isReady); SetValueBoolean($this->GetIDForIdent('IsReady'), $isReady);
// Antwort erstellen
$response = [ $response = [
"power_production" => $power, "power_production" => $power,
"state_of_charge" => $soc, "state_of_charge" => $soc,
@@ -150,22 +137,19 @@ class VGT_Sub extends IPSModule
"max_soc" => $max "max_soc" => $max
]; ];
// Publish an feedbackresponse/deviceid
$this->Publish("feedbackresponse/$device", json_encode($response)); $this->Publish("feedbackresponse/$device", json_encode($response));
return; return;
} }
/* --------------------------------------------------------- /* ---------------------------------------------------------
* REMOTE CONTROL REQUEST * REMOTE CONTROL REQUEST
* ---------------------------------------------------------*/ * --------------------------------------------------------- */
if ($topic === "remote-control-request/$device") { if ($topic === "remote-control-request/$device") {
$this->SetValue('RemoteControlPayload', $payload); $this->SetValue('RemoteControlPayload', $payload);
$json = json_decode($payload, true); $json = json_decode($payload, true);
if (!is_array($json)) return; if (!is_array($json)) return;
// power_setpoint → Float-Variable
if (isset($json["power_setpoint"])) { if (isset($json["power_setpoint"])) {
SetValueFloat( SetValueFloat(
$this->GetIDForIdent('PowerSetpoint'), $this->GetIDForIdent('PowerSetpoint'),
@@ -173,7 +157,6 @@ class VGT_Sub extends IPSModule
); );
} }
// strategy → String-Variable
if (isset($json["strategy"])) { if (isset($json["strategy"])) {
SetValueString( SetValueString(
$this->GetIDForIdent('Strategy'), $this->GetIDForIdent('Strategy'),