no message
This commit is contained in:
@@ -4,44 +4,6 @@
|
|||||||
"type": "ValidationTextBox",
|
"type": "ValidationTextBox",
|
||||||
"name": "DeviceID",
|
"name": "DeviceID",
|
||||||
"caption": "Device ID"
|
"caption": "Device ID"
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"type": "NumberSpinner",
|
|
||||||
"name": "MinSOC",
|
|
||||||
"caption": "Min SOC (%)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "NumberSpinner",
|
|
||||||
"name": "MaxSOC",
|
|
||||||
"caption": "Max SOC (%)"
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"type": "SelectVariable",
|
|
||||||
"name": "VarPowerProduction",
|
|
||||||
"caption": "Variable – Power Production"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SelectVariable",
|
|
||||||
"name": "VarStateOfCharge",
|
|
||||||
"caption": "Variable – State of Charge"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SelectVariable",
|
|
||||||
"name": "VarIsRunning",
|
|
||||||
"caption": "Variable – Is Running"
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"type": "SelectVariable",
|
|
||||||
"name": "VarPositiveSetpointTarget",
|
|
||||||
"caption": "Variable – Positive Power Setpoint Target"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SelectVariable",
|
|
||||||
"name": "VarNegativeSetpointTarget",
|
|
||||||
"caption": "Variable – Negative Power Setpoint Target"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+73
-93
@@ -8,39 +8,38 @@ class VGT_Sub extends IPSModule
|
|||||||
{
|
{
|
||||||
parent::Create();
|
parent::Create();
|
||||||
|
|
||||||
// Device
|
// Device-ID
|
||||||
$this->RegisterPropertyString('DeviceID', '');
|
$this->RegisterPropertyString('DeviceID', '');
|
||||||
|
|
||||||
// Variable-Auswahl
|
// --- Variablen erstellen ---
|
||||||
$this->RegisterPropertyInteger('VarPowerProduction', 0);
|
$this->RegisterVariableFloat('PowerProduction', 'Power Production', '', 10);
|
||||||
$this->RegisterPropertyInteger('VarStateOfCharge', 0);
|
$this->RegisterVariableFloat('StateOfCharge', 'State of Charge', '', 11);
|
||||||
$this->RegisterPropertyInteger('VarIsRunning', 0);
|
$this->RegisterVariableBoolean('IsRunning', 'Is Running', '', 12);
|
||||||
$this->RegisterPropertyInteger('VarPositiveSetpointTarget', 0);
|
$this->RegisterVariableBoolean('IsReady', 'Is Ready', '', 13);
|
||||||
$this->RegisterPropertyInteger('VarNegativeSetpointTarget', 0);
|
|
||||||
|
|
||||||
// Numerische SOC-Grenzen
|
$this->RegisterVariableFloat('MinSOC', 'Min SOC', '', 20);
|
||||||
$this->RegisterPropertyFloat('MinSOC', 20.0);
|
$this->RegisterVariableFloat('MaxSOC', 'Max SOC', '', 21);
|
||||||
$this->RegisterPropertyFloat('MaxSOC', 90.0);
|
|
||||||
|
|
||||||
// Speicherung des letzten PowerSetpoints
|
// Remote Control Variablen
|
||||||
$this->RegisterPropertyFloat('LastPowerSetpoint', 0.0);
|
$this->RegisterVariableFloat('PowerSetpoint', 'Power Setpoint', '', 30);
|
||||||
|
$this->RegisterVariableString('Strategy', 'Strategy', '', 31);
|
||||||
|
|
||||||
// Anzeigevariable für Feedback Request
|
// Debug / Anzeige
|
||||||
$this->RegisterVariableString('FeedbackRequestPayload', 'Feedback Request', '', 10);
|
$this->RegisterVariableString('FeedbackRequestPayload', 'Feedback Request Payload', '', 90);
|
||||||
|
$this->RegisterVariableString('RemoteControlPayload', 'Remote Control Payload', '', 91);
|
||||||
// Anzeigevariable für Remote Control Request
|
|
||||||
$this->RegisterVariableString('RemoteControlPayload', 'Remote Control Payload', '', 20);
|
|
||||||
|
|
||||||
|
// MQTT Splitter
|
||||||
$this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}');
|
$this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}');
|
||||||
}
|
}
|
||||||
|
|
||||||
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');
|
$dev = $this->ReadPropertyString('DeviceID');
|
||||||
if ($dev != '') {
|
if ($dev !== '') {
|
||||||
$this->Subscribe("feedback-request/$dev");
|
$this->Subscribe("feedback-request/$dev");
|
||||||
$this->Subscribe("remote-control-request/$dev");
|
$this->Subscribe("remote-control-request/$dev");
|
||||||
}
|
}
|
||||||
@@ -48,38 +47,29 @@ class VGT_Sub extends IPSModule
|
|||||||
|
|
||||||
public function RequestAction($Ident, $Value)
|
public function RequestAction($Ident, $Value)
|
||||||
{
|
{
|
||||||
// Einfach akzeptieren und nichts machen
|
// Variablen schreibbar machen
|
||||||
|
SetValue($this->GetIDForIdent($Ident), $Value);
|
||||||
return true;
|
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"],
|
|
||||||
|
|
||||||
["type" => "NumberSpinner", "name" => "MinSOC", "caption" => "Min SOC (%)"],
|
|
||||||
["type" => "NumberSpinner", "name" => "MaxSOC", "caption" => "Max SOC (%)"],
|
|
||||||
|
|
||||||
["type" => "SelectVariable", "name" => "VarPowerProduction", "caption" => "Variable – Power Production"],
|
|
||||||
["type" => "SelectVariable", "name" => "VarStateOfCharge", "caption" => "Variable – State of Charge"],
|
|
||||||
["type" => "SelectVariable", "name" => "VarIsRunning", "caption" => "Variable – Is Running"],
|
|
||||||
|
|
||||||
["type" => "SelectVariable", "name" => "VarPositiveSetpointTarget", "caption" => "Variable – Positive Power Setpoint"],
|
|
||||||
["type" => "SelectVariable", "name" => "VarNegativeSetpointTarget", "caption" => "Variable – Negative Power Setpoint"]
|
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* ---------------------------------------------------------
|
||||||
* MQTT SUBSCRIBE
|
* MQTT Subscribe
|
||||||
* ----------------------------------------------------------------------*/
|
* ---------------------------------------------------------*/
|
||||||
private function Subscribe(string $topic)
|
private function Subscribe(string $topic)
|
||||||
{
|
{
|
||||||
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}",
|
||||||
@@ -88,14 +78,12 @@ class VGT_Sub extends IPSModule
|
|||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* ---------------------------------------------------------
|
||||||
* MQTT PUBLISH
|
* MQTT Publish
|
||||||
* ----------------------------------------------------------------------*/
|
* ---------------------------------------------------------*/
|
||||||
private function Publish(string $topic, string $payload)
|
private function Publish(string $topic, string $payload)
|
||||||
{
|
{
|
||||||
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}",
|
||||||
@@ -105,55 +93,51 @@ class VGT_Sub extends IPSModule
|
|||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* ---------------------------------------------------------
|
||||||
* RECEIVE MQTT
|
* RECEIVE MQTT
|
||||||
* ----------------------------------------------------------------------*/
|
* ---------------------------------------------------------*/
|
||||||
public function ReceiveData($JSONString)
|
public function ReceiveData($JSONString)
|
||||||
{
|
{
|
||||||
$data = json_decode($JSONString, true);
|
$data = json_decode($JSONString, true);
|
||||||
if (!isset($data['Type'])) {
|
|
||||||
return;
|
if (!isset($data['Type'])) return;
|
||||||
}
|
|
||||||
|
|
||||||
$type = $data['Type'];
|
$type = $data['Type'];
|
||||||
|
$topic = $data['Topic'] ?? '';
|
||||||
|
$payload = $data['Payload'] ?? '';
|
||||||
|
|
||||||
|
$device = $this->ReadPropertyString('DeviceID');
|
||||||
|
|
||||||
|
// Beim Connect Topics neu abonnieren
|
||||||
if ($type === "MQTT_CONNECTED") {
|
if ($type === "MQTT_CONNECTED") {
|
||||||
$dev = $this->ReadPropertyString('DeviceID');
|
if ($device !== '') {
|
||||||
if ($dev != '') {
|
$this->Subscribe("feedback-request/$device");
|
||||||
$this->Subscribe("feedback-request/$dev");
|
$this->Subscribe("remote-control-request/$device");
|
||||||
$this->Subscribe("remote-control-request/$dev");
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($type !== "MESSAGE") {
|
if ($type !== "MESSAGE") return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$topic = $data['Topic'];
|
/* ---------------------------------------------------------
|
||||||
$payload = $data['Payload'];
|
|
||||||
$device = $this->ReadPropertyString('DeviceID');
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------
|
|
||||||
* FEEDBACK REQUEST
|
* FEEDBACK REQUEST
|
||||||
* ------------------------------------------------------------------*/
|
* ---------------------------------------------------------*/
|
||||||
if ($topic === "feedback-request/$device") {
|
if ($topic === "feedback-request/$device") {
|
||||||
|
|
||||||
$this->SetValue('FeedbackRequestPayload', $payload);
|
$this->SetValue('FeedbackRequestPayload', $payload);
|
||||||
|
|
||||||
$varProd = $this->ReadPropertyInteger('VarPowerProduction');
|
// Variablen abrufen
|
||||||
$varSOC = $this->ReadPropertyInteger('VarStateOfCharge');
|
$power = GetValueFloat($this->GetIDForIdent('PowerProduction'));
|
||||||
$varRun = $this->ReadPropertyInteger('VarIsRunning');
|
$soc = GetValueFloat($this->GetIDForIdent('StateOfCharge'));
|
||||||
|
$run = GetValueBoolean($this->GetIDForIdent('IsRunning'));
|
||||||
|
|
||||||
$power = ($varProd ? GetValue($varProd) : 0.0);
|
$min = GetValueFloat($this->GetIDForIdent('MinSOC'));
|
||||||
$soc = ($varSOC ? GetValue($varSOC) : 0.0);
|
$max = GetValueFloat($this->GetIDForIdent('MaxSOC'));
|
||||||
$run = ($varRun ? GetValue($varRun) : false);
|
|
||||||
|
|
||||||
$min = $this->ReadPropertyFloat('MinSOC');
|
|
||||||
$max = $this->ReadPropertyFloat('MaxSOC');
|
|
||||||
|
|
||||||
$isReady = ($run && $soc > $min && $soc < $max);
|
$isReady = ($run && $soc > $min && $soc < $max);
|
||||||
|
SetValueBoolean($this->GetIDForIdent('IsReady'), $isReady);
|
||||||
|
|
||||||
|
// Antwort erstellen
|
||||||
$response = [
|
$response = [
|
||||||
"power_production" => $power,
|
"power_production" => $power,
|
||||||
"state_of_charge" => $soc,
|
"state_of_charge" => $soc,
|
||||||
@@ -163,42 +147,38 @@ class VGT_Sub extends IPSModule
|
|||||||
"max_soc" => $max
|
"max_soc" => $max
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->Publish("feedback-response/$device", json_encode($response));
|
// Publish an feedbackresponse/deviceid
|
||||||
|
$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)) {
|
if (!is_array($json)) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// power_setpoint → Float-Variable
|
||||||
if (isset($json["power_setpoint"])) {
|
if (isset($json["power_setpoint"])) {
|
||||||
$power = floatval($json["power_setpoint"]);
|
SetValueFloat(
|
||||||
IPS_SetProperty($this->InstanceID, 'LastPowerSetpoint', $power);
|
$this->GetIDForIdent('PowerSetpoint'),
|
||||||
IPS_ApplyChanges($this->InstanceID);
|
floatval($json["power_setpoint"])
|
||||||
|
);
|
||||||
// Positive oder negativ?
|
|
||||||
if ($power > 0) {
|
|
||||||
$varPos = $this->ReadPropertyInteger('VarPositiveSetpointTarget');
|
|
||||||
if ($varPos) {
|
|
||||||
SetValue($varPos, $power);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$varNeg = $this->ReadPropertyInteger('VarNegativeSetpointTarget');
|
|
||||||
if ($varNeg) {
|
|
||||||
SetValue($varNeg, $power);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->Publish("remote-control-response/$device", $payload);
|
// strategy → String-Variable
|
||||||
|
if (isset($json["strategy"])) {
|
||||||
|
SetValueString(
|
||||||
|
$this->GetIDForIdent('Strategy'),
|
||||||
|
strval($json["strategy"])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user