springfall2008 / batpred

Home battery prediction and charging automation for Home Assistant, supporting many inverter types
https://springfall2008.github.io/batpred/
107 stars 37 forks source link

Nordpool #688

Closed JohanAlvedal closed 6 months ago

JohanAlvedal commented 6 months ago

Hello This seems like an interesting project. However, I have nordpool (tibber Sweden) as an integration in HA which delivers my electricity prices. Also has a Huawei inverter that communicates using modbus from HA. The question I have is if you can somehow get it in instead of octopus?

It would be nice to have these to work with Nordpool metric_octopus_import: 're:(sensor.(octopusenergy|)electricity[0-9a-z]+[0-9a-z]+_current_rate)' metric_octopus_export: 're:(sensor.(octopusenergy|)electricity[0-9a-z]+[0-9a-z]+_export_current_rate)'

I've already started getting some data into predbat, so it's looking promising.

sensor.nordpool_kwh_se3_sek_3_10_025 shows the current price and have all data current tomorrow and so on as attribute.


`Average  0,32
Off peak 1  0,25
Off peak 2  0,07
Peak  0,46
Min -0
Max  0,85
Mean  0,28
Unit  kWh
Currency  SEK
Country  Sweden
Region  SE3
Low price false
Price percent to average  1,01
Today  0,11, 0,13, 0,13, 0,15, 0,17, 0,18, 0,29, 0,82, 0,85, 0,82, 0,8, 0,61, 0,35, 0,33, 0,32, 0,33, 0,3, 0,29, 0,27, 0,21, 0,16, 0,11, 0,01, −0
Tomorrow  −0,01, −0,02, −0,03, −0,03, −0,03, −0,03, −0,01, −0, 0, 0,03, 0,03, 0, 0, −0, −0, 0,01, 0,05, 0,15, 0,15, 0,05, 0, 0,02, 0, −0
Tomorrow valid  true
Raw today
- start: '2024-02-02T00:00:00+01:00'
end: '2024-02-02T01:00:00+01:00'
value: 0.111
- start: '2024-02-02T01:00:00+01:00'
end: '2024-02-02T02:00:00+01:00'
value: 0.127
- start: '2024-02-02T02:00:00+01:00'
end: '2024-02-02T03:00:00+01:00'
value: 0.129
- start: '2024-02-02T03:00:00+01:00'
end: '2024-02-02T04:00:00+01:00'
value: 0.147
- start: '2024-02-02T04:00:00+01:00'
end: '2024-02-02T05:00:00+01:00'
value: 0.166
- start: '2024-02-02T05:00:00+01:00'
end: '2024-02-02T06:00:00+01:00'
value: 0.184
- start: '2024-02-02T06:00:00+01:00'
end: '2024-02-02T07:00:00+01:00'
value: 0.287
- start: '2024-02-02T07:00:00+01:00'
end: '2024-02-02T08:00:00+01:00'
value: 0.818
- start: '2024-02-02T08:00:00+01:00'
end: '2024-02-02T09:00:00+01:00'
value: 0.847
- start: '2024-02-02T09:00:00+01:00'
end: '2024-02-02T10:00:00+01:00'
value: 0.822
- start: '2024-02-02T10:00:00+01:00'
end: '2024-02-02T11:00:00+01:00'
value: 0.803
- start: '2024-02-02T11:00:00+01:00'
end: '2024-02-02T12:00:00+01:00'
value: 0.607
- start: '2024-02-02T12:00:00+01:00'
end: '2024-02-02T13:00:00+01:00'
value: 0.347
- start: '2024-02-02T13:00:00+01:00'
end: '2024-02-02T14:00:00+01:00'
value: 0.33
- start: '2024-02-02T14:00:00+01:00'
end: '2024-02-02T15:00:00+01:00'
value: 0.324
- start: '2024-02-02T15:00:00+01:00'
end: '2024-02-02T16:00:00+01:00'
value: 0.325
- start: '2024-02-02T16:00:00+01:00'
end: '2024-02-02T17:00:00+01:00'
value: 0.297
- start: '2024-02-02T17:00:00+01:00'
end: '2024-02-02T18:00:00+01:00'
value: 0.294
- start: '2024-02-02T18:00:00+01:00'
end: '2024-02-02T19:00:00+01:00'
value: 0.266
- start: '2024-02-02T19:00:00+01:00'
end: '2024-02-02T20:00:00+01:00'
value: 0.206
- start: '2024-02-02T20:00:00+01:00'
end: '2024-02-02T21:00:00+01:00'
value: 0.157
- start: '2024-02-02T21:00:00+01:00'
end: '2024-02-02T22:00:00+01:00'
value: 0.105
- start: '2024-02-02T22:00:00+01:00'
end: '2024-02-02T23:00:00+01:00'
value: 0.011
- start: '2024-02-02T23:00:00+01:00'
end: '2024-02-03T00:00:00+01:00'
value: -0.0
Raw tomorrow
- start: '2024-02-03T00:00:00+01:00'
end: '2024-02-03T01:00:00+01:00'
value: -0.014
- start: '2024-02-03T01:00:00+01:00'
end: '2024-02-03T02:00:00+01:00'
value: -0.021
- start: '2024-02-03T02:00:00+01:00'
end: '2024-02-03T03:00:00+01:00'
value: -0.025
- start: '2024-02-03T03:00:00+01:00'
end: '2024-02-03T04:00:00+01:00'
value: -0.029
- start: '2024-02-03T04:00:00+01:00'
end: '2024-02-03T05:00:00+01:00'
value: -0.029
- start: '2024-02-03T05:00:00+01:00'
end: '2024-02-03T06:00:00+01:00'
value: -0.026
- start: '2024-02-03T06:00:00+01:00'
end: '2024-02-03T07:00:00+01:00'
value: -0.006
- start: '2024-02-03T07:00:00+01:00'
end: '2024-02-03T08:00:00+01:00'
value: -0.001
- start: '2024-02-03T08:00:00+01:00'
end: '2024-02-03T09:00:00+01:00'
value: 0
- start: '2024-02-03T09:00:00+01:00'
end: '2024-02-03T10:00:00+01:00'
value: 0.03
- start: '2024-02-03T10:00:00+01:00'
end: '2024-02-03T11:00:00+01:00'
value: 0.03
- start: '2024-02-03T11:00:00+01:00'
end: '2024-02-03T12:00:00+01:00'
value: 0
- start: '2024-02-03T12:00:00+01:00'
end: '2024-02-03T13:00:00+01:00'
value: 0
- start: '2024-02-03T13:00:00+01:00'
end: '2024-02-03T14:00:00+01:00'
value: -0.0
- start: '2024-02-03T14:00:00+01:00'
end: '2024-02-03T15:00:00+01:00'
value: -0.0
- start: '2024-02-03T15:00:00+01:00'
end: '2024-02-03T16:00:00+01:00'
value: 0.007
- start: '2024-02-03T16:00:00+01:00'
end: '2024-02-03T17:00:00+01:00'
value: 0.048
- start: '2024-02-03T17:00:00+01:00'
end: '2024-02-03T18:00:00+01:00'
value: 0.145
- start: '2024-02-03T18:00:00+01:00'
end: '2024-02-03T19:00:00+01:00'
value: 0.146
- start: '2024-02-03T19:00:00+01:00'
end: '2024-02-03T20:00:00+01:00'
value: 0.049
- start: '2024-02-03T20:00:00+01:00'
end: '2024-02-03T21:00:00+01:00'
value: 0.001
- start: '2024-02-03T21:00:00+01:00'
end: '2024-02-03T22:00:00+01:00'
value: 0.02
- start: '2024-02-03T22:00:00+01:00'
end: '2024-02-03T23:00:00+01:00'
value: 0
- start: '2024-02-03T23:00:00+01:00'
end: '2024-02-04T00:00:00+01:00'
value: -0.0
Current price 0,32
Additional costs current hour 0
Price in cents false

`

springfall2008 commented 6 months ago

I think it would be easy to integrate this, it's almost the same as the Octopus.

Can you show a snapshot of the above from within HA in the Developer tools, States menu and I'll get it supported?

JohanAlvedal commented 6 months ago

IMG_0316 IMG_0317 IMG_0318

springfall2008 commented 6 months ago

And you want to use the values from 'today' as your import rates?

JohanAlvedal commented 6 months ago

Yes exactly and tomorrow if possible. Export sensor is an equivalent but without VAT.

One question, if I don't want to use the function to charge an electric car, can I then uncomment all that apply to the car?

Skärmavbild 2024-02-02 kl  20 31 29
gcoan commented 6 months ago

Yes exactly and tomorrow if possible.

Export sensor is an equivalent but without VAT.

One question, if I don't want to use the function to charge an electric car, can I then uncomment all that apply to the car?

Skärmavbild 2024-02-02 kl  20 31 29

Just set num_cars to 0 in apps.yaml and predbat won't do anything with car charging

springfall2008 commented 6 months ago

I've submitted a change to MAIN which should now read this format of data, just point your metric_octopus_import/metric_octopus_export to the sensors and let me know if it works.

JohanAlvedal commented 6 months ago

I'm not sure how? like this? metric_octopus_import: 're:(sensor.(sensor.nordpool_kwh_se3_sek_3_10_025)' metric_octopus_export: 're:(sensor.nordpool_moms)' or metric_octopus_import:

When I tried both options I get the same thing in the log in HA `s6-rc: info: service s6rc-oneshot-runner: starting s6-rc: info: service s6rc-oneshot-runner successfully started s6-rc: info: service base-addon-banner: starting


Add-on: appdaemon-predbat Predbat pre-install in AppDaemon

Add-on version: 1.0.5 You are running the latest version of this add-on. System: Home Assistant OS 11.4 (amd64 / generic-x86-64) Home Assistant Core: 2024.1.6 Home Assistant Supervisor: 2023.12.1

Please, share the above information when looking for help or support in, e.g., GitHub, forums or the Discord chat.

s6-rc: info: service base-addon-banner successfully started s6-rc: info: service fix-attrs: starting s6-rc: info: service base-addon-log-level: starting s6-rc: info: service fix-attrs successfully started s6-rc: info: service base-addon-log-level successfully started s6-rc: info: service legacy-cont-init: starting s6-rc: info: service legacy-cont-init successfully started s6-rc: info: service init-appdaemon: starting s6-rc: info: service init-appdaemon successfully started s6-rc: info: service appdaemon: starting s6-rc: info: service appdaemon successfully started s6-rc: info: service legacy-services: starting [15:32:52] INFO: Starting AppDaemon... s6-rc: info: service legacy-services successfully started 2024-02-03 15:32:56.740402 WARNING pred_bat: ------------------------------------------------------------ 2024-02-03 15:32:56.740634 WARNING pred_bat: Unexpected error running initialize() for pred_bat 2024-02-03 15:32:56.740762 WARNING pred_bat: ------------------------------------------------------------ 2024-02-03 15:32:56.743692 WARNING pred_bat: Traceback (most recent call last): File "/usr/lib/python3.11/site-packages/appdaemon/app_management.py", line 162, in initialize_app await utils.run_in_executor(self, init) File "/usr/lib/python3.11/site-packages/appdaemon/utils.py", line 304, in run_in_executor response = future.result() ^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/apps/predbat.py", line 11628, in initialize raise e File "/config/apps/predbat.py", line 11623, in initialize self.auto_config() File "/config/apps/predbat.py", line 11487, in auto_config matched, arg_value = self.resolve_arg_re(arg, arg_value, state_keys) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/apps/predbat.py", line 11452, in resolve_arg_re res = re.search(my_re, key) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/re/init.py", line 176, in search return _compile(pattern, flags).search(string) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/re/init.py", line 294, in _compile p = _compiler.compile(pattern, flags) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/re/_compiler.py", line 743, in compile p = _parser.parse(p, flags) ^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/re/_parser.py", line 982, in parse p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/re/_parser.py", line 457, in _parse_sub itemsappend(_parse(source, state, verbose, nested + 1, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/re/_parser.py", line 867, in _parse raise source.error("missing ), unterminated subpattern", re.error: missing ), unterminated subpattern at position 1

2024-02-03 15:32:56.743963 WARNING pred_bat: ------------------------------------------------------------`

springfall2008 commented 6 months ago

Like this I think

metric_octopus_import:sensor.nordpool_kwh_se3_sek_3_10_025 metric_octopus_export: sensor.nordpool_moms

JohanAlvedal commented 6 months ago

2024-02-03 17:59:25.788217 WARNING pred_bat: pred_bat: Entity select.predbat_manual_charge not found in namespace default 2024-02-03 17:59:25.788836 INFO AppDaemon: pred_bat: Entity select.predbat_manual_charge created in namespace: default 2024-02-03 17:59:25.864744 INFO pred_bat: Updating HA config manual_discharge to 2024-02-03 17:59:25.865544 WARNING pred_bat: pred_bat: Entity select.predbat_manual_discharge not found in namespace default 2024-02-03 17:59:25.866106 INFO AppDaemon: pred_bat: Entity select.predbat_manual_discharge created in namespace: default 2024-02-03 17:59:25.928276 INFO pred_bat: Updating HA config manual_idle to 2024-02-03 17:59:25.928830 WARNING pred_bat: pred_bat: Entity select.predbat_manual_idle not found in namespace default 2024-02-03 17:59:25.929223 INFO AppDaemon: pred_bat: Entity select.predbat_manual_idle created in namespace: default 2024-02-03 17:59:25.987995 INFO pred_bat: Updating HA config saverestore to 2024-02-03 17:59:25.988575 WARNING pred_bat: pred_bat: Entity select.predbat_saverestore not found in namespace default 2024-02-03 17:59:25.988899 INFO AppDaemon: pred_bat: Entity select.predbat_saverestore created in namespace: default 2024-02-03 17:59:25.995715 INFO pred_bat: Updating HA config auto_update to False 2024-02-03 17:59:26.009995 INFO pred_bat: Note: Disabled configuration item load_filter_modal 2024-02-03 17:59:26.011326 INFO pred_bat: Updating HA config iboost_enable to False 2024-02-03 17:59:26.018021 INFO pred_bat: Updating HA config iboost_solar to True 2024-02-03 17:59:26.024814 INFO pred_bat: Updating HA config iboost_gas to False 2024-02-03 17:59:26.031629 INFO pred_bat: Updating HA config iboost_charging to False 2024-02-03 17:59:26.037880 INFO pred_bat: Note: Disabled configuration item iboost_gas_scale 2024-02-03 17:59:26.038782 INFO pred_bat: Note: Disabled configuration item iboost_max_energy 2024-02-03 17:59:26.039624 INFO pred_bat: Note: Disabled configuration item iboost_today 2024-02-03 17:59:26.040451 INFO pred_bat: Note: Disabled configuration item iboost_max_power 2024-02-03 17:59:26.042957 INFO pred_bat: Note: Disabled configuration item iboost_min_power 2024-02-03 17:59:26.043823 INFO pred_bat: Note: Disabled configuration item iboost_min_soc 2024-02-03 17:59:26.044944 INFO pred_bat: Updating HA config holiday_days_left to 0.0 2024-02-03 17:59:26.051742 INFO pred_bat: Note: Disabled configuration item forecast_plan_hours 2024-02-03 17:59:26.052718 INFO pred_bat: Note: Disabled configuration item plan_debug 2024-02-03 17:59:26.133846 INFO pred_bat: Inverter Type: GE (GivEnergy) 2024-02-03 17:59:26.134608 INFO pred_bat: Predbat: Next run time will be 2024-02-03 18:00:00 and then every 300 seconds 2024-02-03 17:59:26.136736 INFO pred_bat: Balance inverters will run every 60 seconds (if enabled) 2024-02-03 17:59:41.203043 INFO pred_bat: --------------- PredBat - update at 2024-02-03 17:59:41.201527+01:00 with clock skew 0 minutes, minutes now 1075 2024-02-03 17:59:41.604920 INFO pred_bat: Predbat /config/apps/predbat.py version v7.15.11 currently running, latest version is v7.15.11 latest beta v7.15.11 2024-02-03 17:59:41.605848 INFO pred_bat: Autoupdate: Currently up to date 2024-02-03 17:59:41.627398 INFO pred_bat: Inverter type GE forecast_hours 48 max_windows 96 num_cars 0 debug enable is False calculate_plan_every 10 2024-02-03 17:59:41.630058 INFO pred_bat: Predbat mode is set to Monitor 2024-02-03 17:59:41.803304 INFO pred_bat: Found 11520 load_today datapoints going back 1 days 2024-02-03 17:59:43.155148 INFO pred_bat: Car charging hold True threshold 6.0 2024-02-03 17:59:43.156033 INFO pred_bat: Current data so far today: load 22.11 kWh import 22.11 kWh export 0.0 kWh pv 23.27 kWh 2024-02-03 17:59:43.156912 INFO pred_bat: Fetching futurerate data from None 2024-02-03 17:59:43.158578 INFO pred_bat: WARN: No Octopus data in sensor sensor.nordpool_kwh_se3_sek_3_10_025 attribute 'all_rates' 2024-02-03 17:59:43.159451 INFO pred_bat: Error: metric_octopus_import is not set correctly or no energy rates can be read 2024-02-03 17:59:43.167235 INFO pred_bat: ERROR: Exception raised 2024-02-03 18:00:00.005661 INFO pred_bat: --------------- PredBat - update at 2024-02-03 18:00:00.004771+01:00 with clock skew 0 minutes, minutes now 1080 2024-02-03 18:00:00.006632 INFO pred_bat: Using cached GITHub data for https://api.github.com/repos/springfall2008/batpred/releases age 0.3 minutes 2024-02-03 18:00:00.007586 INFO pred_bat: Predbat /config/apps/predbat.py version v7.15.11 currently running, latest version is v7.15.11 latest beta v7.15.11 2024-02-03 18:00:00.008594 INFO pred_bat: Autoupdate: Currently up to date 2024-02-03 18:00:00.024898 INFO pred_bat: Inverter type GE forecast_hours 48 max_windows 96 num_cars 0 debug enable is False calculate_plan_every 10 2024-02-03 18:00:00.026948 INFO pred_bat: Predbat mode is set to Monitor 2024-02-03 18:00:00.204989 INFO pred_bat: Found 11520 load_today datapoints going back 1 days 2024-02-03 18:00:01.702497 INFO pred_bat: Car charging hold True threshold 6.0 2024-02-03 18:00:01.703405 INFO pred_bat: Current data so far today: load 22.3 kWh import 22.35 kWh export 0.0 kWh pv 23.34 kWh 2024-02-03 18:00:01.704290 INFO pred_bat: Fetching futurerate data from None 2024-02-03 18:00:01.705970 INFO pred_bat: WARN: No Octopus data in sensor sensor.nordpool_kwh_se3_sek_3_10_025 attribute 'all_rates' 2024-02-03 18:00:01.706860 INFO pred_bat: Error: metric_octopus_import is not set correctly or no energy rates can be read 2024-02-03 18:00:01.713997 INFO pred_bat: ERROR: Exception raised

springfall2008 commented 6 months ago

It doesn't look like you updated to the version on 'main'?

JohanAlvedal commented 6 months ago

ok but how do i do that?

springfall2008 commented 6 months ago

Select the version from the select.predbat_update drop down menu.

This code actually ended up released now also

JohanAlvedal commented 6 months ago

it works but the price is not 100% correct, for example now at 21:00 the price is 0.02 Sek, but it shows 2.00, but perhaps it should be so?

IMG_0319

springfall2008 commented 6 months ago

What should the price be according to the data, is it out by a certain factor?

JohanAlvedal commented 6 months ago

the price from Nordpool is correct but it is shown in kronor equivalent to pound not pence. 0.02 SEK (1 GBP = 13.36 SEK 133.6 öre (pence). But maybe it should be? it is pence in import and export but in GBP in the far right column.

springfall2008 commented 6 months ago

Yes it’s pence on the left and pounds on the right for the total

gcoan commented 6 months ago

the price from Nordpool is correct but it is shown in kronor equivalent to pound not pence. 0.02 SEK (1 GBP = 13.36 SEK 133.6 öre (pence). But maybe it should be? it is pence in import and export but in GBP in the far right column.

Predbat assumes all the prices from the energy sensors are in pence and produces the plan in pence. Just the total column on the right of the plan is pence x 100 ie GBP

Ignoring that the units are wrong for you, is the order of magnitude of everything correct?

I don't think we want predbat to start doing currency conversion but it may be possible to have a "display currency" setting or some Jinja post processing of the html plan to change the currency text strings

JohanAlvedal commented 6 months ago

Well, that's right, I'm satisfied, very satisfied, thanks for the help so far. Now it will be allowed to run for a few days, then I will work with the settings a bit