no message
This commit is contained in:
+30
-25
@@ -5,38 +5,43 @@
|
|||||||
"name": "DeviceID",
|
"name": "DeviceID",
|
||||||
"caption": "Device ID"
|
"caption": "Device ID"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"type": "Label",
|
|
||||||
"caption": "Variablen zuordnen"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SelectVariable",
|
|
||||||
"name": "VarPowerProduction",
|
|
||||||
"caption": "Power Production Variable (Float)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SelectVariable",
|
|
||||||
"name": "VarStateOfCharge",
|
|
||||||
"caption": "State of Charge Variable (Float/Integer)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SelectVariable",
|
|
||||||
"name": "VarIsRunning",
|
|
||||||
"caption": "Is Running Variable (Boolean)"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "NumberSpinner",
|
"type": "NumberSpinner",
|
||||||
"name": "MinSOC",
|
"name": "MinSOC",
|
||||||
"caption": "Min SOC",
|
"caption": "Min SOC (%)"
|
||||||
"minimum": 0,
|
|
||||||
"maximum": 100
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "NumberSpinner",
|
"type": "NumberSpinner",
|
||||||
"name": "MaxSOC",
|
"name": "MaxSOC",
|
||||||
"caption": "Max SOC",
|
"caption": "Max SOC (%)"
|
||||||
"minimum": 0,
|
},
|
||||||
"maximum": 100
|
|
||||||
|
{
|
||||||
|
"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"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+125
-84
@@ -8,150 +8,191 @@ class VGT_Sub extends IPSModule
|
|||||||
{
|
{
|
||||||
parent::Create();
|
parent::Create();
|
||||||
|
|
||||||
// -------- CONFIG PROPERTIES --------
|
// Device
|
||||||
$this->RegisterPropertyString('DeviceID', '');
|
$this->RegisterPropertyString('DeviceID', '');
|
||||||
|
|
||||||
|
// Variable-Auswahl
|
||||||
$this->RegisterPropertyInteger('VarPowerProduction', 0);
|
$this->RegisterPropertyInteger('VarPowerProduction', 0);
|
||||||
$this->RegisterPropertyInteger('VarStateOfCharge', 0);
|
$this->RegisterPropertyInteger('VarStateOfCharge', 0);
|
||||||
$this->RegisterPropertyInteger('VarIsRunning', 0);
|
$this->RegisterPropertyInteger('VarIsRunning', 0);
|
||||||
|
$this->RegisterPropertyInteger('VarPositiveSetpointTarget', 0);
|
||||||
|
$this->RegisterPropertyInteger('VarNegativeSetpointTarget', 0);
|
||||||
|
|
||||||
$this->RegisterPropertyInteger('MinSOC', 20);
|
// Numerische SOC-Grenzen
|
||||||
$this->RegisterPropertyInteger('MaxSOC', 80);
|
$this->RegisterPropertyFloat('MinSOC', 20.0);
|
||||||
|
$this->RegisterPropertyFloat('MaxSOC', 90.0);
|
||||||
|
|
||||||
// -------- INTERNAL VARIABLES --------
|
// Speicherung des letzten PowerSetpoints
|
||||||
$this->RegisterVariableFloat('PowerSetpoint', 'Power Setpoint', '', 20);
|
$this->RegisterPropertyFloat('LastPowerSetpoint', 0.0);
|
||||||
$this->RegisterVariableFloat('PowerSetpointAbs', 'Power Setpoint ABS', '', 21);
|
|
||||||
$this->RegisterVariableFloat('PowerSetpointPositive', 'Power Setpoint +', '', 22);
|
|
||||||
$this->RegisterVariableFloat('PowerSetpointNegative', 'Power Setpoint -', '', 23);
|
|
||||||
|
|
||||||
$this->RegisterVariableString('Strategy', 'Strategy', '', 24);
|
// Anzeigevariable für Feedback Request
|
||||||
$this->RegisterVariableString('RemoteControlPayload', 'Remote Control Payload', '', 25);
|
$this->RegisterVariableString('FeedbackRequestPayload', 'Feedback Request', '', 10);
|
||||||
|
|
||||||
$this->RegisterVariableString('FeedbackRequestPayload', 'Feedback Request Payload', '', 40);
|
// Anzeigevariable für Remote Control Request
|
||||||
$this->RegisterVariableString('FeedbackResponsePayload', 'Feedback Response Payload', '', 41);
|
$this->RegisterVariableString('RemoteControlPayload', 'Remote Control Payload', '', 20);
|
||||||
|
|
||||||
|
$this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ApplyChanges()
|
public function ApplyChanges()
|
||||||
{
|
{
|
||||||
parent::ApplyChanges();
|
parent::ApplyChanges();
|
||||||
|
|
||||||
// Splitter verbinden
|
|
||||||
$this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}');
|
$this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}');
|
||||||
|
|
||||||
$device = $this->ReadPropertyString('DeviceID');
|
$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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function RequestAction($Ident, $Value)
|
public function GetConfigurationForm()
|
||||||
{
|
{
|
||||||
$this->SetValue($Ident, $Value);
|
return json_encode([
|
||||||
|
"elements" => [
|
||||||
|
|
||||||
|
["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
|
||||||
|
* ----------------------------------------------------------------------*/
|
||||||
private function Subscribe(string $topic)
|
private function Subscribe(string $topic)
|
||||||
{
|
{
|
||||||
if (!$this->HasActiveParent()) return;
|
if (!$this->HasActiveParent()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->SendDataToParent(json_encode([
|
$this->SendDataToParent(json_encode([
|
||||||
'DataID' => '{A1B5C433-4F17-462D-AD71-383F5BBE4F5A}',
|
"DataID" => "{A1B5C433-4F17-462D-AD71-383F5BBE4F5A}",
|
||||||
'Type' => 'SUBSCRIBE',
|
"Type" => "SUBSCRIBE",
|
||||||
'Topic' => $topic
|
"Topic" => $topic
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------
|
||||||
|
* MQTT PUBLISH
|
||||||
|
* ----------------------------------------------------------------------*/
|
||||||
private function Publish(string $topic, string $payload)
|
private function Publish(string $topic, string $payload)
|
||||||
{
|
{
|
||||||
if (!$this->HasActiveParent()) return;
|
if (!$this->HasActiveParent()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->SendDataToParent(json_encode([
|
$this->SendDataToParent(json_encode([
|
||||||
'DataID' => '{A1B5C433-4F17-462D-AD71-383F5BBE4F5A}',
|
"DataID" => "{A1B5C433-4F17-462D-AD71-383F5BBE4F5A}",
|
||||||
'Type' => 'PUBLISH',
|
"Type" => "PUBLISH",
|
||||||
'Topic' => $topic,
|
"Topic" => $topic,
|
||||||
'Payload' => $payload
|
"Payload" => $payload
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------
|
||||||
|
* RECEIVE MQTT
|
||||||
|
* ----------------------------------------------------------------------*/
|
||||||
public function ReceiveData($JSONString)
|
public function ReceiveData($JSONString)
|
||||||
{
|
{
|
||||||
$data = json_decode($JSONString, true);
|
$data = json_decode($JSONString, true);
|
||||||
if (!is_array($data)) return;
|
if (!isset($data['Type'])) {
|
||||||
if (($data['Type'] ?? '') !== 'MESSAGE') return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$topic = $data['Topic'] ?? '';
|
$type = $data['Type'];
|
||||||
$payload = $data['Payload'] ?? '';
|
|
||||||
|
|
||||||
|
if ($type === "MQTT_CONNECTED") {
|
||||||
|
$dev = $this->ReadPropertyString('DeviceID');
|
||||||
|
if ($dev != '') {
|
||||||
|
$this->Subscribe("feedback-request/$dev");
|
||||||
|
$this->Subscribe("remote-control-request/$dev");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($type !== "MESSAGE") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$topic = $data['Topic'];
|
||||||
|
$payload = $data['Payload'];
|
||||||
$device = $this->ReadPropertyString('DeviceID');
|
$device = $this->ReadPropertyString('DeviceID');
|
||||||
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);
|
||||||
|
|
||||||
$response = $this->BuildFeedbackResponse();
|
$varProd = $this->ReadPropertyInteger('VarPowerProduction');
|
||||||
$json = json_encode($response);
|
$varSOC = $this->ReadPropertyInteger('VarStateOfCharge');
|
||||||
|
$varRun = $this->ReadPropertyInteger('VarIsRunning');
|
||||||
|
|
||||||
$this->SetValue('FeedbackResponsePayload', $json);
|
$power = ($varProd ? GetValue($varProd) : 0.0);
|
||||||
$this->Publish("feedback-response/$device", $json);
|
$soc = ($varSOC ? GetValue($varSOC) : 0.0);
|
||||||
|
$run = ($varRun ? GetValue($varRun) : false);
|
||||||
|
|
||||||
|
$min = $this->ReadPropertyFloat('MinSOC');
|
||||||
|
$max = $this->ReadPropertyFloat('MaxSOC');
|
||||||
|
|
||||||
|
$isReady = ($run && $soc > $min && $soc < $max);
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
"power_production" => $power,
|
||||||
|
"state_of_charge" => $soc,
|
||||||
|
"is_running" => $run,
|
||||||
|
"is_ready" => $isReady,
|
||||||
|
"min_soc" => $min,
|
||||||
|
"max_soc" => $max
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->Publish("feedback-response/$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
|
|
||||||
if (isset($json['power_setpoint'])) {
|
|
||||||
$value = floatval($json['power_setpoint']);
|
|
||||||
$this->SetValue('PowerSetpoint', $value);
|
|
||||||
$this->SetValue('PowerSetpointAbs', abs($value));
|
|
||||||
|
|
||||||
if ($value > 0) {
|
|
||||||
$this->SetValue('PowerSetpointPositive', $value);
|
|
||||||
$this->SetValue('PowerSetpointNegative', 0);
|
|
||||||
} elseif ($value < 0) {
|
|
||||||
$this->SetValue('PowerSetpointNegative', $value);
|
|
||||||
$this->SetValue('PowerSetpointPositive', 0);
|
|
||||||
} else {
|
|
||||||
$this->SetValue('PowerSetpointPositive', 0);
|
|
||||||
$this->SetValue('PowerSetpointNegative', 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($json['strategy']))
|
if (isset($json["power_setpoint"])) {
|
||||||
$this->SetValue('Strategy', $json['strategy']);
|
$power = floatval($json["power_setpoint"]);
|
||||||
|
IPS_SetProperty($this->InstanceID, 'LastPowerSetpoint', $power);
|
||||||
|
IPS_ApplyChanges($this->InstanceID);
|
||||||
|
|
||||||
|
// 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);
|
$this->Publish("remote-control-response/$device", $payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function BuildFeedbackResponse()
|
|
||||||
{
|
|
||||||
$idProd = $this->ReadPropertyInteger('VarPowerProduction');
|
|
||||||
$idSOC = $this->ReadPropertyInteger('VarStateOfCharge');
|
|
||||||
$idRun = $this->ReadPropertyInteger('VarIsRunning');
|
|
||||||
|
|
||||||
$min = $this->ReadPropertyInteger('MinSOC');
|
|
||||||
$max = $this->ReadPropertyInteger('MaxSOC');
|
|
||||||
|
|
||||||
$soc = ($idSOC > 0) ? GetValue($idSOC) : 0;
|
|
||||||
$isRunning = ($idRun > 0) ? GetValue($idRun) : false;
|
|
||||||
|
|
||||||
$isReady = ($isRunning && ($soc >= $min) && ($soc <= $max));
|
|
||||||
|
|
||||||
return [
|
|
||||||
"power_production" => ($idProd > 0) ? GetValue($idProd) : 0,
|
|
||||||
"is_running" => $isRunning,
|
|
||||||
"state_of_charge" => $soc,
|
|
||||||
"min_soc" => $min,
|
|
||||||
"max_soc" => $max,
|
|
||||||
"is_ready" => $isReady
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user