Skip to content

Commit

Permalink
Include percentual SoC
Browse files Browse the repository at this point in the history
  • Loading branch information
DrNiels committed Aug 30, 2024
1 parent a59e5de commit 6a7b0db
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion BatteryStorage/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public function Create()
$this->RegisterTimer('Update', 0, 'VG_Update($_IPS["TARGET"]);');

$this->RegisterTimer('Charge', 1000, 'VG_Charge($_IPS["TARGET"]);');

$this->RegisterVariableFloat('SoCPercentage', $this->Translate('SoC (Percentage)'), $profileNameCapacity);
}

public function ApplyChanges()
Expand Down Expand Up @@ -63,6 +65,7 @@ public function RequestAction($Ident, $Value)
break;
case 'SoC':
$this->SetValue('SoC', $Value);
$this->SetValue('SoCPercentage', $Value / $this->ReadPropertyFloat('Capacity'));
break;
}
if (!$this->ReadPropertyInteger('Interval')) {
Expand All @@ -86,6 +89,6 @@ public function Charge()
// As charge runs every second, we produced Consumption W/s in that time
// Convert it to kW/h
$newSoC = $this->GetValue('SoC') + ($this->GetValue('Consumption') / 60 / 60 / 1000);
$this->SetValue('SoC', max(0, min($this->ReadPropertyFloat('Capacity'), $newSoC)));
$this->RequestAction('SoC', max(0, min($this->ReadPropertyFloat('Capacity'), $newSoC)));
}
}

0 comments on commit 6a7b0db

Please sign in to comment.