no message

This commit is contained in:
2025-11-25 07:55:23 +01:00
parent 7983a921f5
commit 21068032f4

View File

@@ -8,9 +8,7 @@ class VGT_Sub extends IPSModule
{ {
parent::Create(); parent::Create();
// --------------------------------------------------------- // -------- CONFIG PROPERTIES --------
// CONFIG PROPERTIES (for form.json)
// ---------------------------------------------------------
$this->RegisterPropertyString('DeviceID', ''); $this->RegisterPropertyString('DeviceID', '');
$this->RegisterPropertyInteger('VarPowerProduction', 0); $this->RegisterPropertyInteger('VarPowerProduction', 0);
@@ -20,13 +18,11 @@ class VGT_Sub extends IPSModule
$this->RegisterPropertyInteger('MinSOC', 20); $this->RegisterPropertyInteger('MinSOC', 20);
$this->RegisterPropertyInteger('MaxSOC', 80); $this->RegisterPropertyInteger('MaxSOC', 80);
// --------------------------------------------------------- // -------- INTERNAL VARIABLES --------
// INTERNAL VARIABLES
// ---------------------------------------------------------
$this->RegisterVariableFloat('PowerSetpoint', 'Power Setpoint', '', 20); $this->RegisterVariableFloat('PowerSetpoint', 'Power Setpoint', '', 20);
$this->RegisterVariableFloat('PowerSetpointAbs', 'Power Setpoint (ABS)', '', 21); $this->RegisterVariableFloat('PowerSetpointAbs', 'Power Setpoint ABS', '', 21);
$this->RegisterVariableFloat('PowerSetpointPositive', 'Power Setpoint Positive', '', 22); $this->RegisterVariableFloat('PowerSetpointPositive', 'Power Setpoint +', '', 22);
$this->RegisterVariableFloat('PowerSetpointNegative', 'Power Setpoint Negative', '', 23); $this->RegisterVariableFloat('PowerSetpointNegative', 'Power Setpoint -', '', 23);
$this->RegisterVariableString('Strategy', 'Strategy', '', 24); $this->RegisterVariableString('Strategy', 'Strategy', '', 24);
$this->RegisterVariableString('RemoteControlPayload', 'Remote Control Payload', '', 25); $this->RegisterVariableString('RemoteControlPayload', 'Remote Control Payload', '', 25);
@@ -39,7 +35,7 @@ class VGT_Sub extends IPSModule
{ {
parent::ApplyChanges(); parent::ApplyChanges();
// MQTT Splitter verbinden // Splitter verbinden
$this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}'); $this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}');
$device = $this->ReadPropertyString('DeviceID'); $device = $this->ReadPropertyString('DeviceID');
@@ -49,22 +45,14 @@ class VGT_Sub extends IPSModule
} }
} }
// ---------------------------------------------------------
// REQUESTACTION (nur Setzen)
// ---------------------------------------------------------
public function RequestAction($Ident, $Value) public function RequestAction($Ident, $Value)
{ {
$this->SetValue($Ident, $Value); $this->SetValue($Ident, $Value);
} }
// --------------------------------------------------------- private function Subscribe(string $topic)
// MQTT SUBSCRIBE
// ---------------------------------------------------------
private function Subscribe(string $topic): void
{ {
if (!$this->HasActiveParent()) { if (!$this->HasActiveParent()) return;
return;
}
$this->SendDataToParent(json_encode([ $this->SendDataToParent(json_encode([
'DataID' => '{A1B5C433-4F17-462D-AD71-383F5BBE4F5A}', 'DataID' => '{A1B5C433-4F17-462D-AD71-383F5BBE4F5A}',
@@ -73,14 +61,9 @@ class VGT_Sub extends IPSModule
])); ]));
} }
// --------------------------------------------------------- private function Publish(string $topic, string $payload)
// MQTT PUBLISH
// ---------------------------------------------------------
private function Publish(string $topic, string $payload): void
{ {
if (!$this->HasActiveParent()) { if (!$this->HasActiveParent()) return;
return;
}
$this->SendDataToParent(json_encode([ $this->SendDataToParent(json_encode([
'DataID' => '{A1B5C433-4F17-462D-AD71-383F5BBE4F5A}', 'DataID' => '{A1B5C433-4F17-462D-AD71-383F5BBE4F5A}',
@@ -90,40 +73,32 @@ class VGT_Sub extends IPSModule
])); ]));
} }
// ---------------------------------------------------------
// RECEIVE MQTT DATA
// ---------------------------------------------------------
public function ReceiveData($JSONString) public function ReceiveData($JSONString)
{ {
$data = json_decode($JSONString, true); $data = json_decode($JSONString, true);
if (!is_array($data)) return; if (!is_array($data)) return;
if (($data['Type'] ?? '') !== 'MESSAGE') return; if (($data['Type'] ?? '') !== 'MESSAGE') return;
$topic = $data['Topic']; $topic = $data['Topic'] ?? '';
$payload = $data['Payload']; $payload = $data['Payload'] ?? '';
$device = $this->ReadPropertyString('DeviceID');
$device = $this->ReadPropertyString('DeviceID');
if ($device === '') return; if ($device === '') return;
// ----------------------------------------------- // ---- FEEDBACK REQUEST ----
// FEEDBACK REQUEST
// -----------------------------------------------
if ($topic === "feedback-request/$device") { if ($topic === "feedback-request/$device") {
$this->SetValue('FeedbackRequestPayload', $payload); $this->SetValue('FeedbackRequestPayload', $payload);
$reply = $this->BuildFeedbackResponse(); $response = $this->BuildFeedbackResponse();
$json = json_encode($reply); $json = json_encode($response);
$this->SetValue('FeedbackResponsePayload', $json); $this->SetValue('FeedbackResponsePayload', $json);
$this->Publish("feedback-response/$device", $json); $this->Publish("feedback-response/$device", $json);
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);
@@ -131,18 +106,17 @@ class VGT_Sub extends IPSModule
$json = json_decode($payload, true); $json = json_decode($payload, true);
if (!is_array($json)) return; if (!is_array($json)) return;
// Power Setpoint Handling // Power Setpoint
if (isset($json['power_setpoint'])) { if (isset($json['power_setpoint'])) {
$ps = floatval($json['power_setpoint']); $value = floatval($json['power_setpoint']);
$this->SetValue('PowerSetpoint', $ps); $this->SetValue('PowerSetpoint', $value);
$this->SetValue('PowerSetpointAbs', abs($value));
$this->SetValue('PowerSetpointAbs', abs($ps)); if ($value > 0) {
$this->SetValue('PowerSetpointPositive', $value);
if ($ps > 0) {
$this->SetValue('PowerSetpointPositive', $ps);
$this->SetValue('PowerSetpointNegative', 0); $this->SetValue('PowerSetpointNegative', 0);
} elseif ($ps < 0) { } elseif ($value < 0) {
$this->SetValue('PowerSetpointNegative', $ps); $this->SetValue('PowerSetpointNegative', $value);
$this->SetValue('PowerSetpointPositive', 0); $this->SetValue('PowerSetpointPositive', 0);
} else { } else {
$this->SetValue('PowerSetpointPositive', 0); $this->SetValue('PowerSetpointPositive', 0);
@@ -150,19 +124,14 @@ class VGT_Sub extends IPSModule
} }
} }
// Strategy Handling if (isset($json['strategy']))
if (isset($json['strategy'])) {
$this->SetValue('Strategy', $json['strategy']); $this->SetValue('Strategy', $json['strategy']);
}
$this->Publish("remote-control-response/$device", $payload); $this->Publish("remote-control-response/$device", $payload);
} }
} }
// --------------------------------------------------------- private function BuildFeedbackResponse()
// FEEDBACK RESPONSE BUILDER
// ---------------------------------------------------------
private function BuildFeedbackResponse(): array
{ {
$idProd = $this->ReadPropertyInteger('VarPowerProduction'); $idProd = $this->ReadPropertyInteger('VarPowerProduction');
$idSOC = $this->ReadPropertyInteger('VarStateOfCharge'); $idSOC = $this->ReadPropertyInteger('VarStateOfCharge');
@@ -171,18 +140,18 @@ class VGT_Sub extends IPSModule
$min = $this->ReadPropertyInteger('MinSOC'); $min = $this->ReadPropertyInteger('MinSOC');
$max = $this->ReadPropertyInteger('MaxSOC'); $max = $this->ReadPropertyInteger('MaxSOC');
$soc = ($idSOC > 0) ? GetValue($idSOC) : 0; $soc = ($idSOC > 0) ? GetValue($idSOC) : 0;
$isRunning = ($idRun > 0) ? GetValue($idRun) : false; $isRunning = ($idRun > 0) ? GetValue($idRun) : false;
$isReady = ($isRunning && ($soc >= $min) && ($soc <= $max)); $isReady = ($isRunning && ($soc >= $min) && ($soc <= $max));
return [ return [
'power_production' => ($idProd > 0) ? GetValue($idProd) : 0, "power_production" => ($idProd > 0) ? GetValue($idProd) : 0,
'is_running' => $isRunning, "is_running" => $isRunning,
'state_of_charge' => $soc, "state_of_charge" => $soc,
'min_soc' => $min, "min_soc" => $min,
'max_soc' => $max, "max_soc" => $max,
'is_ready' => $isReady "is_ready" => $isReady
]; ];
} }
} }