EMHASS: An Energy Management for Home Assistant

Is it possible to set a thermal load as variable?

Hi everyone,

first of all: very nice but also very complex project.

I’m struggling with several aspects, but first I’d like to get my pv forecast right.
Right now I’m pretty off with it: 4kw vs 12kw in reality at peak.

My setup is: three strings (east, south, west) with 12,11,12 module each 450W, one inverter with nominal power 18kw (KACO blueplanet hybrid nh3).
Neither the modules nor the inverter is in the pvlib list, so I went for some Trina Solar modules with 465W and tried different configurations of inverters and strings_per_inverter.
Unfortunately I seem to misunderstand something because forecast is always far too little.

Here is my config:

{
  "adjusted_pv_regression_model": "LassoRegression",
  "adjusted_pv_solar_elevation_threshold": 10,
  "battery_charge_efficiency": 0.95,
  "battery_charge_power_max": 1000,
  "battery_discharge_efficiency": 0.95,
  "battery_discharge_power_max": 1000,
  "battery_dynamic_max": 0.9,
  "battery_dynamic_min": -0.9,
  "battery_maximum_state_of_charge": 0.9,
  "battery_minimum_state_of_charge": 0.3,
  "battery_nominal_energy_capacity": 5000,
  "battery_target_state_of_charge": 0.6,
  "compute_curtailment": false,
  "continual_publish": false,
  "costfun": "self-consumption",
  "delta_forecast_daily": 1,
  "end_timesteps_of_each_deferrable_load": [
    0
  ],
  "historic_days_to_retrieve": 2,
  "inverter_is_hybrid": false,
  "load_cost_forecast_method": "hp_hc_periods",
  "load_forecast_method": "naive",
  "load_negative": false,
  "load_offpeak_hours_cost": 0.1419,
  "load_peak_hour_periods": {
    "period_hp_1": [
      {
        "start": "08:00"
      },
      {
        "end": "12:00"
      }
    ],
    "period_hp_2": [
      {
        "start": "15:00"
      },
      {
        "end": "18:00"
      }
    ]
  },
  "load_peak_hours_cost": 0.1907,
  "logging_level": "INFO",
  "lp_solver": "default",
  "lp_solver_path": "empty",
  "lp_solver_timeout": 45,
  "maximum_power_from_grid": 9000,
  "maximum_power_to_grid": 9000,
  "method_ts_round": "nearest",
  "minimum_power_of_deferrable_loads": [
    2500
  ],
  "modules_per_string": [
    12,
    11,
    12
  ],
  "nominal_power_of_deferrable_loads": [
    7500
  ],
  "num_threads": 0,
  "number_of_deferrable_loads": 1,
  "open_meteo_cache_max_age": 30,
  "operating_hours_of_each_deferrable_load": [
    8
  ],
  "optimization_time_step": 60,
  "photovoltaic_production_sell_price": 0.07553,
  "production_price_forecast_method": "constant",
  "pv_inverter_model": [
    "Fronius_International_GmbH__Fronius_Primo_10_0_1_208_240__240V_",
    "Fronius_International_GmbH__Fronius_Primo_10_0_1_208_240__240V_",
    "Fronius_International_GmbH__Fronius_Primo_10_0_1_208_240__240V_"
  ],
  "pv_module_model": [
    "Trina_Solar_TSM_465DEG15VC_20_II_"
  ],
  "sensor_linear_interp": [
    "sensor.power_photovoltaics"
  ],
  "sensor_power_load_no_var_loads": "sensor.power_load_no_var_loads",
  "sensor_power_photovoltaics": "sensor.pv_momentanleistung_ac",
  "sensor_power_photovoltaics_forecast": "sensor.p_pv_forecast",
  "sensor_replace_zero": [
    "sensor.power_photovoltaics"
  ],
  "set_battery_dynamic": false,
  "set_deferrable_load_single_constant": [
    false
  ],
  "set_deferrable_startup_penalty": [
    0
  ],
  "set_nocharge_from_grid": false,
  "set_nodischarge_to_grid": true,
  "set_total_pv_sell": false,
  "set_use_adjusted_pv": false,
  "set_use_battery": false,
  "set_use_pv": true,
  "set_zero_min": true,
  "start_timesteps_of_each_deferrable_load": [
    0
  ],
  "strings_per_inverter": [
    1,
    1,
    1
  ],
  "surface_azimuth": [
    85,
    175,
    265
  ],
  "surface_tilt": [
    21,
    21,
    21
  ],
  "treat_deferrable_load_as_semi_cont": [
    true
  ],
  "weather_forecast_method": "open-meteo",
  "weight_battery_charge": 0,
  "weight_battery_discharge": 0
}```

Repeat this one 3 times and check, works for me.

1 Like

Confusion about cost_fun_profit interpretation in EMHASS – is negative good?

Hi all,

I’m using EMHASS for MPC optimization and I’m a bit confused about the interpretation of the cost_fun_profit metric shown in the forecast results and output sensors.

Is this correct:

cost_fun_profit = Ī£(P_grid_pos Ɨ unit_load_cost) āˆ’ Ī£(P_grid_neg Ɨ unit_prod_price)

Where:

  • P_grid_pos is power consumed from the grid (kWh),
  • P_grid_neg is power fed back to the grid (kWh),
  • unit_load_cost is the electricity price when consuming,
  • unit_prod_price is the price you receive for feeding back.

From this, I interpret that:

  • A lower (more negative) cost_fun_profit means you have more favorable economics (more feed-in revenue than consumption costs).
  • A positive value means you are spending more on grid consumption than you’re earning from feed-in.

However, someone pointed out that in the EMHASS dashboard (the results table), the cost_fun_profit seems to increase (become more positive) during periods of high PV production and low self-consumption. That would contradict the formula above.

So my questions are:

  1. Is a more negative cost_fun_profit value better (i.e., higher profit)?
  2. Does the EMHASS results table show the delta per timestep or cumulative cost function?
  3. Could this perceived inconsistency be due to zero feed-in prices, forecast errors, or simply misinterpretation of the plotted values?

Thanks in advance for helping clarify this!

Thanks, that already improved it. However, optimization status is infeasible now.

[2025-06-21 15:55:38 +0200] [20] [INFO] >> Obtaining params:
[2025-06-21 15:55:38 +0200] [20] [INFO] Passed runtime parameters: {ā€˜load_cost_forecast’: [0.18732, 0.19268, 0.26397, 0.31271, 0.34478, 0.3791, 0.38928, 0.36011, 0.33443, 0.32128, 0.31285, 0.30856, 0.3022, 0.29931, 0.29724, 0.27823, 0.22404, 0.19258, 0.19247, 0.17936, 0.14669, 0.11236, 0.07476, 0.09619], ā€˜def_total_hours’: [5]}
[2025-06-21 15:55:38 +0200] [20] [INFO] >> Setting input data dict
[2025-06-21 15:55:38 +0200] [20] [INFO] Setting up needed data
[2025-06-21 15:55:38 +0200] [20] [INFO] Retrieving weather forecast data using method = open-meteo
[2025-06-21 15:55:38 +0200] [20] [INFO] Loading existing cached Open-Meteo JSON file: /data/cached-open-meteo-forecast.json
[2025-06-21 15:55:38 +0200] [20] [INFO] The cached Open-Meteo JSON file is recent (age=2m, max_age=30m)
[2025-06-21 15:55:39 +0200] [20] [INFO] Retrieving data from hass for load forecast using method = naive
[2025-06-21 15:55:39 +0200] [20] [INFO] Retrieve hass get data method initiated…
[2025-06-21 15:55:41 +0200] [20] [INFO] EMHASS server online, serving index.html…
[2025-06-21 15:55:45 +0200] [20] [INFO] >> Performing dayahead optimization…
[2025-06-21 15:55:45 +0200] [20] [INFO] Performing day-ahead forecast optimization
[2025-06-21 15:55:45 +0200] [20] [INFO] Perform optimization for the day-ahead
[2025-06-21 15:55:45 +0200] [20] [WARNING] Solver default unknown, using default
[2025-06-21 15:55:45 +0200] [20] [INFO] Status: Infeasible
[2025-06-21 15:55:45 +0200] [20] [INFO] Total value of the Cost function = -859.72
[2025-06-21 15:55:45 +0200] [20] [INFO] Optimization status: Infeasible

I just realized that this was yesterdays status.
Today I get an optimal optimization status. Only thing that has changed is ā€œdef_total_hoursā€. Yesterday it was 5, today it is 3.

Is there a reason behind this??

Hi all, Can someone help me verify if there’s a flaw in my logic? I’ve defined just one load and set its def_total_hours to 0, so it shouldn’t run at all. But when EMHASS runs, it still schedules it to run. What am I missing here? I’ve been using EMHASS for over a year and haven’t seen this behavior before.

I haven’t had this problem, maybe you could try using the updated parameter of operating_hours_of_each_deferrable_load instead of def_total_hours

Sometimes this can happen if your EMHASS configuration has run hours, but your passing runtime payload is set to 0.

Hey. Have been using EMHASS for some time (I posted in here a long time ago).
At the weekend I updated EMHASS to the latest version and switched to the open-meteo forecast for PV generation. This is great and I find it a lot more accurate than the Forecast Solar data that I was manually collecting and passing into EMHASS when I calling naive-mpc-optim.

The one thing I am missing at the moment though is the total forecasted amount of PV generation in KWh for the current day, and for tomorrow. I have some logic that basically overrides some of the models and force charges my battery to 100% if PV generation is below a certain level for the entire day. However I’m not sure how to achieve this when the open-meteo data is all being handled by EMHASS.

It looks like EMHASS is doing a lot of logic with the weather forecast too, so I dont want to try and replicate that all myself, so it’d be ideal if I could somehow pull out the totals from EMHASS using the API or something. I’ve had a look through the docs, but I don’t really see how I’d do this from Home Assistant.

I did think about just adding up the total values returned via the p_pv entity, but since I run the forecasts every 15mins, this doesn’t work, as it only holds forecast from the current time for the next 24hrs.

Any help or suggestions you can offer would be much appreciated, thanks!

I use this approach, just count up the total energy in the future forecasts.

I divide by 2000 to convert the power (W) in EMHASS to 30 minute energy (kWh).

#EMHASS energy forecasts
    pv_forecast_energy:
      device_class: energy
      unit_of_measurement: kWh
      value_template: "{{(state_attr('sensor.p_pv_forecast','forecasts')|map(attribute='p_pv_forecast')|map('int')|sum/2000)|round(1)}}"

    p_load_forecast_energy:
      device_class: energy
      unit_of_measurement: kWh
      value_template: "{{(state_attr('sensor.p_load_forecast','forecasts')|map(attribute='p_load_forecast')|map('int')|sum/2000)|round(1)}}"