Skip to content

Commit

Permalink
Solcast cloud, fix bug in 10/90 past data and add 90% data (#1163)
Browse files Browse the repository at this point in the history
* Solcast reading, fix bug in 10/90 past data and add 90% data

* [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 2, 2024
1 parent 8af706b commit 8de840c
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions apps/predbat/predbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
if not "PRED_GLOBAL" in globals():
PRED_GLOBAL = {}

THIS_VERSION = "v7.21.3"
THIS_VERSION = "v7.21.4"
PREDBAT_FILES = ["predbat.py"]
TIME_FORMAT = "%Y-%m-%dT%H:%M:%S%z"
TIME_FORMAT_SECONDS = "%Y-%m-%dT%H:%M:%S.%f%z"
Expand Down Expand Up @@ -5129,7 +5129,7 @@ def download_solcast_data(self):
return None

estimated_actuals = data.get("estimated_actuals", [])
full_data = forecasts + estimated_actuals
full_data = estimated_actuals + forecasts
for forecast in full_data:
period_end = forecast.get("period_end", None)
if period_end:
Expand All @@ -5139,19 +5139,28 @@ def download_solcast_data(self):
period_minutes = int(period_period[2:-1])
period_start_stamp = period_end_stamp - timedelta(minutes=period_minutes)
pv50 = forecast.get("pv_estimate", 0) / 60 * period_minutes
pv10 = forecast.get("pv_estimate10", pv50) / 60 * period_minutes
pv90 = forecast.get("pv_estimate90", pv50) / 60 * period_minutes
pv10 = forecast.get("pv_estimate10", forecast.get("pv_estimate", 0)) / 60 * period_minutes
pv90 = forecast.get("pv_estimate90", forecast.get("pv_estimate", 0)) / 60 * period_minutes

is_forecast = False
if "pv_estimate10" in forecast:
is_forecast = True

data_item = {
"period_start": period_start_stamp.strftime(TIME_FORMAT),
"pv_estimate": pv50,
"pv_estimate10": pv10,
"pv_estimate90": pv90,
"is_forecast": is_forecast,
}
if period_start_stamp in period_data:
period_data[period_start_stamp]["pv_estimate"] += pv50
period_data[period_start_stamp]["pv_estimate10"] += pv10
period_data[period_start_stamp]["pv_estimate90"] += pv90
if is_forecast and not period_data[period_start_stamp]["is_forecast"]:
# Don't combine forecast's into actuals
pass
else:
period_data[period_start_stamp]["pv_estimate"] += pv50
period_data[period_start_stamp]["pv_estimate10"] += pv10
period_data[period_start_stamp]["pv_estimate90"] += pv90
else:
period_data[period_start_stamp] = data_item

Expand Down Expand Up @@ -11759,10 +11768,13 @@ def publish_pv_stats(self, pv_forecast_data, divide_by, period):

total_today = 0
total_today10 = 0
total_today90 = 0
total_left_today = 0
total_left_today10 = 0
total_left_today90 = 0
total_tomorrow = 0
total_tomorrow10 = 0
total_tomorrow90 = 0
forecast_today = []
forecast_tomorrow = []

Expand All @@ -11778,28 +11790,33 @@ def publish_pv_stats(self, pv_forecast_data, divide_by, period):
if this_point >= midnight_today and this_point < midnight_tomorrow:
total_today += entry["pv_estimate"] / divide_by
total_today10 += entry["pv_estimate10"] / divide_by
total_today90 += entry["pv_estimate90"] / divide_by
if this_point >= now:
total_left_today += entry["pv_estimate"] / divide_by
total_left_today10 += entry["pv_estimate10"] / divide_by
total_left_today90 += entry["pv_estimate90"] / divide_by
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),
}
forecast_today.append(fentry)
if this_point >= midnight_tomorrow and this_point < midnight_next:
total_tomorrow += entry["pv_estimate"] / divide_by
total_tomorrow10 += entry["pv_estimate10"] / divide_by
total_tomorrow90 += entry["pv_estimate90"] / divide_by
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),
}
forecast_tomorrow.append(fentry)

self.log(
"PV Forecast for today is {} ({} 10%) kWh and left today is {} ({} 10%) kWh".format(
self.dp2(total_today), self.dp2(total_today10), self.dp2(total_left_today), self.dp2(total_left_today10)
"PV Forecast for today is {} ({} 10% {} 90%) kWh and left today is {} ({} 10% {} 90%) kWh".format(
self.dp2(total_today), self.dp2(total_today10), self.dp2(total_today90), self.dp2(total_left_today), self.dp2(total_left_today10), self.dp2(total_left_today90)
)
)
self.dashboard_item(
Expand All @@ -11813,8 +11830,10 @@ def publish_pv_stats(self, pv_forecast_data, divide_by, period):
"device_class": "energy",
"total": self.dp2(total_today),
"total10": self.dp2(total_today10),
"total90": self.dp2(total_today90),
"remaining": self.dp2(total_left_today),
"remaining10": self.dp2(total_left_today10),
"remaining90": self.dp2(total_left_today90),
"detailedForecast": forecast_today,
},
)
Expand All @@ -11830,6 +11849,7 @@ def publish_pv_stats(self, pv_forecast_data, divide_by, period):
"device_class": "energy",
"total": self.dp2(total_tomorrow),
"total10": self.dp2(total_tomorrow10),
"total90": self.dp2(total_tomorrow90),
"detailedForecast": forecast_tomorrow,
},
)
Expand Down

0 comments on commit 8de840c

Please sign in to comment.