davidusb-geek / emhass

emhass: Energy Management for Home Assistant, is a Python module designed to optimize your home energy interfacing with Home Assistant.
MIT License
301 stars 61 forks source link

Solar.Forecast service gives error #64

Closed overas closed 1 year ago

overas commented 1 year ago

Describe the bug I am trying to use the Solar.Forecast service with emhass. I have earlier reported another issue Solar.Forecast you fixed: https://github.com/davidusb-geek/emhass/issues/47

I have two Solar.Forecast service for my two roofs. image

I pass the solar_forecast_kwp key with this shell_command:

shell_command:
  trigger_entsoe_forecast: "curl -i -H \"Content-Type: application/json\" -X POST -d '{\"solar_forecast_kwp\":5.3,
    \"load_cost_forecast\":{{((state_attr('sensor.entsoe_average_electricity_price_today', 'prices_today') | map(attribute='price') | list  + state_attr('sensor.entsoe_average_electricity_price_today', 'prices_tomorrow') | map(attribute='price') | list))[now().hour:][:24] }},
    \"prod_price_forecast\":{{((state_attr('sensor.entsoe_average_electricity_price_today', 'prices_today') | map(attribute='price') | list  + state_attr('sensor.entsoe_average_electricity_price_today', 'prices_tomorrow') | map(attribute='price') | list))[now().hour:][:24]}}
    }' http://localhost:5000/action/dayahead-optim"

Emhass gives these error in the log:

2023-03-13 20:10:41,838 - web_server - INFO - Retrieving weather forecast data using method = solar.forecast
2023-03-13 20:10:42,043 - web_server - ERROR - Exception on /action/dayahead-optim [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 2528, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 1825, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 1823, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 1799, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/usr/local/lib/python3.9/dist-packages/emhass/web_server.py", line 170, in action_call
    input_data_dict = set_input_data_dict(config_path, str(data_path), costfun,
  File "/usr/local/lib/python3.9/dist-packages/emhass/command_line.py", line 89, in set_input_data_dict
    df_weather = fcst.get_weather_forecast(method=optim_conf['weather_forecast_method'])
  File "/usr/local/lib/python3.9/dist-packages/emhass/forecast.py", line 273, in get_weather_forecast
    data_dict = {'ts':list(data_raw['result']['watts'].keys()), 'yhat':list(data_raw['result']['watts'].values())}
TypeError: 'NoneType' object is not subscriptable

Hassos also logs:

Logger: homeassistant.config_entries
Source: config_entries.py:425
First occurred: 20:09:30 (2 occurrences)
Last logged: 20:09:30

Config entry 'Hustak' for forecast_solar integration not ready yet: Rate limit for API calls reached. (error 429); Retrying in background
Config entry 'Garasjetak' for forecast_solar integration not ready yet: Rate limit for API calls reached. (error 429); Retrying in background

and

Logger: homeassistant.components.forecast_solar
Source: components/forecast_solar/coordinator.py:65
Integration: Forecast.Solar (documentation, issues)
First occurred: 20:09:30 (18 occurrences)
Last logged: 20:16:18

Unexpected error fetching forecast_solar data: Rate limit for API calls reached. (error 429)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 239, in _async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/components/forecast_solar/coordinator.py", line 65, in _async_update_data
    return await self.forecast.estimate()
  File "/usr/local/lib/python3.10/site-packages/forecast_solar/__init__.py", line 148, in estimate
    data = await self._request(
  File "/usr/local/lib/python3.10/site-packages/forecast_solar/__init__.py", line 122, in _request
    raise ForecastSolarRatelimit(data["message"])
forecast_solar.exceptions.ForecastSolarRatelimit: Rate limit for API calls reached. (error 429)

Home Assistant installation type Home Assistant 2023.3.3 Supervisor 2023.03.1 Operating System 9.5 Frontend 20230309.0 - latest

Home Assistant installation type

Your hardware Intel Nuc with hassos

EMHASS installation type

Emhass.log emhass.log

davidusb-geek commented 1 year ago

This is not an emhass issue. This is your problem:

ForecastSolarRatelimit: Rate limit for API

That api is limited. You already have that integrated to Home Assistant. Don't try to use both in Home Assistant and in EMHASS. Just pick one. EMHASS can use Solar.Forecast without you adding that integration to Home Assistant.