Skip to content

Commit

Permalink
Merge pull request pkuehnel#786 from pkuehnel/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
pkuehnel authored May 1, 2023
2 parents 8437cec + 1867118 commit c791a8b
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Plugins.SolarEdge/Contracts/ICurrentValuesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public interface ICurrentValuesService
{
Task<int> GetCurrentPowerToGrid();
Task<int> GetInverterPower();
Task<int> GetHomeBatterySoc();
Task<int> GetHomeBatteryPower();
Task<int?> GetHomeBatterySoc();
Task<int?> GetHomeBatteryPower();
Task<DtoCurrentPvValues> GetCurrentPvValues();
}
4 changes: 2 additions & 2 deletions Plugins.SolarEdge/Controllers/CurrentValuesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public Task<int> GetInverterPower()
}

[HttpGet]
public Task<int> GetHomeBatterySoc()
public Task<int?> GetHomeBatterySoc()
{
return _currentValuesService.GetHomeBatterySoc();
}

[HttpGet]
public Task<int> GetHomeBatteryPower()
public Task<int?> GetHomeBatteryPower()
{
return _currentValuesService.GetHomeBatteryPower();
}
Expand Down
2 changes: 1 addition & 1 deletion Plugins.SolarEdge/Dtos/CloudApi/SiteCurrentPowerFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public class SiteCurrentPowerFlow
public Grid Grid { get; set; }
public Load Load { get; set; }
public Pv Pv { get; set; }
public Storage Storage { get; set; }
public Storage? Storage { get; set; }
}
25 changes: 18 additions & 7 deletions Plugins.SolarEdge/Services/CurrentValuesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,36 @@ private static int GetInverterPowerFromLatestValue(CloudApiValue latestValue)
return (int)latestValue.SiteCurrentPowerFlow.Pv.CurrentPower;
}

public async Task<int> GetHomeBatterySoc()
public async Task<int?> GetHomeBatterySoc()
{
_logger.LogTrace("{method}()", nameof(GetHomeBatterySoc));
var latestValue = await GetLatestValue().ConfigureAwait(false);

return GetHomeBatterySocFromLatestValue(latestValue);
}

private static int GetHomeBatterySocFromLatestValue(CloudApiValue latestValue)
private static int? GetHomeBatterySocFromLatestValue(CloudApiValue latestValue)
{
if (latestValue.SiteCurrentPowerFlow.Storage == null)
{
return null;
}
return latestValue.SiteCurrentPowerFlow.Storage.ChargeLevel;
}

public async Task<int> GetHomeBatteryPower()
public async Task<int?> GetHomeBatteryPower()
{
_logger.LogTrace("{method}()", nameof(GetHomeBatteryPower));
var latestValue = await GetLatestValue().ConfigureAwait(false);
return GetHomeBatteryPowerFromLatestValue(latestValue);
}

private static int GetHomeBatteryPowerFromLatestValue(CloudApiValue latestValue)
private static int? GetHomeBatteryPowerFromLatestValue(CloudApiValue latestValue)
{
if (latestValue.SiteCurrentPowerFlow.Storage == null)
{
return null;
}
var batteryPower = latestValue.SiteCurrentPowerFlow.Storage.CurrentPower;
if (string.Equals(latestValue.SiteCurrentPowerFlow.Storage.Status, "Discharging"))
{
Expand Down Expand Up @@ -148,9 +156,12 @@ private async Task<CloudApiValue> FakeLastValue()
_logger.LogTrace("{method}()", nameof(FakeLastValue));
var fakedValue = _sharedValues.CloudApiValues.Last().Value;
fakedValue.SiteCurrentPowerFlow.Grid.CurrentPower = 0;
fakedValue.SiteCurrentPowerFlow.Storage.Status = "Charging";
var targetBatteryChargePower = await GetTargetBatteryPower().ConfigureAwait(false);
fakedValue.SiteCurrentPowerFlow.Storage.CurrentPower = targetBatteryChargePower / 1000.0;
if (fakedValue.SiteCurrentPowerFlow.Storage != null)
{
var targetBatteryChargePower = await GetTargetBatteryPower().ConfigureAwait(false);
fakedValue.SiteCurrentPowerFlow.Storage.Status = "Charging";
fakedValue.SiteCurrentPowerFlow.Storage.CurrentPower = targetBatteryChargePower / 1000.0;
}
return fakedValue;
}

Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ TeslaSolarCharger is a service to set one or multiple Teslas' charging current u
- [docker-compose.yml content](#docker-composeyml-content)
- [First startup of the application](#first-startup-of-the-application)
- [Often used optional settings](#often-used-optional-settings)
- [Car Priorities](#car-priorities)
- [Power Buffer](#power-buffer)
- [Home Battery](#home-battery)
- [Telegram integration](#telegram-integration)
Expand Down Expand Up @@ -920,10 +919,6 @@ Assuming the `Measurement` node with `Type` `AC_Power` is the power your inverte

When you are at this point, your car connected to any charging cable in your set home area should start charging based on solar power. But there are a few additional settings that are maybe helpful for your environment:

### Car Priorities

If you have more than one car (or your car does not have ID 1), you can change this setting in the `Car Ids` form field separated by `|`. Note: The order of the IDs is the order of power distribution.

### Power Buffer

If you set `PowerBuffer` to a value different from `0`, the system uses the value as an offset. E.g., If you set `1000`, the car's current is reduced as long as less than 1000 Watt power goes to the grid.
Expand Down
7 changes: 4 additions & 3 deletions TeslaSolarCharger/Server/Services/ChargingCostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ public async Task AddPowerDistributionForAllChargingCars()
&& _configurationWrapper.FrontendConfiguration()?.InverterValueSource != SolarValueSource.None
&& _settings.InverterPower != null)
{
powerFromGrid = _settings.InverterPower
- _configurationWrapper.PowerBuffer()
- _settings.Cars.Select(c => c.CarState.ChargingPowerAtHome).Sum();
var powerBuffer = _configurationWrapper.PowerBuffer();
powerFromGrid = - _settings.InverterPower
+ powerBuffer > 0 ? powerBuffer : 0
+ _settings.Cars.Select(c => c.CarState.ChargingPowerAtHome).Sum();
}
await AddPowerDistribution(car.Id, car.CarState.ChargingPowerAtHome, powerFromGrid).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ internal void UpdateCarConfiguration(CarConfiguration carConfiguration)
}
else
{
if (carConfiguration.LatestTimeToReachSoC < dateTimeOffSetNow)
var localDateTime = dateTimeOffSetNow.ToLocalTime().DateTime;
if (carConfiguration.LatestTimeToReachSoC.Date < localDateTime.Date)
{
carConfiguration.LatestTimeToReachSoC = _dateTimeProvider.Now().Date.AddDays(-1) +
carConfiguration.LatestTimeToReachSoC.TimeOfDay;
Expand Down
6 changes: 6 additions & 0 deletions TeslaSolarCharger/Server/Services/TeslaMateMqttService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ internal void UpdateCar(TeslaMateValue value)
//ToDo: Set to average of requested and actual current
car.CarState.ChargerActualCurrent = car.CarState.LastSetAmp;
}

if (car.CarState.ChargerActualCurrent > 0 && car.CarState.PluggedIn != true)
{
_logger.LogWarning("Car {carId} is not detected as plugged in but actual current > 0 => set plugged in to true", car.Id);
car.CarState.PluggedIn = true;
}
}
else
{
Expand Down

0 comments on commit c791a8b

Please sign in to comment.