Tweaking the charge rate with Predbat/HomeAssistant

15 comments started 2025-11-03 last 2025-11-06
Home AutomationHome Assistant
W
#1 Weasel

Hi,
I would like to know if/how it is possible to automatically change the charging rate of my AIO. I have HomeAssistant and PredBat; plus I am a techie who likes to roll my sleevs up.

Background:
In a conversation with my next-door neighbours, they were griping about how their lights flickered at 10pm precisely each evening. Our two properties share a common overhead feed from the other side of the road which runs down our border to a pole and then splits to each of our houses. Therefore I wondered whether my battery charging might be causing an issue.

I tested my hypothesis by delaying the start of the charging until 10:30 and sure enough, their lights flickered at 10:30. I have delayed my charging until 11pm for now and that would be OK for me, but I am wondering whether I could set things up so that for the 10pm-midnight charging slots, I only charged at 3kW rather than the regular 6kW. This should have less of an effect on my neighbours.

I have also suggested that the neighbours contact SSE to get their advice because surely my 6kW should not be affecting them

R
#2 Rubikcube

Weasel less of an effect on my neighbours.

I suspect that the effect is caused by a "surge" when the charger circuit turns on (initially charging capacitors) before the battery starts charging. In which case the battery charge rate is irrelevant.

Are you saying that your lights don't flicker? Are your neighbour's lights just bulbs? What type of bulbs? The nicest solution might be just to buy your neighbour some decent quality light bulbs.

V
#3 Vestas

Weasel What's the grid voltage when this happens. Its unlikely to be anything healthy.

G
#4 geoffreycoan

Weasel you can most certainly vary the charge rate with predbat

simplest is to turn on low rate charging so predbat will charge at the lowest rate it can to meet the plan target SoC, e.g. at the end of the cheap rate charging period. This will do a slow rate charge all night which will reduce the grid voltage drop and be kinder to your batteries

alternatively you can permanently change your charge rate in apps.yaml. Probably not an issue for the winter as there will be little solar, but this will affect all charging

or third alternative is to use the predbat manual API to override the max charge rate via an automation, and set it back afterwards. I can give you an automation that does this

W
#5 Weasel

geoffreycoan a script would be fantastic sir. I can lower the charge rate for the 2200-0000 cosy slot only

G
#6 geoffreycoan

Weasel here you are

alias: Throttle charge rate for Cosy 10pm period
description: Using predbat_manual_api
triggers:
  - trigger: time
    at:
      - "21:30:00"
    id: reduce-charge-rate
  - trigger: time
    at: "00:30:00"
    id: restore-charge-rate
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - reduce-charge-rate
        sequence:
          - if:
          - alias: Set charge rate to 2000W
            action: select.select_option
            target:
              entity_id:
                - select.predbat_manual_api
                data:
                  option: inverter_limit_charge(0)=2000
      - conditions:
          - condition: trigger
            id:
              - restore-charge-rate
        sequence:
          - alias: Set charge rate to 6000W
            action: select.select_option
            target:
              entity_id:
                - select.predbat_manual_api
            data:
              option: >-
                inverter_limit_charge(0)=6000
trace:
  stored_traces: 10
mode: single
W
#7 Weasel

A thousand thanks sir, I was not expecting such a complete solution, just a pointer to the relevant entities

G
#8 geoffreycoan

Weasel I had my own summer clipping control automation for Predbat that throttles the charge rates up and down for my own inverters to trickle feed the batteries from solar to stop clipping, so I had much of the code already in place and was able to cut it down to what you would need

L
#9 Leeshore

geoffreycoan Is it possible if you could share the code for your automation to stop clipping?

G
#10 geoffreycoan

Leeshore Is it possible if you could share the code for your automation to stop clipping?

No problem, here is the full automation. Its obviously custom to my own setup with two inverters and there is some bits that remain disabled, but in essence the sequence was:

If solar forecast is high, stop both inverters from charging in the morning, so export everything
Mid morning start trickle charging one inverter
Midday start trickle charging second inverter and if first isn’t full, set to full charge rate
Set to full charge rate just before dusk in case there are overnight cheap rate slots predbat wants to charge from

There were bits about forcing demand overnight as well to run the batteries down, or force discharge to ensure empty in the morning.

alias: Predbat summer clipping control v2
description: Using predbat_manual_api
triggers:
  - trigger: time
    at:
      entity_id: sensor.sun_next_dawn
      offset: "-00:30:00"
    id: sunrise
  - trigger: time
    at:
      - "11:00:00"
    id: morning-start-G
  - trigger: time
    at: "13:45:00"
    id: midday-start-H
  - trigger: time
    at:
      entity_id: sensor.sun_next_dusk
      offset: "-00:20:00"
    id: sunset-stop-cross-charging
    enabled: true
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            alias: Sunrise
            id:
              - sunrise
        sequence:
          - if:
              - alias: Today's solar forecast is above 40kWh, clipping will occur
                condition: numeric_state
                entity_id: sensor.predbat_pv_today
                above: 40
            then:
              - alias: Stop charging, set charge rate to 100W
                action: select.select_option
                target:
                  entity_id:
                    - select.predbat_manual_api
                data:
                  option: inverter_limit_charge(0)=100,inverter_limit_charge(1)=0
            else:
              - action: select.select_option
                alias: Set G & H to max charge rate
                target:
                  entity_id:
                    - select.predbat_manual_api
                data:
                  option: inverter_limit_charge(0)=2600,inverter_limit_charge(1)=2600
        alias: Stop charging until peak of the day
      - conditions:
          - condition: trigger
            alias: Start trickle charging G
            id:
              - morning-start-G
        sequence:
          - alias: Cancel trickle discharge
            action: select.select_option
            target:
              entity_id:
                - select.predbat_manual_api
            data:
              option: >-
                inverter_limit_discharge(0)=2600,inverter_limit_discharge(1)=2600
          - action: switch.turn_on
            target:
              entity_id: switch.predbat_set_charge_freeze
            data: {}
            enabled: false
          - if:
              - condition: numeric_state
                alias: Today's solar forecast is above 30kWh
                entity_id: sensor.predbat_pv_today
                above: 30
            then:
              - action: select.select_option
                alias: Trickle charge G, set charge rate to 1500W & H to 0W
                target:
                  entity_id:
                    - select.predbat_manual_api
                data:
                  option: inverter_limit_charge(0)=1500,inverter_limit_charge(1)=0
            else:
              - action: select.select_option
                alias: Set G & H to max charge rate
                target:
                  entity_id:
                    - select.predbat_manual_api
                data:
                  option: inverter_limit_charge(0)=2600,inverter_limit_charge(1)=2600
      - conditions:
          - condition: trigger
            alias: Start trickle charging H
            id:
              - midday-start-H
        sequence:
          - if:
              - condition: numeric_state
                alias: If G is not already half full
                entity_id: sensor.g_sd2237g182_soc
                below: 50
            then:
              - action: select.select_option
                alias: Set G to max charge rate
                target:
                  entity_id:
                    - select.predbat_manual_api
                data:
                  option: inverter_limit_charge(0)=2600
          - if:
              - condition: numeric_state
                alias: Today's solar forecast is above 30kWh
                entity_id: sensor.predbat_pv_today
                above: 30
            then:
              - alias: Set H charge rate to 1000W
                action: select.select_option
                target:
                  entity_id:
                    - select.predbat_manual_api
                data:
                  option: inverter_limit_charge(1)=1000
            else:
              - action: select.select_option
                alias: Set G & H to max charge rate
                target:
                  entity_id:
                    - select.predbat_manual_api
                data:
                  option: inverter_limit_charge(0)=2600,inverter_limit_charge(1)=2600
      - conditions:
          - condition: trigger
            alias: Stop inverters cross charging after sunset
            id:
              - sunset-stop-cross-charging
        sequence:
          - alias: Set H charge rate to 0W to stop cross charging
            action: select.select_option
            target:
              entity_id:
                - select.predbat_manual_api
            data:
              option: inverter_limit_charge(0)=2000,inverter_limit_charge(1)=0
            enabled: false
          - delay:
              seconds: 20
            enabled: false
          - action: select.select_option
            alias: Grid import for 10-11pm evening Cosy period
            target:
              entity_id:
                - select.predbat_manual_freeze_charge
            data:
              option: 22:00:00,22:30:00
            enabled: false
          - delay:
              seconds: 20
            enabled: false
          - alias: Run off batteries from 11pm to 6am
            action: select.select_option
            target:
              entity_id:
                - select.predbat_manual_demand
            data:
              option: >-
                22:00:00,22:30:00,23:00:00,23:30:00,04:00:00,04:30:00,05:00:00,05:30:00
            enabled: false
          - action: switch.turn_off
            target:
              entity_id: switch.predbat_set_charge_freeze
            data: {}
            enabled: false
          - action: select.select_option
            metadata: {}
            data:
              option: Control charge & discharge
            target:
              entity_id: select.predbat_mode
      - conditions:
          - condition: trigger
            alias: Discharge the batteries after sunrise
            id:
              - sunrise-discharge
            enabled: true
        sequence:
          - if:
              - alias: Today's solar forecast is above 45kWh, clipping will occur
                condition: numeric_state
                entity_id: sensor.predbat_pv_today
                above: 45
            then:
              - alias: Trickle discharge, set discharge rate to 1400W
                action: select.select_option
                target:
                  entity_id:
                    - select.predbat_manual_api
                data:
                  option: >-
                    inverter_limit_discharge(0)=1400,inverter_limit_discharge(1)=1400
              - alias: Empty the remaining battery power
                action: select.select_option
                target:
                  entity_id:
                    - select.predbat_manual_export
                data:
                  option: >-
                    05:00:00,05:30:00,06:00:00,06:30:00,07:00:00,07:30:00,08:00:00
            enabled: false
trace:
  stored_traces: 10
mode: single
G
#11 Goshiki2

geoffreycoan Or a fourth method could be to use an automation to select a percentage value for “number.givtcp********battery_charge_rate_ac”
which affects AC charging only.

G
#12 geoffreycoan

Goshiki2 Or a fourth method could be to use an automation to select a percentage value for “number.givtcp********battery_charge_rate_ac”
which affects AC charging only.

good point, and doesn't affect PV charging. I tend not to use that entity because its not one that predbat controls or knows about.

Wherever possible since I am using predbat I try to keep everything within predbat's control. If you throttle the AC charge rate, Predbat will think you're still charging at the full rate and so will produce a plan that can't be achieved.
Of course predbat will recalculate the plan every 10 minutes and the SoC not being where it should be will be noticed

W
#13 Weasel

I too like to keep battery things controlled by the predbat APIs.

I took your script and once I understood how it was interacting with the predbat API, it all made sense. To make sure that I got it all right, I created my own automations. I created 2 separate ones so that I could more readily test them and I can confirm that things look OK. I will know for sure tonight

Once again, many thanks

G
#14 geoffreycoan

Weasel no problem

use of trigger id's and conditions are great, really reduce the number of different automations you need. There's a good smart home junkie video on this technique

W
#15 Weasel

I agree that trigger IDs are great - I just have never used them because I take a bottom-up approach to my automations.

The current set up with 2 separate automations works fine for now and now that I better understand how the API works, I am going to create something that starts off with a very low charge rate (e.g. 500W) and every couple of minutes increases it by 500W until it reaches the max rate.

I have in mind a timed routine that looks at the current charge rate and if less than the maximum, steps it up. The routine will run on a 5 minute timer. Just before the cosy period, I will have a 2nd routine that lowers the charge rate to 500W. The 1st routine will then ramp it up.

This is more a "just because I can" situation, but if it stops my neighbour's lights briefly flickering at 10pm when I suddenly start drawing 6kW, then it works for me.