Setting overnight battery charge level

Ever since I set up Solcast once I had the solar panels installed I have been recording my generation compared to the forecast. All in all the forecast is pretty close. The daily forecast is very close, but doesn’t help me set the overnight charge level. The trick is to set the level as late in the day as you can with the tomorrow forecast. I set mine at 8.30pm. My last Solcast update is 8.00pm.

If the next day is going to be a good generation day there is no point in charging the battery fully to 100%. This automation sets overnight charge percentage.

alias: Set Nightly Battery Charge Level v2
description: Set Nightly Battery Charge Level v2
trigger:
  - platform: time
    at: "20:30:00"
condition: []
action:
  - service: number.set_value
    data:
      value: >
        {% set x = states('sensor.solcast_forecast_tomorrow') | int(0) %} {% set
        levels = { 7: 90, 8: 80, 9: 75, 10: 70, 11: 60, 12: 40, 13: 40 } %} {{
        100 if 0 <= x <= 6 else levels.get(x, 20) }}
    target:
      entity_id: number.lux_ac_battery_charge_level
  - service: notify.notify
    data:
      message: >-
        The battery charge level has been set to {{
        states("number.lux_ac_battery_charge_level") }}
      title: Nightly Battery Charge Level
mode: single

This isn’t very scientific, but this is what I have come up with. It takes the Solcast tomorrow forecast value and makes it an integer and assigns it to X. If the value of X is between 0 and 6, the charge level will be 100%. The rest works like this:

7 = 90%

8 = 80%

9 = 75%

10 = 70%

11 = 60%

12 and 13 = 40%

Anything over 13 will 20%

The only issue I have is, if the solar generation isn’t as forecast then the charge level might be too high and the afternoon top up charge might kick in. For example, if the overnight charge level is 80% and generation is slow, the battery might only be at 60% when the cheap afternoon Agile slot starts. I have found the cheapest afternoon slot is normally around 2-3pm. That does give me enough time to make a decision and change it manually if required. Most days the generation is enough to hit the target, but it is a flaw. It is something I need to look into.

This is still a work in progress, but it is doing a decent job so far.

 
Michael Curtis

My introduction to computers started at my middle school in 1981 when our maths teacher brought in a ZX80. That led the computer club being founded and using a Research Machine 380Z

My first computer was a 48K ZX Spectrum which I loved to programme. Once I left school I worked as a photocopier engineer, then a fax engineer and finally moving on the Apple computers.

For the next 30 years I worked as a system administrator. I now work in the cyber security industry as a Sophos Professional Services consultant

https://www.bazmac.me
Previous
Previous

March’s Solar Generation Numbers

Next
Next

Setting up Home Assistant to upload to PVOutput