Skip to content

Commit

Permalink
Added thee day embedded solar + wind
Browse files Browse the repository at this point in the history
  • Loading branch information
JRascagneres committed Dec 16, 2023
1 parent 7bb2b3d commit adf6977
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 7 deletions.
48 changes: 45 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ other_percentage_generation
grid_collection_time
```

### Day Ahead Solar Forecast
Thirty minute day ahead solar forecast

Name - Solar Forecast\
ID - sensor.national_grid_solar_forecast\
State - Current forecast value\
Attributes:
```
forecast:
- start_time: ...
generation: ...
...
```

### Wind Forecast Entity
Hourly forecast from 20:00 (UTC) on the current day to 20:00 (GMT) on day + 2

Expand Down Expand Up @@ -156,7 +170,7 @@ forecast:
...
```

### Wind Forecast Seven To Fourteen Day Entity
### Wind Forecast Fourteen Day Entity
Two-hourly long term wind forecast - From now to fourteen days ahead

Name - Wind Forecast Fourteen Day\
Expand All @@ -170,6 +184,20 @@ forecast:
...
```

### Embedded Wind Forecast Three Day
Thirty minute long term wind forecast - From now to three days ahead

Name - Embedded Wind Forecast Three Day\
ID - sensor.national_grid_embedded_wind_forecast_three_day\
State - None\
Attributes:
```
forecast:
- start_time: ...
generation: ...
...
```

### Embedded Wind Forecast Fourteen Day
Two-hourly long term wind forecast - From now to fourteen days ahead

Expand All @@ -184,11 +212,25 @@ forecast:
...
```

### Solar Forecast Seven To Fourteen Day Entity
### Embedded Solar Forecast Three Day
Thirty minute long term wind forecast - From now to three days ahead

Name - Embedded Solar Forecast Three Day\
ID - sensor.national_grid_embedded_solar_forecast_three_day\
State - None\
Attributes:
```
forecast:
- start_time: ...
generation: ...
...
```

### Embedded Solar Forecast Seven To Fourteen Day Entity
Two-hourly long term solar forecast - From now to fourteen days ahead

Name - Embedded Solar Forecast Fourteen Day\
ID - sensor.national_grid_fourteen_day_solar_forecast\
ID - sensor.national_grid_embedded_solar_forecast_fourteen_day\
State - None\
Attributes:
```
Expand Down
45 changes: 42 additions & 3 deletions custom_components/national_grid/coordinators/national_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ def get_data(

three_day, fourteen_day = get_long_term_wind_forecast_eso_data(today_full)

solar, wind = get_long_term_embedded_wind_and_solar_forecast(today_full)
(
three_day_solar,
solar,
three_day_wind,
wind,
) = get_long_term_embedded_wind_and_solar_forecast(today_full)

return NationalGridData(
sell_price=current_price,
Expand All @@ -136,7 +141,9 @@ def get_data(
fourteen_wind_forecast=fourteen_day,
solar_forecast=solar_forecast,
fourteen_embedded_solar=solar,
three_embedded_solar=three_day_solar,
fourteen_embedded_wind=wind,
three_embedded_wind=three_day_wind,
grid_generation=grid_generation,
total_demand_mwh=total_demand_mwh,
total_transfers_mwh=total_transfers_mwh,
Expand Down Expand Up @@ -470,16 +477,25 @@ def get_long_term_wind_forecast_eso_data(

def get_long_term_embedded_wind_and_solar_forecast(
now: datetime,
) -> (NationalGridSolarForecast, NationalGridWindForecast):
) -> (
NationalGridSolarForecast,
NationalGridSolarForecast,
NationalGridWindForecast,
NationalGridWindForecast,
):
url = "https://api.nationalgrideso.com/api/3/action/datastore_search?resource_id=db6c038f-98af-4570-ab60-24d71ebd0ae5&limit=32000"
response = requests.get(url, timeout=20)
data = json.loads(response.content)

nearest_30_minutes = now + (now.min.replace(tzinfo=now.tzinfo) - now) % timedelta(
minutes=30
)
in_three_days = nearest_30_minutes + timedelta(days=3)
in_fourteen_days = nearest_30_minutes + timedelta(days=14)

three_day_solar_forecast = []
three_day_wind_forecast = []

solar_forecast = []
wind_forecast = []

Expand All @@ -503,6 +519,22 @@ def get_long_term_embedded_wind_and_solar_forecast(
current_solar_forecast = solar_forecast_val
current_wind_forecast = wind_forecast_val

if (
formatted_datetime >= nearest_30_minutes
and formatted_datetime <= in_three_days
):
three_day_solar_forecast.append(
NationalGridSolarForecastItem(
start_time=formatted_datetime, generation=solar_forecast_val
)
)

three_day_wind_forecast.append(
NationalGridWindForecastItem(
start_time=formatted_datetime, generation=wind_forecast_val
)
)

if (
formatted_datetime >= nearest_30_minutes
and formatted_datetime <= in_fourteen_days
Expand Down Expand Up @@ -533,14 +565,21 @@ def get_long_term_embedded_wind_and_solar_forecast(
)
)

three_day_solar = NationalGridSolarForecast(
current_value=current_solar_forecast, forecast=three_day_solar_forecast
)
three_day_wind = NationalGridWindForecast(
current_value=current_wind_forecast, forecast=three_day_wind_forecast
)

solar = NationalGridSolarForecast(
current_value=current_solar_forecast, forecast=solar_forecast
)
wind = NationalGridWindForecast(
current_value=current_wind_forecast, forecast=wind_forecast
)

return (solar, wind)
return (three_day_solar, solar, three_day_wind, wind)


def get_carbon_intensity(now_utc_full: datetime) -> int:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/national_grid/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"dependencies": [],
"iot_class": "cloud_polling",
"requirements": [],
"version": "0.0.32",
"version": "0.0.33",
"config_flow": true
}
2 changes: 2 additions & 0 deletions custom_components/national_grid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ class NationalGridData(TypedDict):
now_to_three_wind_forecast: NationalGridWindForecastLongTerm
fourteen_wind_forecast: NationalGridWindForecastLongTerm
solar_forecast: NationalGridSolarForecast
three_embedded_solar: NationalGridSolarForecast
fourteen_embedded_solar: NationalGridSolarForecast
three_embedded_wind: NationalGridWindForecast
fourteen_embedded_wind: NationalGridWindForecast
grid_generation: NationalGridGeneration
total_demand_mwh: int
Expand Down
18 changes: 18 additions & 0 deletions custom_components/national_grid/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,15 @@ class NationalGridSensorEntityDescription(SensorEntityDescription):
state_class=SensorStateClass.MEASUREMENT,
extra_attributes_key="fourteen_embedded_solar",
),
NationalGridSensorEntityDescription(
key="three_embedded_solar.current_value",
name="Embedded Solar Forecast Three Day",
unique_id="three_day_embedded_solar",
native_unit_of_measurement="MW",
icon="mdi:solar-power-variant",
state_class=SensorStateClass.MEASUREMENT,
extra_attributes_key="three_embedded_solar",
),
NationalGridSensorEntityDescription(
key="fourteen_embedded_wind.current_value",
name="Embedded Wind Forecast Fourteen Day",
Expand All @@ -309,6 +318,15 @@ class NationalGridSensorEntityDescription(SensorEntityDescription):
state_class=SensorStateClass.MEASUREMENT,
extra_attributes_key="fourteen_embedded_wind",
),
NationalGridSensorEntityDescription(
key="three_embedded_wind.current_value",
name="Embedded Wind Forecast Three Day",
unique_id="three_day_embedded_wind",
native_unit_of_measurement="MW",
icon="mdi:wind-turbine",
state_class=SensorStateClass.MEASUREMENT,
extra_attributes_key="three_embedded_wind",
),
NationalGridSensorEntityDescription(
key=None,
name="Grid Generation",
Expand Down

0 comments on commit adf6977

Please sign in to comment.