Skip to content

Commit 1c426f2

Browse files
Merge pull request #693 from davidusb-geek/davidusb-geek/fix/solve_secrets_bigm_hang
Solve secrets handling and MILP big-M solve hang issues
2 parents 55e10cb + 7a56a4b commit 1c426f2

File tree

11 files changed

+517
-183
lines changed

11 files changed

+517
-183
lines changed

docs/config.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,27 @@ We will need to define these parameters to retrieve data from Home Assistant. Th
2828
- `use_influxdb`: Enable InfluxDB (version 1.x) as a data source instead of the Home Assistant API. This allows for longer historical data retention and better performance for machine learning models. InfluxDB v2 is not currently supported.
2929
- `influxdb_host`: The IP address or hostname of your InfluxDB instance. Defaults to `localhost`.
3030
- `influxdb_port`: The port number for your InfluxDB instance. Defaults to 8086.
31-
- `influxdb_username`: Username for authenticating with InfluxDB. Leave empty if no authentication is required.
32-
- `influxdb_password`: Password for authenticating with InfluxDB. Leave empty if no authentication is required.
3331
- `influxdb_database`: The name of the InfluxDB database containing your Home Assistant data. Defaults to `homeassistant`.
3432
- `influxdb_measurement`: The measurement name where your sensor data is stored. Defaults to `W` for the Home Assistant integration.
3533
- `influxdb_retention_policy`: The retention policy to use for InfluxDB queries. Defaults to `autogen`.
3634

37-
A second part of this section is given by some privacy-sensitive parameters that should be included in a `secrets_emhass.yaml` file alongside the `config_emhass.yaml` file.
35+
A second part of this section is given by some privacy-sensitive parameters that should be included as:
36+
- The list of secret parameters filled in the form on the Add-on **Configuration** pane if using the Add-on installation method.
37+
- A `secrets_emhass.yaml` file alongside the `config_emhass.yaml` file if using the Docker standalone or legacy installation method.
3838

39-
The parameters in the `secrets_emhass.yaml` file are:
39+
The **secrets** parameters are:
4040

4141
- `hass_url`: The URL to your Home Assistant instance. For example: https://myhass.duckdns.org/
4242
- `long_lived_token`: A Long-Lived Access Token from the Lovelace profile page.
4343
- `time_zone`: The time zone of your system. For example: Europe/Paris.
4444
- `lat`: The latitude. For example: 45.0.
4545
- `lon`: The longitude. For example: 6.0
4646
- `alt`: The altitude in meters. For example: 100.0
47+
- `solcast_api_key`: The Solcast API key (weather_forecast_method=solcast)
48+
- `solcast_rooftop_id`: The Solcast rooftop ID (weather_forecast_method=solcast)
49+
- `solar_forecast_kwp`: The PV peak installed power in kW used for the 'solar.forecast' API call (weather_forecast_method=solar.forecast)
50+
- `influxdb_username`: Username for authenticating with InfluxDB. Leave empty if no authentication is required.
51+
- `influxdb_password`: Password for authenticating with InfluxDB. Leave empty if no authentication is required.
4752

4853
## Optimization configuration parameters
4954

docs/passing_data.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,14 @@ Then on the EMHASS configuration you need to set:
138138
"influxdb_port": 8086,
139139
"influxdb_measurement": "state",
140140
"influxdb_retention_policy": "autogen",
141-
"influxdb_password": "influxdb_password",
142-
"influxdb_username": "influxdb_user",
143141
"influxdb_use_ssl": false,
144142
"influxdb_verify_ssl": false,
145143
}
146144
```
147145

146+
Finally, if using the Add-on, you need to fill both "influxdb_password" and "influxdb_username" in the Add-on **Configuration** pane.
147+
If using the Docker standalone or legacy installation method, then you need to set these in the `secrets_emhass.yaml` file.
148+
148149

149150
## Passing in secret parameters
150151
Secret parameters are passed differently, depending on which method you choose. Alternative options are also present for passing secrets, if you are running EMHASS separately from Home Assistant. _(I.e. not via EMHASS-Add-on)_

src/emhass/data/associations.csv

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ retrieve_hass_conf,var_interp,sensor_linear_interp,list_sensor_linear_interp
1111
retrieve_hass_conf,use_influxdb,use_influxdb
1212
retrieve_hass_conf,influxdb_host,influxdb_host
1313
retrieve_hass_conf,influxdb_port,influxdb_port
14-
retrieve_hass_conf,influxdb_username,influxdb_username
15-
retrieve_hass_conf,influxdb_password,influxdb_password
1614
retrieve_hass_conf,influxdb_database,influxdb_database
1715
retrieve_hass_conf,influxdb_measurement,influxdb_measurement
1816
retrieve_hass_conf,influxdb_retention_policy,influxdb_retention_policy
@@ -22,10 +20,17 @@ retrieve_hass_conf,method_ts_round,method_ts_round
2220
retrieve_hass_conf,continual_publish,continual_publish
2321
retrieve_hass_conf,use_websocket,use_websocket
2422
retrieve_hass_conf,ssl_no_verify,ssl_no_verify
23+
params_secrets,hass_url,hass_url
24+
params_secrets,long_lived_token,long_lived_token
2525
params_secrets,time_zone,time_zone
2626
params_secrets,lat,Latitude
2727
params_secrets,lon,Longitude
2828
params_secrets,alt,Altitude
29+
params_secrets,solcast_api_key,solcast_api_key
30+
params_secrets,solcast_rooftop_id,solcast_rooftop_id
31+
params_secrets,solar_forecast_kwp,solar_forecast_kwp
32+
params_secrets,influxdb_username,influxdb_username
33+
params_secrets,influxdb_password,influxdb_password
2934
optim_conf,costfun,costfun
3035
optim_conf,logging_level,logging_level
3136
optim_conf,set_use_pv,set_use_pv

src/emhass/data/config_defaults.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
"use_influxdb": false,
3030
"influxdb_host": "localhost",
3131
"influxdb_port": 8086,
32-
"influxdb_username": "",
33-
"influxdb_password": "",
3432
"influxdb_database": "homeassistant",
3533
"influxdb_measurement": "W",
3634
"influxdb_retention_policy": "autogen",

src/emhass/forecast.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,8 @@ def get_forecast_out_from_csv_or_list(
11911191
forecast_out = pd.concat(forecast_parts, axis=0)
11921192
else:
11931193
forecast_out = pd.DataFrame()
1194+
if not forecast_out.empty and forecast_out.index.dtype != df_final.index.dtype:
1195+
forecast_out.index = forecast_out.index.astype(df_final.index.dtype)
11941196
# Merge with final DataFrame to align indices
11951197
merged = pd.merge_asof(
11961198
df_final.sort_index(),
@@ -1581,6 +1583,8 @@ def get_load_cost_forecast(
15811583
:rtype: pd.DataFrame
15821584
15831585
"""
1586+
if df_final.index.dtype != "datetime64[ns, " + str(self.time_zone) + "]":
1587+
df_final.index = df_final.index.astype("datetime64[ns, " + str(self.time_zone) + "]")
15841588
csv_path = self.emhass_conf["data_path"] / csv_path
15851589
if method == "hp_hc_periods":
15861590
df_final[self.var_load_cost] = self.optim_conf["load_offpeak_hours_cost"]
@@ -1667,6 +1671,8 @@ def get_prod_price_forecast(
16671671
:rtype: pd.DataFrame
16681672
16691673
"""
1674+
if df_final.index.dtype != "datetime64[ns, " + str(self.time_zone) + "]":
1675+
df_final.index = df_final.index.astype("datetime64[ns, " + str(self.time_zone) + "]")
16701676
csv_path = self.emhass_conf["data_path"] / csv_path
16711677
if method == "constant":
16721678
df_final[self.var_prod_price] = self.optim_conf["photovoltaic_production_sell_price"]

src/emhass/machine_learning_forecaster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ async def tune(
622622
exog=self.data_test.drop(self.var_model, axis=1),
623623
)
624624

625-
freq_hours = self.data_exo.index.freq.delta.seconds / 3600
625+
freq_hours = pd.to_timedelta(self.data_exo.index.freq).total_seconds() / 3600
626626
self.lags_opt = int(np.round(len(self.optimize_results.iloc[0]["lags"])))
627627
self.days_needed = int(np.round(self.lags_opt * freq_hours / 24))
628628

0 commit comments

Comments
 (0)