Dynamic max percentage battery off-peak charge based on forecast Wx

31 comments started 2023-02-09 last 2023-05-30
Beta PortalCloud PortalGivEnergy ProductsBatteryCards - Inverter
J
#1 JoshuaP

Hi all

Is there a way of having the inverter charge the battery off-peak (timed charge in the inverter settings) but having the system also adjust the max battery percentage for the grid charge based on the forecast solar generation for the next day?

For example, if tomorrow is forecast to be a very sunny day, I manually change the timed off-peak charge settings to charge the battery to a maximum of c.60% capacity. This means that as ECO mode is also enabled, the battery is topped up to c.100% charge with free energy the next day. Conversely, if it was forecast to be a cloudy day, the max charge percentage would be set to c.90% the day before.

Is there a way of getting the system to estimate this and update the inverter settings so that I don't need to manually change it every day?

Thanks

T
#2 TX200

Yes, if you're willing to get your hands dirty with a bit of automation code.

Search the forum for similar topics and you'll find all sorts of options including standalone python scripts and HomeAssistant GivTCP add ons.

I
#3 IanMac

This feature has been on the "coming soon" list since I had my system installed in September. I've just put in a feature request for something simpler: The ability to set battery charge limit by day of the week. I would be fine if I could just set mine to 60% weekdays and 90% at weekends, as this would suit my needs the majority of the time.

S
#4 stevelewis

JoshuaP www.github.com/salewis38/palm

M
#5 MycroftVonLipwig

Sorry, just to confirm something that has confused me for a while, and as such never touched it...

Does the charge percentage on the inverter only affect the percentage charged from grid and NOT affect the percent charged from solar? If so great. I Never take mine out of eco mode so assume eco mode.

I have Octopus Agile and HomeAssistant. Though some recent updates to the HACS Integration "Octopus Agile" I can now dynamically set the required number of 30 min slots (the very cheapest) based on the SOC of the battery via an automation to a Target Sensor.
I then have a second automation to reduce the Target % (currently just a sensor in HA not the GE Inverter exposed one by GivTCP) down depending on the predicted KWH of Solar forecast for tomorrow. If above 20KWH, 0%, If Below 10KWH 100%, If between 10 and 15KWH, 50%.... and so on.

This has worked perfectly of the last week or so since I have set it up and the sun has been pretty good to me.

Very happy with this method. Not the most elegant but works perfectly for my setup (6KW Panels, 9.5Kwh Batt).

T
#6 Tim

MycroftVonLipwig charge percentage on the inverter

If you mean the Charge to % in the Timed Charge tab, then yes. This is the SoC that the inverter will charge to during a Timed Charge. The rest of the time, in ECO mode, the inverter will divert all surplus PV to charge the battery until it is at 100% SoC when it will start exporting up to your G99 limit.

M
#7 MattWhitfield

MycroftVonLipwig Just as an additional bit of info. Charge % is effectively the maximum battery level to which the battery is charged. If you set it at 70%, then the battery can also discharge down to 70% during that time if you're in eco mode.

M
#8 MycroftVonLipwig

MattWhitfield Ah, good call. In which case I will stay with my dummy min/max sensor for controlling max charge percent. Thank you both @Tim and MattWhitfield !

T
#9 Tim

MattWhitfield If you set it at 70%, then the battery can also discharge down to 70% during that time if you're in eco mode.

The Charge to % only comes into play during a Timed Charge period when the inverter will either charge up to that value, or allow house load to be met from the battery until it discharges down to that value, as you say. Outside of a timed charge period, (assuming ECO mode is enabled and no timed discharge or export), the Charge to % is ignored completely and the inverter supplies house load from PV supplemented by any battery capacity down to the 4% limit and diverts any surplus PV to battery or export if the battery is fully charged.

M
#10 MattWhitfield

Tim Yep, spot on. Didn't call out explicitly that I was only talking about the behaviour in the timed charge period - thanks for the catch.

G
#11 grahamhobson

JoshuaP hi Josh, my requirement is exactly the same as yours. I want to charge to max 50% or 60% overnight if tomorrow is mostly sunny and 90% ish if mostly cloudy. I have some very rusty coding skills from a previous life as a software developer but want someone to lead me through the steps on a nice detailed blog post.

Did you find a solution to that here?

T
#12 Tim

grahamhobson Leave the inverter in ECO mode all the time but add a timed charge for your off-peak window and set the Charge to % (60% or 90% depending on the weather) there. That's all you have to do. Leave it set up as this all year round but adjust the Charge to % as the seasons/weather dictates.

If you've had a good PV day and are expecting another good PV tomorrow, with your battery Charge to % set at say 50%, the battery will supply the house load overnight until it drops to 50%. If that happens before the end of the timed charge period, the inverter will hold the battery at 50% (house load supplied from grid) until the end of the period, when it will continue to discharge until PV is available. If the battery is below the Charge to % at the start of the timed charge period, the inverter will charge the battery to the Charge to % and hold it there, and grid will supply the house until the end of the timed charge period.

S
#13 stevelewis

grahamhobson already implemented... www.github.com/salewis38/palm

G
#14 grahamhobson

Tim Thanks Tim, yes, this is what I am already doing. The goal is to have that grid recharge max percentage set automatically by a scheduled software task based on the solcast forecast. That way it would be automatic and wouldn’t require me to make a manual configuration change every day..

Of course, the ultimate solution would be for the Givenergy system to support this functionality natively, but I’m guessing we may have to wait a while.

I note the @stevelewis link to the palm project on GitHub. This looks interesting, albeit probably more comprehensive in what it is trying to do than I need. If I go this route I will need to dust off some neurons that haven’t been used in 25 years and figure out how to apply this Python project to a macbook rather than a Raspberry Pi.

T
#15 TheRadkes2020

MycroftVonLipwig is this something you could share to a not too technical person. I have HA as well but I'm not great at it and would appreciate any help.

S
#16 stevelewis

grahamhobson There's nothing in the Python code that ties it to a Raspberry Pi... I've run it under Windows and Android and one person has it running on a NAS device.

G
#17 grahamhobson

stevelewis Thanks so much Steve - this is amazing and solves a problem I've been wanting to address since having the battery installed. I have it working now on my MacBook, launched from the command line in terminal. It's working really well. My next task will be to get it running as a launchd service and I will rope in a friend to help me diagnose why that's not working - could be one of many things that are nothing to do with this application itself.

I think there is one small bug, if you set your overnight charge start_time to "00:00" it never seems to fire. I've changed it to "00:06" and now it's working each night.

At the moment I don't plan to use the end_time_winter (extra hold). Should I just set that to the same value as end_time? (current "05:30"). Also, I don't plan to use the boost_start and boost_finish times for winter afternoons. What values should I set those to, to ignore this feature?

Thanks again - very generous of you.

S
#18 stevelewis

grahamhobson glad to hear it's working and thanks for finding the rollover bug - the routines at lines 559 and 567 run at 5 and 2 minutes before the start time, so midnight becomes -00:05 instead of 23:55. I'll fix it sometime soon.

As you suggest for the winter extra hold time. For winter boost, best to comment out the lines in the main loop near the end of the file.

Edit: Bug fixed in v0.8.5 on Github. Setting boost start and finish times to the same value disables this functionality.

G
#19 grahamhobson

stevelewis Hi Steve, thanks and I have installed v0.8.5 with the three new files. I've used the new settings template to create settings.py and transcribed over the inverter and solcast settings plus timing parameters. All looks ok but I get a runtime error:

graham@GRs-MacBook-Air palm % ~/Documents/Python/palm/palm_soc.py >>~/Documents/Python/logs/palm_soc.log 
Traceback (most recent call last):
  File "/Users/graham/Documents/Python/palm/palm_soc.py", line 564, in <module>
    TIME_NOW_MINS_VAR == start_time - 5:
                         ^^^^^^^^^^
NameError: name 'start_time' is not defined

For the record, class GE in settings is defined as follows:

class GE:
    """User settings for GivEnergy inverter API"""
    enable = True
    url = "https://api.givenergy.cloud/v1/inverter/CE2219G150/"
    key = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI5NTc3MDIxOS1jYWE2LTRmOTctOTE3Ni0zNDBlZGMzZDQxNTgiLCJqdGkiOiI0Y2FiYmM0NGJmZDczYmY1Y2MyNmY5MDIxYzg5MmRhMDM0ZGM4OWVlYjAxZWViNDgzYWZjZDJjOTBlNWU3NDNjNDJmOWE1MmQzN2M0MzI3YSIsImlhdCI6MTY4Mjk1MTA3My41NTgxNDgsIm5iZiI6MTY4Mjk1MTA3My41NTgxNTEsImV4cCI6MTcxNDU3MzQ3My41NTA0NTIsInN1YiI6IjE4MDYzIiwic2NvcGVzIjpbImFwaSJdfQ.HKRC675xfjpIgt35Kp_2p8Cph6K2CcH8VGrf1eDkcWD0E-w9L6eUZOnt0VHZt1hq8BQ3VG8jhkr-kZhUXElzdQ"

    # Disable SoC calculation in the winter months as consumption >> generation
    winter = ["01", "02", "11", "12"]

    # Throttle SoC calculation in shoulder months as consumption can vary with heating coming on
    shoulder = ["03", "04", "05", "09", "10"]

    # Lower limit for state of charge (summertime)
    min_soc_target = 25

    # Higher SoC limit for shoulder months
    max_soc_target = 75

    # Battery reserve for power cuts (minmum of 4%)
    batt_reserve = 4

    # Nominal battery capacity in kWh
    batt_capacity = 10.4

    # Proportion of battery that's usable
    batt_utilisation = 0.85

    batt_max_charge = batt_capacity * batt_utilisation

    # Inverter charge/discharge rate in kW
    charge_rate = 3

# Legacy parameter - deprecated at palm version 0.9.0 (moved to Octopus.sched)
    # Default data for base load. Overwritten by actual data if available
    base_load = [0.3, 2, 0.3, 0.3, 0.3, 0.5, 1.7, 1.8, 2.6, 1.5, 0.5, 2.5,\
        1.3, 1, 1.5, 0.5, 0.3, 1, 1.5, 1, 0.6, 0.5, 0.5, 0.3]

    # Start time for Overnight Charge
    start_time = "00:00"

    # End time for Overnight Charge
    end_time = "05:30"

    # Hold end time for 2 hours in winter to save battery for morning peak
    # To disable, set to same time as end_time above
    end_time_winter = "05:30"

    # Winter afternoon boost start and end times for Cosy Octopus
    # To disable, set boost_start and boost_finish to the same time
    boost_start = "05:30"
    boost_finish = "05:30"
S
#20 stevelewis

grahamhobson oops! Never update code after 11pm... Should be start_time_mins in two places to match the declaration immediately above.

S
#21 stevelewis

grahamhobson you may want to delete your system details from your post 😁

T
#22 Tim

grahamhobson You may have to ask Givenergy to delete your system details!

G
#23 grahamhobson

stevelewis Thanks Steve. Yeah, oops - forgot the inverter details were in there. Can't remove the post but I reset the API key as soon as I saw your message. I've applied the two changes and so far so good.

A further question if you don't mind, yesterday (running the previous version) just before midnight the algorithm calculated 100% upper charge limit, which is odd for the forecast being dry and mostly sunny today. I can't work out the interplay between predicted load and weather forecasts and how they are weighted. 24 hours earlier the charge limit was calculated at 45% and we had enough to fill the battery by early afternoon and run washing loads/dishwasher etc with plenty to spare (so that felt like the right level).

Output from the app since midnight... (and definitely no API keys)...

Successful Solcast download.
PV Estimate 10% (hrly, 7 days) / kWh ; 04-05-2023 00:01:05 ; [0.0, 0.0, 0.0, 0.0, 0.0, 0.009, 0.064, 0.194, 0.36, 0.48, 0.554, 0.584, 0.466, 0.31, 0.186, 0.084, 0.036, 0.015, 0.004, 0.0, 0.0, 0.0, 0.0] [3.404, 0.0, 0.0, 0.0, 0.0, 0.0]
PV Estimate 50% (hrly, 7 days) / kWh ; 04-05-2023 00:01:05 ; [0.0, 0.0, 0.0, 0.0, 0.001, 0.026, 0.231, 0.506, 0.803, 1.019, 1.164, 1.223, 1.089, 0.919, 0.739, 0.525, 0.381, 0.198, 0.017, 0.001, 0.0, 0.0, 0.0] [8.991, 0.0, 0.0, 0.0, 0.0, 0.0]
PV Estimate 90% (hrly, 7 days) / kWh ; 04-05-2023 00:01:05 ; [0.0, 0.0, 0.0, 0.0, 0.002, 0.069, 0.324, 0.687, 1.111, 1.48, 1.769, 1.942, 1.898, 1.748, 1.541, 1.278, 1.002, 0.582, 0.148, 0.002, 0.0, 0.0, 0.0] [15.847, 0.0, 0.0, 0.0, 0.0, 0.0]
Info; Load Calc Summary: 21.7 [0.0, 0.3, 0.4, 0.2, 0.3, 0.3, 0.2, 0.5, 1.3, 1.0, 1.0, 1.7, 1.5, 0.4, 2.3, 1.5, 2.3, 1.5, 1.5, 1.0, 0.6, 1.0, 0.5, 0.4]
Info; 10% forecast...

Info; SoC Calcs;           Hour     Charge       Cons         Gen        SoC
Info; SoC Calc;               0       8.84          0         0.0        100
Info; SoC Calc;               1       8.84          0         0.0        100
Info; SoC Calc;               2       8.84          0         0.0        100
Info; SoC Calc;               3       8.84          0         0.0        100
Info; SoC Calc;               4       8.84          0         0.0        100
Info; SoC Calc;               5       8.55        0.3        0.01         96
Info; SoC Calc;               6       8.41        0.2        0.06         95
Info; SoC Calc;               7       8.11        0.5        0.19         91
Info; SoC Calc;               8       7.17        1.3        0.36         81
Info; SoC Calc;               9       6.65        1.0        0.48         75
Info; SoC Calc;              10        6.2        1.0        0.55         70
Info; SoC Calc;              11       5.09        1.7        0.58         57
Info; SoC Calc;              12       4.05        1.5        0.47         45
Info; SoC Calc;              13       3.96        0.4        0.31         44
Info; SoC Calc;              14       1.85        2.3        0.19         20
Info; SoC Calc;              15       0.43        1.5        0.08          4
Info; SoC Calc;              16      -1.83        2.3        0.04        -20
Info; SoC Calc;              17      -3.32        1.5        0.01        -37
Info; SoC Calc;              18      -4.81        1.5         0.0        -54
Info; SoC Calc;              19      -5.81        1.0         0.0        -65
Info; SoC Calc;              20      -6.41        0.6         0.0        -72
Info; SoC Calc;              21      -7.41        1.0         0.0        -83
Info; SoC Calc;              22      -7.91        0.5         0.0        -89
Info; SoC Calc;              23      -8.31        0.4         0.0        -94

Info; SoC Calc Summary;   Max Charge Min Charge      Max %      Min % Target SoC
Info; SoC Calc Summary;            0      -8.31          0        -94        100
Info; SoC (Adjusted);              0      -8.31          0        -94          

Info; SoC Summary;  04-05-2023 00:04:06 ; Tom Fcast Gen (kWh);  3.404 ; 8.991 ; 15.847 ; SoC Target (%);  100 ; Today Gen (kWh);  0.0 2
Info; 50% forecast...

Info; SoC Calcs;           Hour     Charge       Cons         Gen        SoC
Info; SoC Calc;               0       8.84          0         0.0        100
Info; SoC Calc;               1       8.84          0         0.0        100
Info; SoC Calc;               2       8.84          0         0.0        100
Info; SoC Calc;               3       8.84          0         0.0        100
Info; SoC Calc;               4       8.84          0         0.0        100
Info; SoC Calc;               5       8.57        0.3        0.03         96
Info; SoC Calc;               6        8.6        0.2        0.23         97
Info; SoC Calc;               7        8.6        0.5        0.51         97
Info; SoC Calc;               8       8.11        1.3         0.8         91
Info; SoC Calc;               9       8.13        1.0        1.02         91
Info; SoC Calc;              10       8.29        1.0        1.16         93
Info; SoC Calc;              11       7.81        1.7        1.22         88
Info; SoC Calc;              12        7.4        1.5        1.09         83
Info; SoC Calc;              13       7.92        0.4        0.92         89
Info; SoC Calc;              14       6.36        2.3        0.74         71
Info; SoC Calc;              15       5.39        1.5        0.53         60
Info; SoC Calc;              16       3.47        2.3        0.38         39
Info; SoC Calc;              17       2.16        1.5         0.2         24
Info; SoC Calc;              18       0.68        1.5        0.02          7
Info; SoC Calc;              19      -0.32        1.0         0.0         -3
Info; SoC Calc;              20      -0.92        0.6         0.0        -10
Info; SoC Calc;              21      -1.92        1.0         0.0        -21
Info; SoC Calc;              22      -2.42        0.5         0.0        -27
Info; SoC Calc;              23      -2.82        0.4         0.0        -31

Info; SoC Calc Summary;   Max Charge Min Charge      Max %      Min % Target SoC
Info; SoC Calc Summary;          8.6      -2.82         97        -31        100
Info; SoC (Adjusted);            8.6      -2.82         97        -31          

Info; SoC Summary;  04-05-2023 00:04:06 ; Tom Fcast Gen (kWh);  3.404 ; 8.991 ; 15.847 ; SoC Target (%);  100 ; Today Gen (kWh);  0.0 2
Info; 90% forecast...

Info; SoC Calcs;           Hour     Charge       Cons         Gen        SoC
Info; SoC Calc;               0       8.84          0         0.0        100
Info; SoC Calc;               1       8.84          0         0.0        100
Info; SoC Calc;               2       8.84          0         0.0        100
Info; SoC Calc;               3       8.84          0         0.0        100
Info; SoC Calc;               4       8.84          0         0.0        100
Info; SoC Calc;               5       8.61        0.3        0.07         97
Info; SoC Calc;               6       8.74        0.2        0.32         98
Info; SoC Calc;               7       8.92        0.5        0.69        100
Info; SoC Calc;               8       8.73        1.3        1.11         98
Info; SoC Calc;               9       9.21        1.0        1.48        104
Info; SoC Calc;              10       9.98        1.0        1.77        112
Info; SoC Calc;              11      10.22        1.7        1.94        115
Info; SoC Calc;              12      10.62        1.5         1.9        120
Info; SoC Calc;              13      11.97        0.4        1.75        135
Info; SoC Calc;              14      11.21        2.3        1.54        126
Info; SoC Calc;              15      10.99        1.5        1.28        124
Info; SoC Calc;              16       9.69        2.3         1.0        109
Info; SoC Calc;              17       8.77        1.5        0.58         99
Info; SoC Calc;              18       7.42        1.5        0.15         83
Info; SoC Calc;              19       6.42        1.0         0.0         72
Info; SoC Calc;              20       5.82        0.6         0.0         65
Info; SoC Calc;              21       4.82        1.0         0.0         54
Info; SoC Calc;              22       4.32        0.5         0.0         48
Info; SoC Calc;              23       3.92        0.4         0.0         44

Info; SoC Calc Summary;   Max Charge Min Charge      Max %      Min % Target SoC
Info; SoC Calc Summary;        11.97       8.61        135         97         65
Info; SoC (Adjusted);          11.97       8.61        100         62          

Info; SoC Summary;  04-05-2023 00:04:06 ; Tom Fcast Gen (kWh);  3.404 ; 8.991 ; 15.847 ; SoC Target (%);  65 ; Today Gen (kWh);  0.0 2
Info; 35% weighted forecast...

Info; SoC Calcs;           Hour     Charge       Cons         Gen        SoC
Info; SoC Calc;               0       8.84          0         0.0        100
Info; SoC Calc;               1       8.84          0         0.0        100
Info; SoC Calc;               2       8.84          0         0.0        100
Info; SoC Calc;               3       8.84          0         0.0        100
Info; SoC Calc;               4       8.84          0         0.0        100
Info; SoC Calc;               5       8.56        0.3        0.02         96
Info; SoC Calc;               6       8.53        0.2        0.17         96
Info; SoC Calc;               7       8.42        0.5        0.39         95
Info; SoC Calc;               8       7.75        1.3        0.64         87
Info; SoC Calc;               9       7.57        1.0        0.82         85
Info; SoC Calc;              10       7.51        1.0        0.94         84
Info; SoC Calc;              11       6.79        1.7        0.98         76
Info; SoC Calc;              12       6.15        1.5        0.86         69
Info; SoC Calc;              13       6.44        0.4        0.69         72
Info; SoC Calc;              14       4.67        2.3        0.53         52
Info; SoC Calc;              15       3.53        1.5        0.36         39
Info; SoC Calc;              16       1.48        2.3        0.25         16
Info; SoC Calc;              17       0.11        1.5        0.13          1
Info; SoC Calc;              18      -1.38        1.5        0.01        -15
Info; SoC Calc;              19      -2.38        1.0         0.0        -26
Info; SoC Calc;              20      -2.98        0.6         0.0        -33
Info; SoC Calc;              21      -3.98        1.0         0.0        -45
Info; SoC Calc;              22      -4.48        0.5         0.0        -50
Info; SoC Calc;              23      -4.88        0.4         0.0        -55

Info; SoC Calc Summary;   Max Charge Min Charge      Max %      Min % Target SoC
Info; SoC Calc Summary;         6.44      -4.88         72        -55        100
Info; SoC (Adjusted);           6.44      -4.88         72        -55          

Info; SoC Summary;  04-05-2023 00:04:06 ; Tom Fcast Gen (kWh);  3.404 ; 8.991 ; 15.847 ; SoC Target (%);  100 ; Today Gen (kWh);  0.0 2
Info; Setting Register 77 (AC Charge Upper % Limit) to 100,                       Response:<Response [201]>
Info; Setting Register 64 (AC Charge 1 Start Time) to 00:06,                       Response:<Response [201]>
Info; Setting Register 65 (AC Charge 1 End Time) to 05:30,                       Response:<Response [201]>
S
#24 stevelewis

grahamhobson The 100% target looks right - there's not enough generation to pull the SoC above 100% during the day with the 35% confidence value (palm_soc.py line 589). Do you have the correct array size configured in Solcast? (I'm guessing you have about 2kWp).

The previous day's load is used as the reference so going all-out on a sunny afternoon can have an impact the following day, especially if a cloudy morning and sunny afternoon is being forecast. Also, if your load is dominated by a weekly cycle, referencing the load from the same day the previous week is possible, it really depends on your usage pattern.

G
#25 grahamhobson

stevelewis Ah, ok, that makes sense. I actually have 12 panels, so a 4kW theoretical maximum (but in practice about 3kW at best).

Last year I was playing around with solcast and noticed that its graphical forecasts of my PV output were always higher than what I actually achieved, even after applying the recommended 92% efficiency factor. I ramped it right down to 50% which is where the issue is. I’ll put it back up to 80% or 90% and see how things look then.

Thanks again Steve - really appreciated.

G
#26 grahamhobson

Hi stevelewis , I continue to get great use out of your palm application. I made some minor changes to my copy of palm_soc.py a couple of days ago, so that I can run it from a schedule iOS/iPadOS automation at say 11pm, rather than having to have a continuously running service on a Raspberry Pi or MacBook. Here are the comments I added…

# NOTE: this is the modified version of palm_soc by Graham Hobson created 12 May 2023. Changes include:
# New command line argument (-o) added to enable once mode (immediate execution then exit).
# This is useful if the application is run from a cron job or iOS scheduled event.
# When using once mode, setting inverter start_time and end_time is now optional. They can 
# be set to empty strings in settings.py and the times won't be updated in the
# inverter registers (for users that want to control times through the GivEnergy app).
# Added timestamp to start of main loop logging. Useful for log analysis.
# Corrected one typo in log narrative.

It’s a small number of changes. Would you be interested to see the code and potentially incorporate it into a future release? If so let me know the best way to send it to you (here, GitHub, elsewhere?).

T
#27 Tim

grahamhobson Not wanting to steamroller @stevelewis's response, but I suspect that if you fork his Github repo, make the changes on your fork and make a Pull Request on his original repo, he can incorporate your changes directly into his repo, available for everyone else on an update. 🫢

S
#28 stevelewis

Tim that's the idea 👍

S
#29 stevelewis

grahamhobson Hi Graham, I like the run once option (the cut-down palm_ha.py version which has been ported to Home Assistant does something similar by default). Please could you drop your code into GitHub and I'll take a look.merge the changes.

G
#30 grahamhobson

stevelewis Done (I think). First time I’ve done a PR on GitHub, so let me know if not the results you were expecting to see.

S
#31 stevelewis

FYI: Multiple updates have been made to palm.py. Latest version is now released on Github