Skip to content

Commit

Permalink
Add support for capping power to inverter capacity (#11)
Browse files Browse the repository at this point in the history
Signed-off-by: rany <ranygh@riseup.net>
  • Loading branch information
rany2 authored Jun 9, 2024
1 parent 2da9b3b commit 0d901b8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
9 changes: 9 additions & 0 deletions custom_components/open_meteo_solar_forecast/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
CONF_DECLINATION,
CONF_EFFICIENCY_FACTOR,
CONF_MODULES_POWER,
CONF_INVERTER_POWER,
DOMAIN,
)

Expand Down Expand Up @@ -55,6 +56,7 @@ async def async_step_user(
CONF_BASE_URL: user_input[CONF_BASE_URL],
CONF_DECLINATION: user_input[CONF_DECLINATION],
CONF_MODULES_POWER: user_input[CONF_MODULES_POWER],
CONF_INVERTER_POWER: user_input[CONF_INVERTER_POWER],
CONF_EFFICIENCY_FACTOR: user_input[CONF_EFFICIENCY_FACTOR],
},
)
Expand Down Expand Up @@ -85,6 +87,9 @@ async def async_step_user(
vol.Required(CONF_MODULES_POWER): vol.All(
vol.Coerce(int), vol.Range(min=1)
),
vol.Required(CONF_INVERTER_POWER, default=0): vol.All(
vol.Coerce(int), vol.Range(min=0)
),
vol.Optional(CONF_EFFICIENCY_FACTOR, default=1.0): vol.All(
vol.Coerce(float), vol.Range(min=0)
),
Expand Down Expand Up @@ -138,6 +143,10 @@ async def async_step_init(
CONF_MODULES_POWER,
default=self.config_entry.options[CONF_MODULES_POWER],
): vol.All(vol.Coerce(int), vol.Range(min=1)),
vol.Required(
CONF_INVERTER_POWER,
default=self.config_entry.options.get(CONF_INVERTER_POWER, 0),
): vol.All(vol.Coerce(int), vol.Range(min=0)),
vol.Optional(
CONF_EFFICIENCY_FACTOR,
default=self.config_entry.options.get(
Expand Down
1 change: 1 addition & 0 deletions custom_components/open_meteo_solar_forecast/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
CONF_DECLINATION = "declination"
CONF_AZIMUTH = "azimuth"
CONF_MODULES_POWER = "modules_power"
CONF_INVERTER_POWER = "inverter_power"
CONF_EFFICIENCY_FACTOR = "efficiency_factor"
8 changes: 7 additions & 1 deletion custom_components/open_meteo_solar_forecast/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
CONF_BASE_URL,
CONF_DECLINATION,
CONF_EFFICIENCY_FACTOR,
CONF_INVERTER_POWER,
CONF_MODULES_POWER,
DOMAIN,
LOGGER,
Expand All @@ -36,16 +37,21 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
# this if statement is here to catch that.
api_key = entry.options.get(CONF_API_KEY) or None

# Handle new options that were added after the initial release
ac_kwp = entry.options.get(CONF_INVERTER_POWER, 0)
ac_kwp = ac_kwp / 1000 if ac_kwp else None

self.forecast = OpenMeteoSolarForecast(
api_key=api_key,
session=async_get_clientsession(hass),
latitude=entry.data[CONF_LATITUDE],
longitude=entry.data[CONF_LONGITUDE],
azimuth=entry.options[CONF_AZIMUTH] - 180,
base_url=entry.options[CONF_BASE_URL],
ac_kwp=ac_kwp,
dc_kwp=(entry.options[CONF_MODULES_POWER] / 1000),
declination=entry.options[CONF_DECLINATION],
efficiency_factor=entry.options[CONF_EFFICIENCY_FACTOR],
kwp=(entry.options[CONF_MODULES_POWER] / 1000),
)

update_interval = timedelta(minutes=30)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/open_meteo_solar_forecast/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"documentation": "https://github.com/rany2/ha-open-meteo-solar-forecast",
"integration_type": "service",
"iot_class": "cloud_polling",
"requirements": ["open_meteo_solar_forecast==0.1.13"],
"requirements": ["open_meteo_solar_forecast==0.1.14"],
"version": "0.1.9",
"issue_tracker": "https://github.com/rany2/ha-open-meteo-solar-forecast/issues",
"documentation": "https://github.com/rany2/ha-open-meteo-solar-forecast"
Expand Down
4 changes: 3 additions & 1 deletion custom_components/open_meteo_solar_forecast/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"longitude": "[%key:common::config_flow::data::longitude%]",
"efficiency_factor": "DC efficiency factor (0.0-1.0, 0.0 = 100% loss, 1.0 = no loss)",
"modules_power": "Total Watt peak power of your solar modules",
"inverter_power": "The capacity of your inverter in Watt",
"name": "[%key:common::config_flow::data::name%]"
}
}
Expand All @@ -28,7 +29,8 @@
"azimuth": "[%key:component::solar_forecast::config::step::user::data::azimuth%]",
"declination": "[%key:component::solar_forecast::config::step::user::data::declination%]",
"efficiency_factor": "[%key:component::solar_forecast::config::step::user::data::efficiency_factor%]",
"modules_power": "[%key:component::solar_forecast::config::step::user::data::modules_power%]"
"modules_power": "[%key:component::solar_forecast::config::step::user::data::modules_power%]",
"inverter_power": "[%key:component::solar_forecast::config::step::user::data::inverter_power%]"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"longitude": "Longitude",
"efficiency_factor": "DC efficiency factor (0.0-1.0, 0.0 = 100% loss, 1.0 = no loss)",
"modules_power": "Total Watt peak power of your solar modules",
"inverter_power": "The capacity of your inverter in Watt",
"name": "Name"
},
"description": "Fill in the data of your solar panels. Please refer to the documentation if a field is unclear."
Expand Down Expand Up @@ -89,7 +90,8 @@
"declination": "Declination (0 = Horizontal, 90 = Vertical)",
"inverter_size": "Inverter size (Watt)",
"efficiency_factor": "DC efficiency factor (0.0-1.0, 0.0 = 100% loss, 1.0 = no loss)",
"modules_power": "Total Watt peak power of your solar modules"
"modules_power": "Total Watt peak power of your solar modules",
"inverter_power": "The capacity of your inverter in Watt"
},
"description": "These values allow tweaking the Forecast.Solar result. Please refer to the documentation if a field is unclear."
}
Expand Down

0 comments on commit 0d901b8

Please sign in to comment.