no message
This commit is contained in:
+57
-64
@@ -1,66 +1,59 @@
|
|||||||
{
|
{
|
||||||
"elements": [
|
"elements": [
|
||||||
{
|
{
|
||||||
"type": "ValidationTextBox",
|
"type": "ValidationTextBox",
|
||||||
"name": "TopicSuffix",
|
"name": "TopicSuffix",
|
||||||
"caption": "Topic Suffix / x"
|
"caption": "Topic Suffix / x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "SelectVariable",
|
"type": "SelectVariable",
|
||||||
"name": "ReqActionID",
|
"name": "ReqActionID",
|
||||||
"caption": "Ausgabe-Variable / RequestAction"
|
"caption": "Ausgabe-Variable / RequestAction"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "NumberSpinner",
|
"type": "SelectVariable",
|
||||||
"name": "TargetSoC",
|
"name": "SoCID",
|
||||||
"caption": "Ziel-Ladestand %",
|
"caption": "SoC Variable"
|
||||||
"minimum": 0,
|
},
|
||||||
"maximum": 100
|
{
|
||||||
},
|
"type": "SelectVariable",
|
||||||
{
|
"name": "PowerProductionID",
|
||||||
"type": "NumberSpinner",
|
"caption": "Aktuelle Leistung Variable"
|
||||||
"name": "ChargePower",
|
},
|
||||||
"caption": "Ladeleistung in W",
|
{
|
||||||
"minimum": 0,
|
"type": "NumberSpinner",
|
||||||
"maximum": 100000
|
"name": "TargetSoC",
|
||||||
},
|
"caption": "Ziel-Ladestand %",
|
||||||
{
|
"minimum": 0,
|
||||||
"type": "NumberSpinner",
|
"maximum": 100
|
||||||
"name": "DischargePower",
|
},
|
||||||
"caption": "Entladeleistung in W",
|
{
|
||||||
"minimum": 0,
|
"type": "NumberSpinner",
|
||||||
"maximum": 100000
|
"name": "ChargePower",
|
||||||
},
|
"caption": "Ladeleistung in W",
|
||||||
{
|
"minimum": 0,
|
||||||
"type": "NumberSpinner",
|
"maximum": 100000
|
||||||
"name": "MaxPowerSetpoint",
|
},
|
||||||
"caption": "Max. Power Setpoint",
|
{
|
||||||
"minimum": 0,
|
"type": "NumberSpinner",
|
||||||
"maximum": 100000
|
"name": "DischargePower",
|
||||||
}
|
"caption": "Entladeleistung in W",
|
||||||
],
|
"minimum": 0,
|
||||||
"actions": [
|
"maximum": 100000
|
||||||
{
|
},
|
||||||
"type": "Button",
|
{
|
||||||
"caption": "Topics neu abonnieren",
|
"type": "NumberSpinner",
|
||||||
"onClick": "MBSDL_Subscribe($id);"
|
"name": "MaxPowerSetpoint",
|
||||||
}
|
"caption": "Max. Power Setpoint",
|
||||||
],
|
"minimum": 0,
|
||||||
"status": [
|
"maximum": 100000
|
||||||
{
|
}
|
||||||
"code": 101,
|
],
|
||||||
"icon": "active",
|
"actions": [
|
||||||
"caption": "Instanz aktiv"
|
{
|
||||||
},
|
"type": "Button",
|
||||||
{
|
"caption": "Batterie-Steuerung testen",
|
||||||
"code": 102,
|
"onClick": "MBSDL_RunBatteryControl($id);"
|
||||||
"icon": "inactive",
|
}
|
||||||
"caption": "Topic Suffix fehlt"
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
"code": 103,
|
|
||||||
"icon": "error",
|
|
||||||
"caption": "Keine Ausgabe-Variable gewählt"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
+60
-117
@@ -9,47 +9,34 @@ class MQTTBatterySDL extends IPSModule
|
|||||||
$this->RegisterPropertyString('TopicSuffix', '');
|
$this->RegisterPropertyString('TopicSuffix', '');
|
||||||
|
|
||||||
$this->RegisterPropertyInteger('ReqActionID', 0);
|
$this->RegisterPropertyInteger('ReqActionID', 0);
|
||||||
|
$this->RegisterPropertyInteger('SoCID', 0);
|
||||||
|
$this->RegisterPropertyInteger('PowerProductionID', 0);
|
||||||
|
|
||||||
$this->RegisterPropertyInteger('TargetSoC', 50);
|
$this->RegisterPropertyInteger('TargetSoC', 50);
|
||||||
$this->RegisterPropertyInteger('ChargePower', 2500);
|
$this->RegisterPropertyInteger('ChargePower', 2500);
|
||||||
$this->RegisterPropertyInteger('DischargePower', 2500);
|
$this->RegisterPropertyInteger('DischargePower', 2500);
|
||||||
$this->RegisterPropertyInteger('MaxPowerSetpoint', 10000);
|
$this->RegisterPropertyInteger('MaxPowerSetpoint', 10000);
|
||||||
|
|
||||||
$this->RegisterVariableFloat('PowerProduction', 'Power Production', '', 10);
|
$this->RegisterVariableBoolean('IsReady', 'Is Ready', '', 10);
|
||||||
$this->RegisterVariableBoolean('IsReady', 'Is Ready', '', 20);
|
$this->RegisterVariableBoolean('IsRunning', 'Is Running', '', 20);
|
||||||
$this->RegisterVariableBoolean('IsRunning', 'Is Running', '', 30);
|
$this->RegisterVariableFloat('MinSoC', 'Min SoC', '', 30);
|
||||||
$this->RegisterVariableFloat('StateOfCharge', 'State of Charge', '', 40);
|
$this->RegisterVariableFloat('MaxSoC', 'Max SoC', '', 40);
|
||||||
$this->RegisterVariableFloat('MinSoC', 'Min SoC', '', 50);
|
|
||||||
$this->RegisterVariableFloat('MaxSoC', 'Max SoC', '', 60);
|
|
||||||
|
|
||||||
$this->RegisterVariableInteger('PowerSetpoint', 'Power Setpoint', '', 70);
|
$this->RegisterVariableInteger('PowerSetpoint', 'Power Setpoint', '', 50);
|
||||||
$this->EnableAction('PowerSetpoint');
|
$this->EnableAction('PowerSetpoint');
|
||||||
|
|
||||||
$this->RegisterVariableString('Strategy', 'Strategy', '', 80);
|
$this->RegisterVariableString('Strategy', 'Strategy', '', 60);
|
||||||
$this->EnableAction('Strategy');
|
$this->EnableAction('Strategy');
|
||||||
|
|
||||||
$this->RegisterVariableString('LastReadResponse', 'Letzte Lese-Antwort', '', 90);
|
$this->RegisterVariableString('LastReadResponse', 'Letzte Lese-Antwort', '', 70);
|
||||||
$this->RegisterVariableString('LastWriteResponse', 'Letzte Steuer-Antwort', '', 100);
|
$this->RegisterVariableString('LastWriteResponse', 'Letzte Steuer-Antwort', '', 80);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ApplyChanges()
|
public function ApplyChanges()
|
||||||
{
|
{
|
||||||
parent::ApplyChanges();
|
parent::ApplyChanges();
|
||||||
|
|
||||||
if ($this->ReadPropertyString('TopicSuffix') == '') {
|
$this->SetStatus(IS_ACTIVE);
|
||||||
$this->SetStatus(102);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->ReadPropertyInteger('ReqActionID') <= 0) {
|
|
||||||
$this->SetStatus(103);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->SetStatus(101);
|
|
||||||
$this->Subscribe();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function RequestAction($Ident, $Value)
|
public function RequestAction($Ident, $Value)
|
||||||
@@ -71,80 +58,77 @@ class MQTTBatterySDL extends IPSModule
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'Strategy':
|
case 'Strategy':
|
||||||
SetValueString($this->GetIDForIdent('Strategy'), $Value);
|
SetValueString($this->GetIDForIdent('Strategy'), (string)$Value);
|
||||||
$this->RunBatteryControl();
|
$this->RunBatteryControl();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Subscribe()
|
public function RunBatteryControl()
|
||||||
{
|
{
|
||||||
$suffix = $this->ReadPropertyString('TopicSuffix');
|
$reqActionID = $this->ReadPropertyInteger('ReqActionID');
|
||||||
|
$socID = $this->ReadPropertyInteger('SoCID');
|
||||||
|
$powerProductionID = $this->ReadPropertyInteger('PowerProductionID');
|
||||||
|
|
||||||
if ($suffix == '') {
|
if (!$this->IsValidVariable($reqActionID)) {
|
||||||
|
$this->SendDebug('RunBatteryControl', 'Keine gültige Ausgabe-Variable gewählt', 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$topics = [
|
if (!$this->IsValidVariable($socID)) {
|
||||||
'feedback-request/' . $suffix,
|
$this->SendDebug('RunBatteryControl', 'Keine gültige SoC Variable gewählt', 0);
|
||||||
'remote-control-request/' . $suffix
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($topics as $topic) {
|
|
||||||
$this->SendDataToParent(json_encode([
|
|
||||||
'DataID' => '{D6F8C9A1-2A3B-4C5D-9E0F-333333333333}',
|
|
||||||
'PacketType' => 8,
|
|
||||||
'Topic' => $topic,
|
|
||||||
'QoS' => 0
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ReceiveData($JSONString)
|
|
||||||
{
|
|
||||||
$data = json_decode($JSONString, true);
|
|
||||||
|
|
||||||
if (!is_array($data)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$topic = $data['Topic'] ?? '';
|
$strategy = GetValueString($this->GetIDForIdent('Strategy'));
|
||||||
$payload = $data['Buffer'] ?? '';
|
$setpoint = GetValue($this->GetIDForIdent('PowerSetpoint'));
|
||||||
|
$soc = GetValue($socID);
|
||||||
|
|
||||||
$suffix = $this->ReadPropertyString('TopicSuffix');
|
$targetSoC = $this->ReadPropertyInteger('TargetSoC');
|
||||||
|
$chargePower = $this->ReadPropertyInteger('ChargePower');
|
||||||
|
$dischargePower = $this->ReadPropertyInteger('DischargePower');
|
||||||
|
|
||||||
if ($topic == 'feedback-request/' . $suffix) {
|
if ($strategy == 'activate') {
|
||||||
$this->HandleReadRequest();
|
RequestAction($reqActionID, $setpoint * -1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($topic == 'remote-control-request/' . $suffix) {
|
if ($strategy == 'stop') {
|
||||||
$this->HandleRemoteControlRequest($payload);
|
RequestAction($reqActionID, 0);
|
||||||
|
|
||||||
|
if ($this->IsValidVariable($powerProductionID)) {
|
||||||
|
SetValue($powerProductionID, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((int)$soc == $targetSoC) {
|
||||||
|
RequestAction($reqActionID, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($soc < $targetSoC) {
|
||||||
|
RequestAction($reqActionID, abs($chargePower));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($soc > $targetSoC) {
|
||||||
|
RequestAction($reqActionID, abs($dischargePower) * -1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function Publish(string $topic, string $payload)
|
public function BuildReadResponse()
|
||||||
{
|
{
|
||||||
$this->SendDataToParent(json_encode([
|
$socID = $this->ReadPropertyInteger('SoCID');
|
||||||
'DataID' => '{D6F8C9A1-2A3B-4C5D-9E0F-333333333333}',
|
$powerProductionID = $this->ReadPropertyInteger('PowerProductionID');
|
||||||
'PacketType' => 3,
|
|
||||||
'Topic' => $topic,
|
|
||||||
'Payload' => $payload,
|
|
||||||
'QoS' => 0,
|
|
||||||
'Retain' => false
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function HandleReadRequest()
|
|
||||||
{
|
|
||||||
$suffix = $this->ReadPropertyString('TopicSuffix');
|
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'power_production' => GetValue($this->GetIDForIdent('PowerProduction')),
|
'power_production' => $this->IsValidVariable($powerProductionID) ? GetValue($powerProductionID) : 0,
|
||||||
'is_ready' => GetValue($this->GetIDForIdent('IsReady')),
|
'is_ready' => GetValue($this->GetIDForIdent('IsReady')),
|
||||||
'is_running' => GetValue($this->GetIDForIdent('IsRunning')),
|
'is_running' => GetValue($this->GetIDForIdent('IsRunning')),
|
||||||
'state_of_charge' => GetValue($this->GetIDForIdent('StateOfCharge')),
|
'state_of_charge' => $this->IsValidVariable($socID) ? GetValue($socID) : 0,
|
||||||
'min_soc' => GetValue($this->GetIDForIdent('MinSoC')),
|
'min_soc' => GetValue($this->GetIDForIdent('MinSoC')),
|
||||||
'max_soc' => GetValue($this->GetIDForIdent('MaxSoC'))
|
'max_soc' => GetValue($this->GetIDForIdent('MaxSoC'))
|
||||||
];
|
];
|
||||||
@@ -153,10 +137,10 @@ class MQTTBatterySDL extends IPSModule
|
|||||||
|
|
||||||
SetValueString($this->GetIDForIdent('LastReadResponse'), $json);
|
SetValueString($this->GetIDForIdent('LastReadResponse'), $json);
|
||||||
|
|
||||||
$this->Publish('feedback-response/' . $suffix, $json);
|
return $json;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function HandleRemoteControlRequest(string $payload)
|
public function HandleRemoteControlJSON(string $payload)
|
||||||
{
|
{
|
||||||
if ($payload == '') {
|
if ($payload == '') {
|
||||||
return;
|
return;
|
||||||
@@ -189,8 +173,6 @@ class MQTTBatterySDL extends IPSModule
|
|||||||
|
|
||||||
$this->RunBatteryControl();
|
$this->RunBatteryControl();
|
||||||
|
|
||||||
$suffix = $this->ReadPropertyString('TopicSuffix');
|
|
||||||
|
|
||||||
$output = [
|
$output = [
|
||||||
'power_setpoint' => GetValue($this->GetIDForIdent('PowerSetpoint')),
|
'power_setpoint' => GetValue($this->GetIDForIdent('PowerSetpoint')),
|
||||||
'strategy' => GetValueString($this->GetIDForIdent('Strategy'))
|
'strategy' => GetValueString($this->GetIDForIdent('Strategy'))
|
||||||
@@ -200,51 +182,12 @@ class MQTTBatterySDL extends IPSModule
|
|||||||
|
|
||||||
SetValueString($this->GetIDForIdent('LastWriteResponse'), $json);
|
SetValueString($this->GetIDForIdent('LastWriteResponse'), $json);
|
||||||
|
|
||||||
$this->Publish('remote-control-response/' . $suffix, $json);
|
return $json;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function RunBatteryControl()
|
private function IsValidVariable(int $id)
|
||||||
{
|
{
|
||||||
$strategy = GetValueString($this->GetIDForIdent('Strategy'));
|
return $id > 0 && IPS_ObjectExists($id) && IPS_GetObject($id)['ObjectType'] == 2;
|
||||||
$setpoint = GetValue($this->GetIDForIdent('PowerSetpoint'));
|
|
||||||
$soc = GetValue($this->GetIDForIdent('StateOfCharge'));
|
|
||||||
|
|
||||||
$targetSoC = $this->ReadPropertyInteger('TargetSoC');
|
|
||||||
$chargePower = $this->ReadPropertyInteger('ChargePower');
|
|
||||||
$dischargePower = $this->ReadPropertyInteger('DischargePower');
|
|
||||||
$reqActionID = $this->ReadPropertyInteger('ReqActionID');
|
|
||||||
|
|
||||||
if ($reqActionID <= 0 || !IPS_ObjectExists($reqActionID)) {
|
|
||||||
$this->SendDebug('RunBatteryControl', 'Keine gültige ReqActionID gewählt', 0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($strategy == 'activate') {
|
|
||||||
RequestAction($reqActionID, $setpoint * -1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($strategy == 'stop') {
|
|
||||||
RequestAction($reqActionID, 0);
|
|
||||||
SetValue($this->GetIDForIdent('PowerProduction'), 0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((int)$soc == $targetSoC) {
|
|
||||||
RequestAction($reqActionID, 0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($soc < $targetSoC) {
|
|
||||||
RequestAction($reqActionID, abs($chargePower));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($soc > $targetSoC) {
|
|
||||||
RequestAction($reqActionID, abs($dischargePower) * -1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user