Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standalone and Add-on merge #334

Merged

Conversation

GeoDerp
Copy link
Contributor

@GeoDerp GeoDerp commented Aug 2, 2024

Related to #269

@GeoDerp
Copy link
Contributor Author

GeoDerp commented Aug 2, 2024

This is still in early development

It's here to show progress. A lot has changed, and a lot will still need to be.
Will edit this comment as the PR progresses.

Edits:

  • Merged/Simplified EMHASS/Add-on Dockerfile
  • Added functionality to auto detect EMHASS on HAOS (choose to whether to use Supervisor API)
  • Suggested edit to migrate container registry from DockerHub to Github Projects. (Similar to Home Assistants, should functionally be the same) @davidusb-geek feel free to comment on this.
  • Simplified EMHASS-Add-on Github repo to bare minimum: Standalone and Add-on merge emhass-add-on#100
    • Copies the docker image from the EMHASS container registry
  • Simplified build_params with associations (similar to Fixed bug in #169 #181)
  • Dev Container now built from the main Dockerfile
  • Added dedicated function for checking parameters against deferrable load amount

Parameter / Config changes:

  • New configuration page has been added to the webserver to modify and save to config.json
  • config.json file has been added as the new config (centralized config for all users)
    • options.json is now only used for secrets (HAOS version of secrets_emhass.yaml)
      • config parameter naming conventions/definitions almost identical to options.json
        • EMHASS Add-on users can copy and past their existing json into the configuration page to generate the updated config.json file.
    • Removed config_emhass.yaml
    • Support for config_emhass.yaml still exists under legacy_config_path and will convert the parameter definitions for you (press save on the configuration page to save to config.json)
  • config_defaults.json added:
    • test reference
    • default state on configuration page
    • missing parameters in config.json (adding some support for optional params)

TODO:

  • Finalize EMHASS HAOS auto detect
    • Test HAOS auto detect
  • Update all documentation to match parameter definitions of config.json
    • EMHASS
    • EMHASS-add-on
  • Update all documentation to match the new method to run, dev & test EMHASS
    • EMHASS
    • EMHASS-add-on
  • Modify GitHub Actions to publish images to github container registry
  • Plan and implement parameter defaults location
  • Update unittests
    • Update unittest to test new functionality
  • Thorough Test EMHASS/EMHASS-Add-on functionality
    • Thorough Test configuration functionality
  • Finalize build_params associations
  • Fix functionality of Dev Container

Secret and Config Example

EMHASS methods

configuration page

List view example

Screenshot 2024-09-03 at 19-16-27 EMHASS Energy Management Optimization for Home Assistant

Box view example

Screenshot 2024-09-03 at 19-16-40 EMHASS Energy Management Optimization for Home Assistant

@GeoDerp
Copy link
Contributor Author

GeoDerp commented Aug 3, 2024

I am currently unsure how we should approach the parameter naming conventions moving forward.
This PR is currently set up with the EMHASS code as the original parameter naming convention, and the options.json the add-on naming conversation (options.json being converted in build_parms with the associations list.
However, we could also change all the parameters in the options.json to match the original.
Moreover, we could change the code to match the options.json parameter naming.
Either way I'm planning on making a script that will help users to convert from one to the other for an easier transition.

@davidusb-geek
Copy link
Owner

It would be probably best to change the code to match the options.json, those names are way more explicit

src/emhass/utils.py Fixed Show fixed Hide fixed
@@ -484,8 +363,8 @@
# Launch server
port = int(os.environ.get('PORT', 5000))
app.logger.info("Launching the emhass webserver at: http://"+web_ui_url+":"+str(port))
app.logger.info("Home Assistant data fetch will be performed using url: "+hass_url)
app.logger.info("Home Assistant data fetch will be performed using url: "+params_secrets['hass_url'])

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

This expression logs
sensitive data (secret)
as clear text.
This expression logs
sensitive data (secret)
as clear text.
@GeoDerp

This comment was marked as outdated.

@GeoDerp

This comment was marked as outdated.

with emhass_conf['associations_path'].open('r') as data:
associations = list(csv.reader(data, delimiter=","))
else:
logger.error("Cant find associations file (associations.csv) in: " + str(emhass_conf['associations_path']))

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

This expression logs
sensitive data (secret)
as clear text.
This expression logs
sensitive data (secret)
as clear text.
This expression logs
sensitive data (private)
as clear text.
This expression logs
sensitive data (private)
as clear text.
This expression logs
sensitive data (secret)
as clear text.
This expression logs
sensitive data (secret)
as clear text.
This expression logs
sensitive data (private)
as clear text.
This expression logs
sensitive data (private)
as clear text.
@GeoDerp

This comment was marked as outdated.

@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

Comment on lines +635 to +639
document.getElementById("config-box").innerHTML = JSON.stringify(
config,
null,
2
);

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.
@GeoDerp
Copy link
Contributor Author

GeoDerp commented Aug 30, 2024

The hope is to do some testing then create a video tomorrow showing the progress and how this PR works.
Im also hoping that we can find some people that can help with things like testing, unitest of new functionality and refreshing the documentation.

@davidusb-geek davidusb-geek merged commit 0215cb3 into davidusb-geek:master Oct 25, 2024
13 of 14 checks passed
@GeoDerp
Copy link
Contributor Author

GeoDerp commented Oct 25, 2024

Amazing! Let me know if you need any clarification on anything, or need me to fix something. 👍

@davidusb-geek
Copy link
Owner

davidusb-geek commented Oct 25, 2024

Amazing! Let me know if you need any clarification on anything, or need me to fix something. 👍

Ok will do 👍

A quick first question: on the add-on repo all github workflows are commented out. So this is normal since all will be dealed here in the main EMHASS code repo right?
If so I've just disabled actions on the add-on repo for now

@GeoDerp
Copy link
Contributor Author

GeoDerp commented Oct 25, 2024

Amazing! Let me know if you need any clarification on anything, or need me to fix something. 👍

Ok will do 👍

A quick first question: on the add-on repo all github workflows are commented out. So this is normal since all will be dealed here in the main EMHASS code repo right?
If so I've just disabled actions on the add-on repo for now

Yep, that is correct. 👍

@davidusb-geek
Copy link
Owner

davidusb-geek commented Oct 25, 2024

Ok, released a new version.
Then locally tested the add-on on my own HA instance using the method: "Adding EMHASS-Add-on into pre-existing Home Assistant environment".
Configured my config.json from the webserver, saved and launched a day-ahead optimization.
Everything went smoothly.
Proceeding to push the new add-on release version.
Impressive work @GeoDerp, Cheers!

GeoDerp added a commit to GeoDerp/emhass that referenced this pull request Oct 26, 2024
@purcell-lab
Copy link
Contributor

purcell-lab commented Oct 26, 2024

Then locally tested the add-on on my own HA instance using the method: "Adding EMHASS-Add-on into pre-existing Home Assistant environment".

I seem to be missing the upgrade step.

I took my existing 0.10.6 and upgraded to 0.11.0, but wasn't offered an opportunity to bring across my old configuration and then was running 0.11.0 with a 'default' configuration.

Rolling back to by backup on 0.10.6 was successful and has restarted with my working config.

@purcell-lab
Copy link
Contributor

I will continue to report my experiences here, but let me know if these would be better to raise as issues.

I have now manually taken my YAML config from 0.10.6 and copy/ converted to 0.11.0, which seems to convert correctly.

There is a hard coded reference to sensor_power_photovoltaics (in the replace NAN values), but I have changed by sensor entity to sensor.apf_generation_entity, which then causes an error.

Screenshot 2024-10-26 15 47 05
Screenshot 2024-10-26 15 46 39

When I updated the replace NAN values with my updated entity, I could go to the next stage.

@davidusb-geek
Copy link
Owner

I will continue to report my experiences here, but let me know if these would be better to raise as issues.

I have now manually taken my YAML config from 0.10.6 and copy/ converted to 0.11.0, which seems to convert correctly.

There is a hard coded reference to sensor_power_photovoltaics (in the replace NAN values), but I have changed by sensor entity to sensor.apf_generation_entity, which then causes an error.

When I updated the replace NAN values with my updated entity, I could go to the next stage.

Yes it is a manual conversion of the configuration file, is not automatic.
So after manually changing to the correct names for your sensors everything is working fine?

@GeoDerp
Copy link
Contributor Author

GeoDerp commented Oct 26, 2024

I will continue to report my experiences here, but let me know if these would be better to raise as issues.

I have now manually taken my YAML config from 0.10.6 and copy/ converted to 0.11.0, which seems to convert correctly.

There is a hard coded reference to sensor_power_photovoltaics (in the replace NAN values), but I have changed by sensor entity to sensor.apf_generation_entity, which then causes an error.

Screenshot 2024-10-26 15 47 05
Screenshot 2024-10-26 15 46 39

When I updated the replace NAN values with my updated entity, I could go to the next stage.

Ah yes, because sensor_linear_interp & sensor_replace_zero are new parameters for the add-on users, so there was no conversation. May be good to note that.

@purcell-lab
Copy link
Contributor

So after manually changing to the correct names for your sensors everything is working fine?

No unfortunately not, I haven't been able to get a stable optimisation. When I call my MPC optimisation the call times out. As does the day ahead optimisation.

I'm going to try and simplify my. MPC call to see if I can start with something functional.

@GeoDerp
Copy link
Contributor Author

GeoDerp commented Oct 26, 2024

So after manually changing to the correct names for your sensors everything is working fine?

No unfortunately not, I haven't been able to get a stable optimisation. When I call my MPC optimisation the call times out. As does the day ahead optimisation.

I'm going to try and simplify my. MPC call to see if I can start with something functional.

Feel free to send the logs over if you find anything and I'll look Into it. If you could also uninstall the add-on and re-install to see if that changes anything. I'm guessing not but it might be a weird cache issue?

@GeoDerp
Copy link
Contributor Author

GeoDerp commented Oct 26, 2024

Im looking into this issue now.
I can't seem to replicate the issue, tho I do believe initially I saw something that could be similar. Let me know how you go @purcell-lab.

@GeoDerp
Copy link
Contributor Author

GeoDerp commented Oct 28, 2024

Sorry to bug you gain @purcell-lab , while I'm fixing the other bugs, are there any logs I can observe for your issues?
Might be also good to get a json string of one of your MPC calls. (and maybe config)

@kcoffau
Copy link

kcoffau commented Oct 29, 2024

Hi,

ive migrated my config across and it runs in the UI.

Like @purcell-lab I am using the script to publish my Solcast, price and battery data from HA into EMHASS.

My first note is that my battery used to be sent as 51% as "0.51". Its seems to now be expecting "51". So I updated that.. But now its publishing "5105.23" back, so there seems to be a multiplier issue.

I am getting very abnormal results elsewhere as well, but i am going to start with Battery SOC.

Kel.

image
This is a 2 day outlook and i would expect it to cycle the battery 4 times in 2 days for my setup.

I`ll keep digging later, got to get back to "actual work", but the UI is a great step in the right direction. The solar/inverter would be great as a searchable selector/dropdown as people find the underscore stuff confusing.

FYI this is my shell command
post_mpc_optim_ev_freelunch_ext: "curl -i -H \"Content-Type: application/json\" -X POST -d '{\"load_cost_forecast\":[{% set current_time = now() %}{% set base_time = current_time.replace(minute=0, second=0, microsecond=0) if current_time.minute < 30 else current_time.replace(minute=30, second=0, microsecond=0) %}{% for offset in range(96) %}{% set nowish = base_time + timedelta(minutes=30*offset) %}{{ states('input_number.ovo_power_plan_ev_cost') if 0 <= nowish.hour < 6 else states('input_number.ovo_power_plan_free_lunch_cost') if 11 <= nowish.hour < 14 else states('input_number.ovo_power_plan_peak_cost') }}{% if not loop.last %}, {% endif %}{% endfor %}], \"prod_price_forecast\":[{% for _ in range(96) %}{{states('input_number.ovo_power_plan_solar_fit')}}{% if not loop.last %}, {% endif %}{% endfor %}], \"pv_power_forecast\":{{(((state_attr('sensor.solcast_pv_forecast_forecast_today', 'detailedForecast') +(state_attr('sensor.solcast_pv_forecast_forecast_tomorrow', 'detailedForecast')) +(state_attr('sensor.solcast_pv_forecast_forecast_day_3', 'detailedForecast')) +(state_attr('sensor.solcast_pv_forecast_forecast_day_4', 'detailedForecast')) +(state_attr('sensor.solcast_pv_forecast_forecast_day_5', 'detailedForecast')) +(state_attr('sensor.solcast_pv_forecast_forecast_day_6', 'detailedForecast')) +(state_attr('sensor.solcast_pv_forecast_forecast_day_7', 'detailedForecast'))) |selectattr('period_start', 'ge', now() - timedelta(minutes=29.99)) | map(attribute='pv_estimate')|map('multiply',1000)|map('int')|list)[:96])}}, \"prediction_horizon\":{{min(96,(state_attr('sensor.solcast_pv_forecast_forecast_today', 'detailedForecast')|length + state_attr('sensor.solcast_pv_forecast_forecast_tomorrow', 'detailedForecast')|length + state_attr('sensor.solcast_pv_forecast_forecast_day_3', 'detailedForecast')|length + state_attr('sensor.solcast_pv_forecast_forecast_day_4', 'detailedForecast')|length + state_attr('sensor.solcast_pv_forecast_forecast_day_5', 'detailedForecast')|length + state_attr('sensor.solcast_pv_forecast_forecast_day_6', 'detailedForecast')|length + state_attr('sensor.solcast_pv_forecast_forecast_day_7', 'detailedForecast')|length))}},\"soc_init\":{{states('sensor.victron_battery_state_of_charge_system')|float(0)/1}},\"def_total_hours\":[0]}' http://localhost:5000/action/naive-mpc-optim"

The EMHASS Logs are here:
2024-10-29 11:43:17,622 - web_server - INFO - Passed runtime parameters: {'load_cost_forecast': [0.0, 0.0, 0.0, 0.0, 0.0, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.0], 'prod_price_forecast': [0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03], 'pv_power_forecast': [4500, 4652, 4685, 4611, 4188, 3776, 3450, 3179, 2806, 2341, 1770, 1132, 575, 157, 110, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 51, 381, 1225, 1986, 2743, 3532, 4150, 4685, 5000, 5000, 5000, 5000, 5000, 5000, 4786, 4482, 4272, 4007, 3525, 3021, 2404, 1751, 1124, 579, 168, 115, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 165, 940, 1757, 2483, 3229, 3938, 4418, 4781, 5000, 5000, 5000], 'prediction_horizon': 96, 'soc_init': 51.0, 'def_total_hours': [0]}
2024-10-29 11:43:17,623 - web_server - INFO - >> Setting input data dict
2024-10-29 11:43:17,634 - web_server - INFO - Setting up needed data
2024-10-29 11:43:17,639 - web_server - INFO - Retrieve hass get data method initiated...
2024-10-29 11:43:20,272 - web_server - INFO - EMHASS server online, serving index.html...
2024-10-29 11:43:24,081 - web_server - INFO - EMHASS server online, serving index.html...
2024-10-29 11:43:24,390 - web_server - INFO - Retrieving weather forecast data using method = list
2024-10-29 11:43:24,393 - web_server - INFO - Retrieving data from hass for load forecast using method = naive
2024-10-29 11:43:24,394 - web_server - INFO - Retrieve hass get data method initiated...
2024-10-29 11:43:28,090 - web_server - INFO - EMHASS server online, serving index.html...
2024-10-29 11:43:36,040 - web_server - INFO - >> Performing naive MPC optimization...
2024-10-29 11:43:36,041 - web_server - INFO - Performing naive MPC optimization
2024-10-29 11:43:36,130 - web_server - INFO - Perform an iteration of a naive MPC controller
2024-10-29 11:43:36,724 - web_server - INFO - Status: Infeasible
2024-10-29 11:43:36,725 - web_server - INFO - Total value of the Cost function = 256.80
2024-10-29 11:43:42,301 - web_server - INFO - Passed runtime parameters: {}
2024-10-29 11:43:42,301 - web_server - INFO - >> Setting input data dict
2024-10-29 11:43:42,301 - web_server - INFO - Setting up needed data
2024-10-29 11:43:42,311 - web_server - INFO - >> Publishing data...
2024-10-29 11:43:42,323 - web_server - INFO - Publishing data to HASS instance
2024-10-29 11:43:42,369 - web_server - INFO - Successfully posted to sensor.p_pv_forecast = 4113.88
2024-10-29 11:43:42,401 - web_server - INFO - Successfully posted to sensor.p_load_forecast = 2147.05
2024-10-29 11:43:42,424 - web_server - INFO - Successfully posted to sensor.p_deferrable0 = 0.0
2024-10-29 11:43:42,447 - web_server - INFO - Successfully posted to sensor.p_deferrable1 = 0.0
2024-10-29 11:43:42,473 - web_server - INFO - Successfully posted to sensor.p_batt_forecast = -8000.0
2024-10-29 11:43:42,497 - web_server - INFO - Successfully posted to sensor.soc_batt_forecast = 5105.23
2024-10-29 11:43:42,521 - web_server - INFO - Successfully posted to sensor.p_grid_forecast = 6033.17
2024-10-29 11:43:42,541 - web_server - INFO - Successfully posted to sensor.total_cost_fun_value = -124.98
2024-10-29 11:43:42,561 - web_server - INFO - Successfully posted to sensor.optim_status = Infeasible
2024-10-29 11:43:42,591 - web_server - INFO - Successfully posted to sensor.unit_load_cost = 0.0
2024-10-29 11:43:42,614 - web_server - INFO - Successfully posted to sensor.unit_prod_price = 0.03

UPDATE: this was on version v0.11.0
Updating to v0.11.1 and will repost results. Just saw it was published in last few minutes.

@kcoffau
Copy link

kcoffau commented Oct 29, 2024

image
Unsure if v0.11.1 fixed it, or what, but i am not back to normal.

i also fiddled with settings.
image

image

Log:
2024-10-29 13:26:54,289 - web_server - INFO - Saved parameters from webserver
2024-10-29 13:27:02,395 - web_server - INFO - Passed runtime parameters: {'load_cost_forecast': [0.0, 0.0, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.4202, 0.0, 0.0, 0.0, 0.0], 'prod_price_forecast': [0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03], 'pv_power_forecast': [4968, 4749, 4447, 4031, 3558, 3013, 2405, 1759, 1133, 596, 175, 116, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 54, 432, 1297, 2071, 2844, 3670, 4287, 4703, 5000, 5000, 5000, 5000, 5000, 5000, 4850, 4542, 4346, 4007, 3525, 3021, 2404, 1772, 1121, 554, 151, 104, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 150, 874, 1697, 2429, 3188, 3932, 4418, 4781, 5000, 5000, 5000, 5000, 5000, 4956], 'prediction_horizon': 96, 'soc_init': 0.65, 'def_total_hours': [0]}
2024-10-29 13:27:02,396 - web_server - INFO - >> Setting input data dict
2024-10-29 13:27:02,396 - web_server - INFO - Setting up needed data
2024-10-29 13:27:02,402 - web_server - INFO - Retrieve hass get data method initiated...
2024-10-29 13:27:05,192 - web_server - INFO - Retrieving weather forecast data using method = list
2024-10-29 13:27:05,202 - web_server - INFO - Retrieving data from hass for load forecast using method = naive
2024-10-29 13:27:05,203 - web_server - INFO - Retrieve hass get data method initiated...
2024-10-29 13:27:17,095 - web_server - INFO - >> Performing naive MPC optimization...
2024-10-29 13:27:17,095 - web_server - INFO - Performing naive MPC optimization
2024-10-29 13:27:17,140 - web_server - INFO - Perform an iteration of a naive MPC controller
2024-10-29 13:27:18,587 - web_server - INFO - Status: Optimal
2024-10-29 13:27:18,587 - web_server - INFO - Total value of the Cost function = -8.24
2024-10-29 13:27:24,859 - web_server - INFO - Passed runtime parameters: {}
2024-10-29 13:27:24,860 - web_server - INFO - >> Setting input data dict
2024-10-29 13:27:24,861 - web_server - INFO - Setting up needed data
2024-10-29 13:27:24,865 - web_server - INFO - >> Publishing data...
2024-10-29 13:27:24,865 - web_server - INFO - Publishing data to HASS instance
2024-10-29 13:27:24,898 - web_server - INFO - Successfully posted to sensor.p_pv_forecast = 4997.79
2024-10-29 13:27:24,923 - web_server - INFO - Successfully posted to sensor.p_load_forecast = 1357.25
2024-10-29 13:27:24,945 - web_server - INFO - Successfully posted to sensor.p_hybrid_inverter = -3002.21
2024-10-29 13:27:24,965 - web_server - INFO - Successfully posted to sensor.p_deferrable0 = 0.0
2024-10-29 13:27:24,987 - web_server - INFO - Successfully posted to sensor.p_deferrable1 = 0.0
2024-10-29 13:27:25,008 - web_server - INFO - Successfully posted to sensor.p_batt_forecast = -8000.0
2024-10-29 13:27:25,031 - web_server - INFO - Successfully posted to sensor.soc_batt_forecast = 70.28
2024-10-29 13:27:25,062 - web_server - INFO - Successfully posted to sensor.p_grid_forecast = 4359.47
2024-10-29 13:27:25,084 - web_server - INFO - Successfully posted to sensor.total_cost_fun_value = -8.24
2024-10-29 13:27:25,104 - web_server - INFO - Successfully posted to sensor.optim_status = Optimal
2024-10-29 13:27:25,127 - web_server - INFO - Successfully posted to sensor.unit_load_cost = 0.0
2024-10-29 13:27:25,152 - web_server - INFO - Successfully posted to sensor.unit_prod_price = 0.03
2024-10-29 13:27:58,844 - web_server - INFO - EMHASS server online, serving index.html...
2024-10-29 13:28:48,179 - web_server - INFO - serving configuration.html...
2024-10-29 13:28:48,320 - web_server - INFO - Obtaining parameters from config.json:

@purcell-lab
Copy link
Contributor

purcell-lab commented Oct 29, 2024

Upgraded to v0.11.1.

Still not having joy.

The REST post timeouts for me, I have extended timeout to 120 seconds.

image

Unfortunately the logs don't provide much context:

2024-10-29 12:39:56,310 - web_server - INFO - Launching the emhass webserver at: http://0.0.0.0:5000
2024-10-29 12:39:56,310 - web_server - INFO - Home Assistant data fetch will be performed using url: http://supervisor/core/api
2024-10-29 12:39:56,310 - web_server - INFO - The data path is: /app/data
2024-10-29 12:39:56,311 - web_server - INFO - The logging is: INFO
2024-10-29 12:39:56,314 - web_server - INFO - Using core emhass version: 0.11.1
waitress   INFO  Serving on http://0.0.0.0:5000
2024-10-29 12:40:21,401 - web_server - INFO - Passed runtime parameters: {'load_cost_forecast': [0.04, 0.05, 0.05, 0.05, 0.06, 0.08, 0.09, 0.26, 0.29, 0.33, 0.39, 0.46, 0.48, 0.45, 0.41, 0.4, 0.39, 0.26, 0.25, 0.24, 0.23, 0.22, 0.22, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.22, 0.22, 0.18, 0.13, 0.11, 0.11, 0.1, 0.1, 0.07, 0.06, 0.06, 0.06, 0.05, 0.05, 0.05, 0.05, 0.05], 'prod_price_forecast': [-0.04, -0.04, -0.04, -0.03, -0.03, -0.01, 0.0, 0.02, 0.05, 0.08, 0.14, 0.2, 0.22, 0.19, 0.16, 0.15, 0.14, 0.13, 0.12, 0.11, 0.11, 0.1, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.08, 0.08, 0.09, 0.09, 0.1, 0.1, 0.06, 0.02, -0.0, -0.0, -0.01, -0.01, -0.02, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03], 'prediction_horizon': 48, 'alpha': 0, 'beta': 1, 'num_def_loads': 6, 'def_total_hours': [0, 0, 0, 7, 13, 4], 'def_end_timestep': [0, 0, 0, 0, 0, 0], 'P_deferrable_nom': [1000, 6333, 11520, 500, 600, 11520], 'def_current_state': [0, 0, 0, 1, 1, 1], 'def_start_penalty': [1, 1, 1, 1, 1, 1], 'treat_def_as_semi_cont': [1, 1, 0, 0, 1, 0], 'set_def_constant': [0, 0, 0, 0, 0, 0], 'soc_init': 0.92, 'soc_final': 1}
2024-10-29 12:40:21,402 - web_server - INFO -  >> Setting input data dict
2024-10-29 12:40:21,402 - web_server - INFO - Setting up needed data
2024-10-29 12:40:21,454 - web_server - INFO - Retrieve hass get data method initiated...
2024-10-29 12:40:22,706 - web_server - INFO - Retrieving weather forecast data using method = scrapper
2024-10-29 12:40:26,342 - web_server - INFO - Retrieving data from hass for load forecast using method = naive
2024-10-29 12:40:26,343 - web_server - INFO - Retrieve hass get data method initiated...
2024-10-29 12:40:29,641 - web_server - INFO -  >> Performing naive MPC optimization...
2024-10-29 12:40:29,642 - web_server - INFO - Performing naive MPC optimization
2024-10-29 12:40:29,674 - web_server - INFO - Perform an iteration of a naive MPC controller
{
  "battery_charge_efficiency": 0.95,
  "battery_charge_power_max": 11000,
  "battery_discharge_efficiency": 0.95,
  "battery_discharge_power_max": 15000,
  "battery_dynamic_max": 0.9,
  "battery_dynamic_min": -0.9,
  "battery_maximum_state_of_charge": 1,
  "battery_minimum_state_of_charge": 0,
  "battery_nominal_energy_capacity": 40500,
  "battery_target_state_of_charge": 0.1,
  "compute_curtailment": true,
  "continual_publish": false,
  "costfun": "profit",
  "delta_forecast_daily": 2,
  "end_timesteps_of_each_deferrable_load": [
    0,
    0,
    0,
    0,
    0,
    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.09,
  "load_peak_hour_periods": {
    "period_hp_1": [
      {
        "start": "02:54"
      },
      {
        "end": "15:24"
      }
    ],
    "period_hp_2": [
      {
        "start": "17:24"
      },
      {
        "end": "20:24"
      }
    ]
  },
  "load_peak_hours_cost": 0.31,
  "logging_level": "INFO",
  "lp_solver": "COIN_CMD",
  "lp_solver_path": "/usr/bin/cbc",
  "maximum_power_from_grid": 50000,
  "maximum_power_to_grid": 30000,
  "method_ts_round": "first",
  "modules_per_string": [
    29,
    21
  ],
  "nominal_power_of_deferrable_loads": [
    1340,
    5000,
    11500,
    4000,
    600,
    11500
  ],
  "number_of_deferrable_loads": 6,
  "operating_hours_of_each_deferrable_load": [
    4,
    2,
    0,
    0,
    3,
    0
  ],
  "optimization_time_step": 30,
  "photovoltaic_production_sell_price": 0.05,
  "production_price_forecast_method": "constant",
  "pv_inverter_model": [
    "SolarEdge_Technologies_Ltd___SE7600A_US__208V_",
    "SolarEdge_Technologies_Ltd___SE7600A_US__208V_"
  ],
  "pv_module_model": [
    "Advance_Power_API_M370",
    "Advance_Power_API_M370"
  ],
  "sensor_linear_interp": [
    "sensor.apf_generation_entity",
    "sensor.power_load_no_var_loads"
  ],
  "sensor_power_load_no_var_loads": "sensor.power_load_no_var_loads",
  "sensor_power_photovoltaics": "sensor.apf_generation_entity",
  "sensor_replace_zero": [
    "sensor.apf_generation_entity",
    "sensor.power_load_no_var_loads"
  ],
  "set_battery_dynamic": true,
  "set_deferrable_load_single_constant": [
    false,
    false,
    false,
    false,
    false,
    false
  ],
  "set_deferrable_startup_penalty": [
    5,
    1,
    0,
    1,
    10,
    0
  ],
  "set_nocharge_from_grid": false,
  "set_nodischarge_to_grid": false,
  "set_total_pv_sell": false,
  "set_use_battery": true,
  "set_zero_min": true,
  "start_timesteps_of_each_deferrable_load": [
    0,
    0,
    0,
    0,
    0,
    0
  ],
  "strings_per_inverter": [
    1,
    1
  ],
  "surface_azimuth": [
    90,
    270
  ],
  "surface_tilt": [
    18,
    10
  ],
  "treat_deferrable_load_as_semi_cont": [
    true,
    true,
    false,
    false,
    true,
    false
  ],
  "weather_forecast_method": "scrapper",
  "weight_battery_charge": 1,
  "weight_battery_discharge": 0.05
}

@GeoDerp
Copy link
Contributor Author

GeoDerp commented Oct 29, 2024

Thanks @kcoffau & @purcell-lab , I'll have a look at this and see if I can find anything. It may get out of the realm for me to fix (depending on where the issue/s resides). So I may need @davidusb-geek 's help. But I'll let you know after I have a look.

@GeoDerp
Copy link
Contributor Author

GeoDerp commented Oct 29, 2024

@purcell-lab , It looks like the optimization is being stuck after the last Validated window. I'm not quite sure why. Any ideas @davidusb-geek ? It looks like a battery problem. ("set_use_battery": false, fixes the issue) May be related to @kcoffau 's issue?

waitress   INFO  Serving on http://0.0.0.0:5000
2024-10-29 11:38:58,301 - web_server - INFO - EMHASS server online, serving index.html...
2024-10-29 11:39:01,586 - web_server - INFO - Passed runtime parameters: {}
2024-10-29 11:39:01,586 - web_server - INFO -  >> Setting input data dict
2024-10-29 11:39:01,586 - web_server - INFO - Setting up needed data
2024-10-29 11:39:01,599 - web_server - INFO - Retrieving weather forecast data using method = scrapper
2024-10-29 11:39:03,484 - web_server - INFO - Retrieving data from hass for load forecast using method = naive
2024-10-29 11:39:03,485 - web_server - INFO - Retrieve hass get data method initiated...
2024-10-29 11:39:03,918 - web_server - INFO -  >> Performing dayahead optimization...
2024-10-29 11:39:03,918 - web_server - INFO - Performing day-ahead forecast optimization
2024-10-29 11:39:03,920 - web_server - INFO - Perform optimization for the day-ahead
2024-10-29 11:39:04,014 - web_server - DEBUG - Deferrable load 0: Proposed optimization window: 0 --> 0
2024-10-29 11:39:04,014 - web_server - DEBUG - Deferrable load 0: Validated optimization window: 0 --> 0
2024-10-29 11:39:04,027 - web_server - DEBUG - Deferrable load 1: Proposed optimization window: 0 --> 0
2024-10-29 11:39:04,027 - web_server - DEBUG - Deferrable load 1: Validated optimization window: 0 --> 0
2024-10-29 11:39:04,038 - web_server - DEBUG - Deferrable load 2: Proposed optimization window: 0 --> 0
2024-10-29 11:39:04,038 - web_server - DEBUG - Deferrable load 2: Validated optimization window: 0 --> 0
2024-10-29 11:39:04,049 - web_server - DEBUG - Deferrable load 3: Proposed optimization window: 0 --> 0
2024-10-29 11:39:04,049 - web_server - DEBUG - Deferrable load 3: Validated optimization window: 0 --> 0
2024-10-29 11:39:04,063 - web_server - DEBUG - Deferrable load 4: Proposed optimization window: 0 --> 0
2024-10-29 11:39:04,063 - web_server - DEBUG - Deferrable load 4: Validated optimization window: 0 --> 0
2024-10-29 11:39:04,074 - web_server - DEBUG - Deferrable load 5: Proposed optimization window: 0 --> 0
2024-10-29 11:39:04,075 - web_server - DEBUG - Deferrable load 5: Validated optimization window: 0 --> 0

Using Marks config above.

P.s. Ill be revisiting the runtime parameters soon from this PR. I believe there are defiantly places I can fix up.

@davidusb-geek
Copy link
Owner

davidusb-geek commented Oct 29, 2024

@purcell-lab , It looks like the optimization is being stuck after the last Validated window. I'm not quite sure why. Any ideas @davidusb-geek ? It looks like a battery problem. ("set_use_battery": false, fixes the issue) May be related to @kcoffau 's issue?

Unfortunately no idea for now, this will need debugging

@purcell-lab
Copy link
Contributor

Is the documentation for 0.10.6 still available, as a number of the variables are changed I still need access to the previous documentation.

On a site with 0.10.6 installed the documentation link goes to the latest version, which of course is now 0.11.1, which isn't relevant.

@purcell-lab
Copy link
Contributor

P.s. Ill be revisiting the runtime parameters soon from this PR. I believe there are defiantly places I can fix up.

It would also be great to get more debugging info as the various states are processed, so we can see where the system need attention.

#350

@GeoDerp
Copy link
Contributor Author

GeoDerp commented Oct 31, 2024

I'll have a relook at your issue @purcell-lab likely today with 0.11.2 to see if the issue still persists.

@GeoDerp
Copy link
Contributor Author

GeoDerp commented Oct 31, 2024

Is the documentation for 0.10.6 still available, as a number of the variables are changed I still need access to the previous documentation.

On a site with 0.10.6 installed the documentation link goes to the latest version, which of course is now 0.11.1, which isn't relevant.

In read the docs, there is a option to select version. So there may be a way for us to set like a 0.10.6 tag/snapshot.

For now you can view the GitHub version snapshots:

https://github.com/davidusb-geek/emhass/tree/v0.10.6

https://github.com/davidusb-geek/emhass-add-on/tree/v0.10.6

And also the docs page: https://emhass.readthedocs.io/en/latest/differences.html#legacy-parameter-definitions
For the parameter conversation from the 0.10.x to 0.11.0

@GeoDerp
Copy link
Contributor Author

GeoDerp commented Oct 31, 2024

Looks like the issue still persists with @purcell-lab 's config. I believe its something to do with the battery, I'll do some searching. Unable to find the fault so far.

@kcoffau
Copy link

kcoffau commented Oct 31, 2024

@purcell-lab

ive compared our config:
Mine is below for reference.

I note the following differences (that just arent general settings)
"battery_maximum_state_of_charge": 1,

  • I had an issue with setting 1, and had to set to 0.99

"battery_minimum_state_of_charge": 0,

  • I had an issue with setting 0, and had to set 0.01

"set_battery_dynamic": true,"

  • i could never get this to work. Did you want to try disabling for troubleshooting?

"weight_battery_charge": 1,"
"weight_battery_discharge": 0.05"

  • both of these values after the last release i was getting very obscure behaviour. I set them both to "0" and it resolved it.

Ohh, and your SOC_final in your CURL is also 1. Did you want to troubleshoot with a 0.99?

Otherwise your config looks within reason the same as mine, +/- inverter/grid/solar settings.


{
  "battery_charge_efficiency": 0.99,
  "battery_charge_power_max": 8000,
  "battery_discharge_efficiency": 0.99,
  "battery_discharge_power_max": 8000,
  "battery_dynamic_max": 0.9,
  "battery_dynamic_min": -0.9,
  "battery_maximum_state_of_charge": 0.99,
  "battery_minimum_state_of_charge": 0.01,
  "battery_nominal_energy_capacity": 75000,
  "battery_target_state_of_charge": 0.98,
  "compute_curtailment": false,
  "continual_publish": false,
  "costfun": "profit",
  "delta_forecast_daily": 2,
  "end_timesteps_of_each_deferrable_load": [
    0,
    0
  ],
  "historic_days_to_retrieve": 3,
  "inverter_is_hybrid": true,
  "load_cost_forecast_method": "hp_hc_periods",
  "load_forecast_method": "naive",
  "load_negative": false,
  "load_offpeak_hours_cost": 0.08,
  "load_peak_hour_periods": {
    "period_hp_1": [
      {
        "start": "06:00"
      },
      {
        "end": "11:00"
      }
    ],
    "period_hp_2": [
      {
        "start": "14:00"
      },
      {
        "end": "23:59"
      }
    ]
  },
  "load_peak_hours_cost": 0.48,
  "logging_level": "INFO",
  "lp_solver": "COIN_CMD",
  "lp_solver_path": "/usr/bin/cbc",
  "maximum_power_from_grid": 15000,
  "maximum_power_to_grid": 5000,
  "method_ts_round": "nearest",
  "modules_per_string": [
    11
  ],
  "nominal_power_of_deferrable_loads": [
    0,
    0
  ],
  "number_of_deferrable_loads": 2,
  "operating_hours_of_each_deferrable_load": [
    0,
    0
  ],
  "optimization_time_step": 30,
  "photovoltaic_production_sell_price": 0.03,
  "production_price_forecast_method": "constant",
  "pv_inverter_model": [
    "Fronius_International_GmbH__Fronius_Primo_5_0_1_208_240__240V_"
  ],
  "pv_module_model": [
    "CSUN_Eurasia_Energy_Systems_Industry_and_Trade_CSUN295_60M"
  ],
  "sensor_linear_interp": [
    "sensor.power_ac_fronius_inverter_1_192_168_10_122"
  ],
  "sensor_power_load_no_var_loads": "sensor.victron_ac_l1",
  "sensor_power_photovoltaics": "sensor.power_ac_fronius_inverter_1_192_168_10_122",
  "sensor_replace_zero": [
    "sensor.power_ac_fronius_inverter_1_192_168_10_122",
    "sensor.victron_ac_l1"
  ],
  "set_battery_dynamic": false,
  "set_deferrable_load_single_constant": [
    false,
    false
  ],
  "set_deferrable_startup_penalty": [
    0,
    0
  ],
  "set_nocharge_from_grid": false,
  "set_nodischarge_to_grid": false,
  "set_total_pv_sell": false,
  "set_use_battery": true,
  "set_zero_min": false,
  "start_timesteps_of_each_deferrable_load": [
    0,
    0
  ],
  "strings_per_inverter": [
    2
  ],
  "surface_azimuth": [
    10
  ],
  "surface_tilt": [
    15
  ],
  "treat_deferrable_load_as_semi_cont": [
    true,
    true
  ],
  "weather_forecast_method": "scrapper",
  "weight_battery_charge": 0,
  "weight_battery_discharge": 0
}

@GeoDerp
Copy link
Contributor Author

GeoDerp commented Nov 1, 2024

@purcell-lab

ive compared our config: Mine is below for reference.

I note the following differences (that just arent general settings) "battery_maximum_state_of_charge": 1,

* I had an issue with setting 1, and had to set to 0.99

"battery_minimum_state_of_charge": 0,

* I had an issue with setting 0, and had to set 0.01

"set_battery_dynamic": true,"

* i could never get this to work. Did you want to try disabling for troubleshooting?

"weight_battery_charge": 1," "weight_battery_discharge": 0.05"

* both of these values after the last release i was getting very obscure behaviour.  I set them both to "0" and it resolved it.

Ohh, and your SOC_final in your CURL is also 1. Did you want to troubleshoot with a 0.99?

Otherwise your config looks within reason the same as mine, +/- inverter/grid/solar settings.


{
  "battery_charge_efficiency": 0.99,
  "battery_charge_power_max": 8000,
  "battery_discharge_efficiency": 0.99,
  "battery_discharge_power_max": 8000,
  "battery_dynamic_max": 0.9,
  "battery_dynamic_min": -0.9,
  "battery_maximum_state_of_charge": 0.99,
  "battery_minimum_state_of_charge": 0.01,
  "battery_nominal_energy_capacity": 75000,
  "battery_target_state_of_charge": 0.98,
  "compute_curtailment": false,
  "continual_publish": false,
  "costfun": "profit",
  "delta_forecast_daily": 2,
  "end_timesteps_of_each_deferrable_load": [
    0,
    0
  ],
  "historic_days_to_retrieve": 3,
  "inverter_is_hybrid": true,
  "load_cost_forecast_method": "hp_hc_periods",
  "load_forecast_method": "naive",
  "load_negative": false,
  "load_offpeak_hours_cost": 0.08,
  "load_peak_hour_periods": {
    "period_hp_1": [
      {
        "start": "06:00"
      },
      {
        "end": "11:00"
      }
    ],
    "period_hp_2": [
      {
        "start": "14:00"
      },
      {
        "end": "23:59"
      }
    ]
  },
  "load_peak_hours_cost": 0.48,
  "logging_level": "INFO",
  "lp_solver": "COIN_CMD",
  "lp_solver_path": "/usr/bin/cbc",
  "maximum_power_from_grid": 15000,
  "maximum_power_to_grid": 5000,
  "method_ts_round": "nearest",
  "modules_per_string": [
    11
  ],
  "nominal_power_of_deferrable_loads": [
    0,
    0
  ],
  "number_of_deferrable_loads": 2,
  "operating_hours_of_each_deferrable_load": [
    0,
    0
  ],
  "optimization_time_step": 30,
  "photovoltaic_production_sell_price": 0.03,
  "production_price_forecast_method": "constant",
  "pv_inverter_model": [
    "Fronius_International_GmbH__Fronius_Primo_5_0_1_208_240__240V_"
  ],
  "pv_module_model": [
    "CSUN_Eurasia_Energy_Systems_Industry_and_Trade_CSUN295_60M"
  ],
  "sensor_linear_interp": [
    "sensor.power_ac_fronius_inverter_1_192_168_10_122"
  ],
  "sensor_power_load_no_var_loads": "sensor.victron_ac_l1",
  "sensor_power_photovoltaics": "sensor.power_ac_fronius_inverter_1_192_168_10_122",
  "sensor_replace_zero": [
    "sensor.power_ac_fronius_inverter_1_192_168_10_122",
    "sensor.victron_ac_l1"
  ],
  "set_battery_dynamic": false,
  "set_deferrable_load_single_constant": [
    false,
    false
  ],
  "set_deferrable_startup_penalty": [
    0,
    0
  ],
  "set_nocharge_from_grid": false,
  "set_nodischarge_to_grid": false,
  "set_total_pv_sell": false,
  "set_use_battery": true,
  "set_zero_min": false,
  "start_timesteps_of_each_deferrable_load": [
    0,
    0
  ],
  "strings_per_inverter": [
    2
  ],
  "surface_azimuth": [
    10
  ],
  "surface_tilt": [
    15
  ],
  "treat_deferrable_load_as_semi_cont": [
    true,
    true
  ],
  "weather_forecast_method": "scrapper",
  "weight_battery_charge": 0,
  "weight_battery_discharge": 0
}

Thanks @kcoffau this is great. Seems like there are some bugs when it comes to the battery optimization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants