Skip to content

Commit

Permalink
Make solcast data reporting more robust (#1187)
Browse files Browse the repository at this point in the history
* Make solcast data reporting more robust

* [pre-commit.ci lite] apply automatic fixes

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
springfall2008 and pre-commit-ci-lite[bot] committed Jun 6, 2024
1 parent 6524f81 commit 7ee650c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions apps/predbat/predbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11840,10 +11840,16 @@ def publish_pv_stats(self, pv_forecast_data, divide_by, period):
midnight_today = self.midnight_utc
now = self.now_utc

power_scale = 60 / period / divide_by # Scale kwh to power
power_scale = 60 / period # Scale kwh to power

for entry in pv_forecast_data:
this_point = datetime.strptime(entry["period_start"], TIME_FORMAT)
if "period_start" not in entry:
continue
try:
this_point = datetime.strptime(entry["period_start"], TIME_FORMAT)
except (ValueError, TypeError):
continue

if this_point >= midnight_today:
day = (this_point - midnight_today).days
if day not in total_day:
Expand Down Expand Up @@ -11872,9 +11878,9 @@ def publish_pv_stats(self, pv_forecast_data, divide_by, period):

fentry = {
"period_start": entry["period_start"],
"pv_estimate": self.dp2(entry["pv_estimate"] * power_scale),
"pv_estimate10": self.dp2(entry["pv_estimate10"] * power_scale),
"pv_estimate90": self.dp2(entry["pv_estimate90"] * power_scale),
"pv_estimate": self.dp2(pv_estimate * power_scale),
"pv_estimate10": self.dp2(pv_estimate10 * power_scale),
"pv_estimate90": self.dp2(pv_estimate90 * power_scale),
}
forecast_day[day].append(fentry)

Expand All @@ -11885,7 +11891,7 @@ def publish_pv_stats(self, pv_forecast_data, divide_by, period):
"PV Forecast for today is {} ({} 10% {} 90%) kWh and left today is {} ({} 10% {} 90%) kWh".format(
self.dp2(total_day[day]),
self.dp2(total_day10[day]),
self.dp2(total_day10[day]),
self.dp2(total_day90[day]),
self.dp2(total_left_today),
self.dp2(total_left_today10),
self.dp2(total_left_today90),
Expand Down Expand Up @@ -11914,7 +11920,7 @@ def publish_pv_stats(self, pv_forecast_data, divide_by, period):
else:
day_name = "tomorrow" if day == 1 else "d{}".format(day)
day_name_long = day_name if day == 1 else "day {}".format(day)
self.log("PV Forecast for day {} is {} ({} 10% {} 90%) kWh".format(day_name, self.dp2(total_day[day]), self.dp2(total_day10[day]), self.dp2(total_day10[day])))
self.log("PV Forecast for day {} is {} ({} 10% {} 90%) kWh".format(day_name, self.dp2(total_day[day]), self.dp2(total_day10[day]), self.dp2(total_day90[day])))

self.dashboard_item(
"sensor." + self.prefix + "_pv_" + day_name,
Expand Down

0 comments on commit 7ee650c

Please sign in to comment.