davidusb-geek / emhass

emhass: Energy Management for Home Assistant, is a Python module designed to optimize your home energy interfacing with Home Assistant.
MIT License
258 stars 51 forks source link

load_cast_forecast nordpool fails, #309

Open renaatdb opened 2 weeks ago

renaatdb commented 2 weeks ago

Hello, I am running emhass and nordpool. generic-x86-64 core-2024.6.0 Home Assistant OS 12.3 EMHASS Current version: 0.10.1 Nordpool 0.0.14

What I have to fill in when I use nordpool? I want to use dynamic prices

image

I used the actually a working example for using Nordpool: https://emhass.readthedocs.io/en/latest/forecasts.html#example-using-the-nordpool-integration

shell_command:
  dayahead_optim: "curl -i -H \"Content-Type:application/json\" -X POST -d '{\"pv_power_forecast\":{{states('sensor.solcast_24hrs_forecast')}}}' http://localhost:5001/action/dayahead-optim"

  publish_data: "curl -i -H \"Content-Type:application/json\" -X POST -d '{}' http://localhost:5000/action/publish-data"  

  trigger_nordpool_forecast: "curl -i -H \"Content-Type: application/json\" -X POST -d '{\"load_cost_forecast\":{{((state_attr('sensor.nordpool_kwh_be_eur_3_10_021', 'raw_today') | map(attribute='value') | list  + state_attr('sensor.nordpool_kwh_be_eur_3_10_021', 'raw_tomorrow') | map(attribute='value') | list))[now().hour:][:24] }},\"prod_price_forecast\":{{((state_attr('sensor.nordpool_kwh_be_eur_3_10_021', 'raw_today') | map(attribute='value') | list  + state_attr('sensor.nordpool_kwh_be_eur_3_10_021', 'raw_tomorrow') | map(attribute='value') | list))[now().hour:][:24]}}}' http://localhost:5000/action/dayahead-optim"

P PV is ok Load_cost NOT ok image

Logs

2024-06-10 21:00:00,391 - web_server - INFO -  >> Publishing data...
2024-06-10 21:00:00,391 - web_server - INFO - Publishing data to HASS instance
2024-06-10 21:00:00,403 - web_server - INFO - Successfully posted to sensor.p_pv_forecast = 209.25
2024-06-10 21:00:00,409 - web_server - INFO - Successfully posted to sensor.p_load_forecast = 0.87
2024-06-10 21:00:00,419 - web_server - INFO - Successfully posted to sensor.p_pv_curtailment = 0.0
2024-06-10 21:00:00,428 - web_server - INFO - Successfully posted to sensor.p_deferrable0 = 0.0
2024-06-10 21:00:00,438 - web_server - INFO - Successfully posted to sensor.p_grid_forecast = -208.38
2024-06-10 21:00:00,447 - web_server - INFO - Successfully posted to sensor.total_cost_fun_value = 2.0
2024-06-10 21:00:00,455 - web_server - INFO - Successfully posted to sensor.optim_status = Infeasible
2024-06-10 21:00:00,464 - web_server - INFO - Successfully posted to sensor.unit_load_cost = 0.1419
2024-06-10 21:00:00,472 - web_server - INFO - Successfully posted to sensor.unit_prod_price = 0.065
2024-06-10 21:04:15,890 - web_server - INFO - EMHASS server online, serving index.html...
2024-06-10 21:04:24,044 - web_server - INFO - Passed runtime parameters: {}
2024-06-10 21:04:24,044 - web_server - INFO -  >> Setting input data dict
2024-06-10 21:04:24,044 - web_server - INFO - Setting up needed data
2024-06-10 21:04:24,045 - web_server - INFO - Retrieving weather forecast data using method = scrapper
2024-06-10 21:04:27,548 - web_server - INFO - Retrieving data from hass for load forecast using method = naive
2024-06-10 21:04:27,548 - web_server - INFO - Retrieve hass get data method initiated...
2024-06-10 21:04:28,935 - web_server - INFO -  >> Performing dayahead optimization...
2024-06-10 21:04:28,935 - web_server - INFO - Performing day-ahead forecast optimization
2024-06-10 21:04:28,937 - web_server - INFO - Perform optimization for the day-ahead
2024-06-10 21:04:30,144 - web_server - WARNING - Solver default unknown, using default
Welcome to the CBC MILP Solver 
Version: 2.10.3 
Build Date: Dec 15 2019 

`
command line - /usr/local/lib/python3.11/dist-packages/pulp/solverdir/cbc/linux/64/cbc /tmp/a406c2faf3af486291a0164c75fb59de-pulp.mps -max -timeMode elapsed -branch -printingOptions all -solution /tmp/a406c2faf3af486291a0164c75fb59de-pulp.sol (default strategy 1)
At line 2 NAME          MODEL
At line 3 ROWS
At line 486 COLUMNS
At line 2069 RHS
At line 2551 BOUNDS
At line 2936 ENDATA
Problem MODEL has 481 rows, 384 columns and 1102 elements
Coin0008I MODEL read with 0 errors
Option for timeMode changed from cpu to elapsed
Problem is infeasible - 0.00 seconds
Option for printingOptions changed from normal to all
Total time (CPU seconds):       0.00   (Wallclock seconds):       0.00

2024-06-10 21:04:30,159 - web_server - INFO - Status: Infeasible
2024-06-10 21:04:30,159 - web_server - INFO - Total value of the Cost function = 1.98
2024-06-10 21:04:30,335 - web_server - INFO -  >> Sending rendered template table data
`

Is there something I do not see?

Thanks ``

JohanAlvedal commented 2 weeks ago

Got it working here. https://github.com/JohanAlvedal/homeautomation/tree/main/Emhass/Shell

renaatdb commented 2 weeks ago

https://github.com/JohanAlvedal/homeautomation/tree/main/Emhass/Shell

Thanks, I'm going to study it

renaatdb commented 2 weeks ago

@JohanAlvedal Looks too complicated for me. tried to change this

shell_command:
  dayahead_optim: "curl -i -H \"Content-Type:application/json\" -X POST -d '{\"pv_power_forecast\":{{states('sensor.solcast_24hrs_forecast')}}}' http://localhost:5001/action/dayahead-optim"

into

dayahead_optim_v2: '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:][:48] | list | length)) }},
  "pv_power_forecast":{{ ([states("sensor.solcast_pv_forecast_power_now") | 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 }},
  "delta_forecast":2
  }'' http://localhost:5000/action/dayahead-optim'

i'm trying to find simple configurations

purcell-lab commented 2 weeks ago

There is no doubt adding in these additional forecasts with some json foo can get quite complex quickly.

It would be useful if we could provide a blueprint/ template for some of the standard suppliers; nordpool, Amber, octopus. So the end user could just tick a check box, rather than having all this yaml fun.

The other consideration is each time you modify the shell_command or rest_command you need to restart HA, it would also reduce complexity if you could just reload a template/ script each time you needed to modify the payload.

JohanAlvedal commented 2 weeks ago

Absolutely, I agree with you. Someone talented who could create a blueprint so you can enter your electricity supplier solcast and the most relevant parts, I think it would help many users of emhass. It was/is the part that many users struggle with to get emhass up and running, because it is precisely that part that is extremely complex. When and how should all scripts be run and how should they be configured.

renaatdb commented 2 weeks ago

Thanks, I thought I was the only one having trouble with this. It's amazing how Emhass was made. However, it is difficult for a beginner to get started and difficult to understand the manual. Hopefully I'll manage to get everything working in the future. I want to purchase a battery in the future and see what a dynamic rate (with Nordpool) can teach me. I am now trying to predict what the use of a battery can bring me. I assume Emhass can help me with this. Thanks

renaatdb commented 1 week ago

Hello, This is also an interesting tool from Thermia . https://classiconlinestorage.blob.core.windows.net/web-resources/SmartPrice_Info_and_FAQ_NL.pdf