Skip to content

Commit

Permalink
v4.0.17
Browse files Browse the repository at this point in the history
added weather description sensor
  • Loading branch information
Greg committed May 7, 2024
1 parent c285b9d commit 2b6630c
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 12 deletions.
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@

Before submitting an issue, search the issues and discussion forum to see if this has already been ask and answered in the past. The following usually fixes most users problems...
- make sure the API key you enter is the API key and not the rooftop id
- make sure the solcast toolkit area is working
- READ THE LOG OUTPUT, this gives some good info as to whats happening or a problem
- make sure your not out of API calls
- if all that fails run the service to delete the solcast data file (or manually delete it from HA/config/solcast.json and restart HA)


# HA Solcast PV Solar Forecast Integration

Home Assistant(https://www.home-assistant.io) Integration Component
Expand Down Expand Up @@ -220,6 +212,7 @@ Click the Forecast option button and select the Solcast Solar option.. Click SAV
| `D7` | number | Y | `kWh` | Total forecast solar production for day + 6 (day 7) |
| `This Hour` | number | N | `Wh` | Forecasted solar production current hour |
| `Next Hour` | number | N | `Wh` | Forecasted solar production next hour |
| `Forecast Next X Hours` | number | N | `kWh` | Custom user defined X hour forecast |
| `Remaining Today` | number | N | `kWh` | Predicted remaining solar production today |
| `Peak Forecast Today` | number | N | `W` | Highest predicted production within an hour period today |
| `Peak Time Today` | date/time | N | | Hour of max forecasted production of solar today |
Expand All @@ -228,13 +221,14 @@ Click the Forecast option button and select the Solcast Solar option.. Click SAV
| `Power Now` | number | N | `W` | Power forecast during the current 0-30 / 30-59 min hour period |
| `Power Next 30 Mins` | number | N | `W` | Power forecast for the next 30 min block period |
| `Power Next Hour` | number | N | `W` | Power forecast for the next block 60 min from now |
| `Weather` | string | N | | Solcast weather description |


### Configuration

| Name | Type | Attributes | Unit | Description |
| ------------------------------ | ----------- | ----------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Rooftop name` | number | Y | `kWh` | Total forecast for rooftop today (attributes contain the solcast rooftop setup) |
| `Forecast Field` | selector | N | | selector to select the Solcast value field for calculations either 'estimate', 'estimate10' or 'estimate90' |

### Diagnostic

Expand All @@ -243,8 +237,10 @@ Click the Forecast option button and select the Solcast Solar option.. Click SAV
| `API Last Polled` | date/time | N | | Date/time when the API data was polled |
| `API Limit` | number | N | `integer` | Total times the API can been called in a 24 hour period[^1] |
| `API used` | number | N | `integer` | Total times the API has been called today (API counter resets to zero at midnight UTC)[^1] |
| `Rooftop(s) name` | number | Y | `kWh` | Total forecast for rooftop today (attributes contain the solcast rooftop setup)[^2] |

[^1]: API usage information is directly read from Solcast
[^2]: Each rooftop created in Solcast will be listed seperately



Expand Down
4 changes: 4 additions & 0 deletions custom_components/solcast_solar/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async def update_integration_listeners(self, *args):

async def service_event_update(self, *args):
await self.solcast.http_data(dopast=False)
await self.solcast.sites_weather()
await self.update_integration_listeners()

async def service_event_delete_old_solcast_json_file(self, *args):
Expand Down Expand Up @@ -116,6 +117,9 @@ def get_sensor_value(self, key=""):
return self.solcast.get_api_limit()
elif key == "lastupdated":
return self.solcast.get_last_updated_datetime()
elif key == "weather_description":
return self.solcast.get_weather()


#just in case
return None
Expand Down
2 changes: 1 addition & 1 deletion custom_components/solcast_solar/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/oziee/ha-solcast-solar/issues",
"requirements": ["aiohttp>=3.8.5", "datetime>=4.3", "isodate>=0.6.1"],
"version": "4.0.16"
"version": "4.0.17"
}
5 changes: 5 additions & 0 deletions custom_components/solcast_solar/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@
#name="Power Next Hour",
suggested_display_precision=0,
),
"weather_description": SensorEntityDescription(
key="weather_description",
translation_key="weather_description",
icon="mdi:weather-partly-snowy-rainy",
),
}


Expand Down
41 changes: 41 additions & 0 deletions custom_components/solcast_solar/solcastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def __init__(
self._damp =options.dampening
self._customhoursensor = options.customhoursensor
self._use_data_field = f"pv_{options.key_estimate}"
self._weather = ""

async def serialize_data(self):
"""Serialize data to file."""
Expand Down Expand Up @@ -189,6 +190,42 @@ async def sites_usage(self):
except Exception as e:
_LOGGER.error("SOLCAST - sites_usage error: %s", traceback.format_exc())

async def sites_weather(self):
"""Request rooftop site weather byline via the Solcast API."""

try:
if len(self._sites) > 0:
sp = self.options.api_key.split(",")
rid = self._sites[0].get("resource_id", None)

params = {"resourceId": rid, "api_key": sp[0]}
_LOGGER.debug(f"SOLCAST - get rooftop weather byline from solcast")
async with async_timeout.timeout(60):
resp: ClientResponse = await self.aiohttp_session.get(
url=f"https://api.solcast.com.au/json/reply/GetRooftopSiteSparklines", params=params, ssl=False
)
resp_json = await resp.json(content_type=None)
status = resp.status

if status == 200:
d = cast(dict, resp_json)
_LOGGER.debug(f"SOLCAST - sites_weather returned data: {d}")
self._weather = d.get("forecast_descriptor", None).get("description", None)
_LOGGER.debug(f"SOLCAST - rooftop weather description: {self._weather}")
else:
raise Exception(f"SOLCAST - sites_weather: gathering rooftop weather description failed. request returned Status code: {status} - Responce: {resp_json}.")

except json.decoder.JSONDecodeError:
_LOGGER.error("SOLCAST - sites_weather JSONDecodeError.. The rooftop weather description from Solcast is unknown, Solcast site could be having problems")
except ConnectionRefusedError as err:
_LOGGER.error("SOLCAST - sites_weather Error.. %s",err)
except ClientConnectionError as e:
_LOGGER.error('SOLCAST - sites_weather Connection Error', str(e))
except asyncio.TimeoutError:
_LOGGER.error("SOLCAST - sites_weather Connection Error - Timed out connection to solcast server")
except Exception as e:
_LOGGER.error("SOLCAST - sites_weather error: %s", traceback.format_exc())

async def load_saved_data(self):
try:
if len(self._sites) > 0:
Expand Down Expand Up @@ -277,6 +314,10 @@ def get_api_limit(self):
except Exception:
return None

def get_weather(self):
"""Return weather description"""
return self._weather

def get_last_updated_datetime(self) -> dt:
"""Return date time with the data was last updated"""
return dt.fromisoformat(self._data["last_updated"])
Expand Down
3 changes: 2 additions & 1 deletion custom_components/solcast_solar/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@
"total_kwh_forecast_d5": {"name": "Forecast Day 5"},
"total_kwh_forecast_d6": {"name": "Forecast Day 6"},
"total_kwh_forecast_d7": {"name": "Forecast Day 7"},
"power_now": {"name": "Power Now"}
"power_now": {"name": "Power Now"},
"weather_description": {"name": "Weather"}
},
"select": {
"estimate_mode" : {"name": "Use Forecast Field"}
Expand Down
3 changes: 2 additions & 1 deletion custom_components/solcast_solar/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@
"total_kwh_forecast_d5": {"name": "Forecast Day 5"},
"total_kwh_forecast_d6": {"name": "Forecast Day 6"},
"total_kwh_forecast_d7": {"name": "Forecast Day 7"},
"power_now": {"name": "Power Now"}
"power_now": {"name": "Power Now"},
"weather_description": {"name": "Weather"}
},
"select": {
"estimate_mode" : {"name": "Use Forecast Field"}
Expand Down
4 changes: 4 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
### Changes

v4.0.17
- updated Slovak translation thanks @misa1515
- added sensor for Solcast weather description

v4.0.16
- added @Zachoz idea of adding a setting to select which solcast estimate field value for the forecast calculations, either estimate, estimate10 or estimate90
ESTIMATE - Default forecasts
Expand Down

0 comments on commit 2b6630c

Please sign in to comment.