EMHASS: An Energy Management for Home Assistant

Right now the battery is discharging and is at 4% should go down to 2%. However, I know it happens to me sometimes and then the SOC is lower than they should be.

The funny thing is it was working fine before I upgraded to v0.11

Edited my shell script to
‘def_total_hours’: [5, 0], ‘def_end_timestep’: [7, 0]}
Then it worked immediately

post_naive_mpc_shell_nocar: >
  curl -i -H "Content-Type: application/json" -X POST -d '{
    "load_cost_forecast":{{((state_attr("sensor.nordpool_tibber", "raw_today") | map(attribute="value") | list  + state_attr("sensor.nordpool_tibber", "raw_tomorrow") | map(attribute="value") | list))[now().hour:][:24] }},
    "prod_price_forecast":{{((state_attr("sensor.nordpool_tibber", "raw_today") | map(attribute="value") | list  + state_attr("sensor.nordpool_tibber", "raw_tomorrow") | map(attribute="value") | list))[now().hour:][:24] }},
    "prediction_horizon":{{min(24, (((state_attr("sensor.nordpool_tibber", "raw_today")|map(attribute="value")|list + state_attr("sensor.nordpool_tibber", "raw_tomorrow") | map(attribute="value")| list)[now().hour:][:24]|list|length)))}},
    "pv_power_forecast":{{([states("sensor.inverter_input_power")|int(0)] + state_attr("sensor.solcast_pv_forecast_forecast_today", "detailedHourly")|selectattr("period_start","gt",utcnow()) | map(attribute="pv_estimate")|map("multiply",1000)|map("int")|list + state_attr("sensor.solcast_pv_forecast_forecast_tomorrow", "detailedHourly")|selectattr("period_start","gt",utcnow()) | map(attribute="pv_estimate")|map("multiply",1000)|map("int")|list)| tojson}},
    "load_power_forecast":{{[states('sensor.power_load_novar_loads')|int] +(states('input_text.fifo_buffer').split(',')|map('int')|list)[1:]}},
    "soc_init":{{ max(0,states("sensor.battery_state_of_capacity")|int(0))/100 }},
    "soc_final":{{ max(100,states("number.battery_end_of_discharge_soc")|int(0))/100 }},
    "delta_forecast":2,
    "alpha": 1,
    "beta": 0,
    "def_total_hours":[5, 0],
    "def_end_timestep":[7, 0]
  }' http://localhost:5000/action/naive-mpc-optim

VS Dont work

post_naive_mpc_shell_nocar: >
  curl -i -H "Content-Type: application/json" -X POST -d '{
    "load_cost_forecast":{{((state_attr("sensor.nordpool_tibber", "raw_today") | map(attribute="value") | list  + state_attr("sensor.nordpool_tibber", "raw_tomorrow") | map(attribute="value") | list))[now().hour:][:24] }},
    "prod_price_forecast":{{((state_attr("sensor.nordpool_tibber", "raw_today") | map(attribute="value") | list  + state_attr("sensor.nordpool_tibber", "raw_tomorrow") | map(attribute="value") | list))[now().hour:][:24] }},
    "prediction_horizon":{{min(24, (((state_attr("sensor.nordpool_tibber", "raw_today")|map(attribute="value")|list + state_attr("sensor.nordpool_tibber", "raw_tomorrow") | map(attribute="value")| list)[now().hour:][:24]|list|length)))}},
    "pv_power_forecast":{{([states("sensor.inverter_input_power")|int(0)] + state_attr("sensor.solcast_pv_forecast_forecast_today", "detailedHourly")|selectattr("period_start","gt",utcnow()) | map(attribute="pv_estimate")|map("multiply",1000)|map("int")|list + state_attr("sensor.solcast_pv_forecast_forecast_tomorrow", "detailedHourly")|selectattr("period_start","gt",utcnow()) | map(attribute="pv_estimate")|map("multiply",1000)|map("int")|list)| tojson}},
    "load_power_forecast":{{[states('sensor.power_load_novar_loads')|int] +(states('input_text.fifo_buffer').split(',')|map('int')|list)[1:]}},
    "soc_init":{{ max(0,states("sensor.battery_state_of_capacity")|int(0))/100 }},
    "soc_final":{{ max(100,states("number.battery_end_of_discharge_soc")|int(0))/100 }},
    "delta_forecast":2,
    "alpha": 1,
    "beta": 0,
    "def_total_hours":[{{ states('sensor.charger_def_hours') | default(0) }}, 0],
    "def_end_timestep": [0, 0]
  }' http://localhost:5000/action/naive-mpc-optim

delta_forecast has been changed to delta_forecast_daily, maybe that’s it

@davidusb @GeoDerp
I’ve noticed this in the supervisor log, not sure if I should track it among the issues of EMAHSS on github.
Just let me know:


EDIT
Solution here


2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'logging_level' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'costfun' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'sensor_power_photovoltaics' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'sensor_power_load_no_var_loads' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'set_total_pv_sell' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'set_nocharge_from_grid' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'set_nodischarge_to_grid' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'maximum_power_from_grid' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'maximum_power_to_grid' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'number_of_deferrable_loads' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'list_nominal_power_of_deferrable_loads' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'list_operating_hours_of_each_deferrable_load' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'list_start_timesteps_of_each_deferrable_load' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'list_end_timesteps_of_each_deferrable_load' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'list_peak_hours_periods_start_hours' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'list_peak_hours_periods_end_hours' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'list_treat_deferrable_load_as_semi_cont' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'list_set_deferrable_load_single_constant' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'list_set_deferrable_startup_penalty' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'load_peak_hours_cost' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'load_offpeak_hours_cost' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'photovoltaic_production_sell_price' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.083 WARNING (MainThread) [supervisor.addons.options] Option 'list_pv_module_model' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'list_pv_inverter_model' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'list_surface_tilt' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'list_surface_azimuth' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'list_modules_per_string' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'list_strings_per_inverter' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'inverter_is_hybrid' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'compute_curtailment' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'set_use_battery' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'battery_nominal_energy_capacity' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'optimization_time_step' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'historic_days_to_retrieve' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'method_ts_round' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'lp_solver' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'lp_solver_path' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'set_battery_dynamic' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'battery_dynamic_max' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'battery_dynamic_min' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'weight_battery_discharge' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'weight_battery_charge' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'load_forecast_method' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'battery_discharge_power_max' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'battery_charge_power_max' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'battery_discharge_efficiency' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'battery_charge_efficiency' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'battery_minimum_state_of_charge' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'battery_maximum_state_of_charge' does not exist in the schema for EMHASS (5b918bf2_emhass)
2024-11-15 13:34:26.084 WARNING (MainThread) [supervisor.addons.options] Option 'battery_target_state_of_charge' does not exist in the schema for EMHASS (5b918bf2_emhass)

Hi!

I’m still on 0.10.6 using the addon in Home assistant and I fear to upgrade to 0.11.2.
I use only one deferrable load (no battery) which is my heating system.
What if I upgrade? Are there any manual steps to be done? It seems the configuration is different, so, do I have to migrate that manually? How?
I have never done a restore. What would be the most convenient way to restore back to 0.10.6, if needed? Is this procedure described anywhere (step by step)?

Thanks!

  1. Before upgrading make sure to copy somewhere your add-on configuration text (here it is shown how to access it, valid also for previous versions of the add-on). You’ll need it later at step 4.
  2. Before upgrading make sure the flag “backup” is on.
  3. Click on upgrade
  4. After the upgrade, which may take a while, follow the instructions below (I linked the minute where the relevant part for you starts) to make sure your configuration is transferred to the new “format”.
  1. Then make sure your sensors (not the default ones) are being used for " Sensor to replace NAN values with 0s" and " Sensor to replace NAN values with linear interpolation". If not, edit the names/lists as needed.
  2. here

That’s it. The shell/restful commands should work straight away.

If you experience any problems you can roll back the add-on: go to Settings → System → Backup.
You should see something like addon_5b918bf2_emhass_0.10.6 (the backup that was created at steps 2 and 3). Select it, check the checkboxes, restore. When the process is over you’ll have your previous version of the add-on back.

2 Likes

I’d like to add
6. Remove the add-on yaml config. (Or most of it)

That’s where your logs in the supervisor come from.
More information is here: "Battery settings for the add-on incorrect" in HA Supervisor logs · Issue #103 · davidusb-geek/emhass-add-on · GitHub

3 Likes

If this is posted to me, im not 100% on that answer, i would assume it is but how can i verify?

Ive basicly copied marks system and robs within these threads

So if they have a moving mpc then yer this actually would make sence.

I havnt upgraded to the new emhass as its taken me so long to get this system work correctly im too scarsd to go through the upgrade just yet.

How would i get the car to charge and stay charging?

For some context, ‘normal’ prod_price is around 0.05 $/ kWh.

We are in the midst of a price ‘spike’ and EMHASS doesn’t want to sell now for 17.497 $/ kWh because it wants to wait for later when the forecast is to sell for $18.073 and $17.699. Mathematically it is correct.

However, these are forecasts and subject to change. So how can I weight EMHASS to act on almost high enough prices to sell now, rather than waiting for a future forecast?

I’ve been having the same issue (except with 30 min blocks), and it’s not exactly what you’ve asked but here’s my latest approach.

I’m not sure which advanced amber price you’ve been using, but my approach has been to to use the advanced_low for the next 6 blocks, then go for the advanced_predicted for there onwards.
Tonight during the spike it seemed to have discharged slightly earlier than it would have if I was just using advanced_predicted. I’m sure i’ve left some money on the table, but it was much better than my previous approach of using a single price.

But i’m with you, it’d be great to have a “prioritise/weight selling sooner than later” option somehow.

 "prod_price_forecast":
        {{ ([states("sensor.amber_feed_in_price")|float(0)]
        + (state_attr("sensor.amber_feed_in_forecast", "forecasts")|map(attribute="advanced_price_low")|list)[:5]
        + (state_attr("sensor.amber_feed_in_forecast", "forecasts")|map(attribute="advanced_price_predicted")|list)[5:])[:48]
        }},
1 Like

Creating the values for “load cost forecat” from Entsoe data as follows:
“load_cost_forecast”:{{((state_attr(‘sensor.entso_energy_average_electricity_price_today’,
‘prices’) | map(attribute=‘price’) | list))[now().hour:][:24] }}

With dynamic pricing of energy, some companies define the cost for returned energy as a value which is a fixed value less than the “load cost” price.
So:
I want to create the list for “prod_price_forecast” in the same way, but subtracting a fixed value from the “load_cost_forecast” list.
I can not find a way to accomplish this.
Note: This could also be a configuration item!!

It has been discussed:

interesting to see you’re getting ready for 5 min windows. at the moment, are you slicing some of the 30 mins blocks in 6 smaller blocks?
if so do you have the code on how you’re cutting up the different inputs to the MPC?

My plan for Amber is to run day-ahead for the full 24 hour schedule at 30 minute resolution and then run MPC on the 5 minute intervals data for the next 60-120 minutes.

The charts above are from a LocalVolts account (that I’m helping setup EMHASS) that has 288x 5 minute intervals for the full 24 hours, but as you have noticed the LV forecasts are just the 30 minute forecast repeated 6 times. LV doesn’t have the Amber Advanced Price Forecast and that really makes a difference to the level of trust you can put into the forecast. Last night as you saw from my chart, it would say a $17+ spike in the next 5 minute forecast, but the spike didn’t come for over an hour.

Optimisations for 5 minutes is going to be challenging with EMHASS. Say you get the confirmed price after 20-30 seconds. On a Home Assistant green (under powered) it can take up to a minute to process 288x 5 minute intervals so you don’t start charging or discharging until 1.30 into a 5 minute interval. Obviously more processing CPU would help, but I’m also thinking of just processing with MPC the next 6-12 x 5 minute intervals would also greatly reduced optimisation time, with little effect on outcomes.

yeah, i hear what you’re saying about the race to compute a result in a 5 min window

Thanks! That was helpfull.

I currently have an issue where the EMHASS add-on starts, but refuses to keep running.
It simply stops running, the (debug) logs are not helpful:

INFO - web_server - Launching the emhass webserver at: http://0.0.0.0:5000
INFO - web_server - Home Assistant data fetch will be performed using url: http://supervisor/core/api
INFO - web_server - The data path is: /share
INFO - web_server - The logging is: DEBUG
INFO - web_server - Using core emhass version: 0.11.2

It’s not triggered by a call to the REST API, (but those fail ofc.)
I already deleted all saved files from the add-on folder. To no avail.
I think it fails to aqcuire some data via the supervisor-api. But I don’t know why that happens.

Unsure what made the difference, but I was able to clear the box in the Web UI and was able to perform a perfect optimization again, followed by a Dayahead and MPC again.

passing max power from grid as a runtime parameter for day-ahead and mpc?

Here in Belgium you get punished with a capacity tariff which is the highest 15min average power drawn from grid in a month. (something like every 1kw over 2,5kw costst you 40€/year on top of your energy costs). When running the optimizer, day ahead or mpc it is important you stay under a certain preset limit. As my ambiton might change over time I have a input_number slider for that in home assistant (next to reading the actual value from the p1 meter).
Is there a way to pass the " maximum_power_from_grid" configuration setting as a runtime parameter? Or use a template in the Configuration like in the screenshot below perhaps?

I do not see it listed in the docs.

You are on the right track with the input slider, but it doesn’t go in your configuration file, you need to put it into your REST command or shell script when you can the optimisation.

Blockquote
you need to put it into your REST command or shell script when you can the optimisation

I know, I use a templated rest api call to configure my deferable loads from the home assistant UI, but since the " maximum_power_from_grid" parameter is’t listed in the " Passing other data at runtime section of the doc’s I didn’t think it was possible. That is why I asked

1 Like