Load balancing current to EV-charger

Got a PHEV the other week and installed a stationary charger (Easee Home).
(Btw, great job with the costum component @fondberg ).

As I’m located in an area where the grid supplier don’t have a proper load balancing connector (RJ45) to the ingoing meter I can’t use the dedicated harwired balancer that the manufacturer supply. Eventually I will have a connector, but that will be RJ12. Easee will realease a RJ12 version of their load balancer “Equalizer” but for the time being I’m stuck with nothing.

So I need to do the load balancing manually. Good thing I have installed 3 meters (zwave) in house, and most relevant to the ingoing consumption.

The description would be like:

  1. Charger start at a always safe level set, 6A (in my particular case that’s 11A). This is set as default in the charger as well as a reset after each charging stop.
  2. If house consumption is low enough, the charger increase to a level where it still keep the house+charger under 20A.
  3. If house consumption decrese, the charger should increase, still not over 20A.
  4. If house consumption increse, the charger should decrese, still not over 20A.
  5. Whenever the charger stop, the safe start level is reset (6A).

Now the problem is I just got from Vera (LUA). So I’m kinda new to the platform but know my way around automation in general so logics might not be the problem here.
Being new to Home Assistant I’m not perfectly sure how or where to put the getting and setting of entity states.

I can’t be the only one with this need so I thought it would be a good thing to ask if anyone has made such automation and might be able to share how?

look at Hellowlol/chargebot: chargebot for appdaemon (github.com)

Looks exactly what I need.
Though I’m unfamiliar with running applications on Home Assistant and doubt that will be something I can run on a RPI Supervisor installation?

Haven’t figured out how to install AppDaemon on a RPi w Supervisor yet so I will try to do it the hard way by using your Easee integration’s service “set_charger_circuit_dynamic_limit” and have that run through and automation involving the measured current from a Qubino 3-phase Meter (3PM).

I’ll share a working blueprint once done.

As a side-note, chargebot uses wattage and a fixed voltage. Should work ok, but its not right (my voltage varies outside what the grid supplier i guarantees (10%)).

Another side note about that is that Aeotec Home Elecric Meter (HEM) is prioritizing current (A) before power (W), while the Qubino 3PM does the opposite. So I would use my 3PM with chargebot and HEM for actual balancing.

Haven’t had any luck.

I used the tip from @olalid at.

Great start but I fail to get that ‘sensor.allowed_current’ to work properly as a template sensor. I have a max fuse at 20A, so the Qubino sensor says 20 minus itself (let’s say it’s 2). So the set_circuit_dynamic_limit gets set to 20-2=18 A, which is more than 16 A which the charger is rated for in the box (max circuit current). So this uses 16 A.
But then there is only 20-16-2=2 A reported to sensor.allowed.current, so the charger is then set to 2A which is below 6A meaning the charger will turn off until it reports back 18 A allowed current in the next step. Which goes on and on and on. Not very ideal for neither the charger, the household wires nor the hybrid battery in the car.

I’ve tried doing some fancy function in the template sensor but the only luck I’ve had it starts reading it self and loop up or down to infinity. Home Assistant seems to be lacking a “delay” in the sensor template to not risk it reading it’s own value and interger in to itself.

So, anyone have any ideas of how to solve it?

By the way, what does the “Smart charging” switch do besides turning my charger blue and stall at “waiting for load balancing”?

When you change the setting of the charger, it will decrease the household consumption by the same amount.
So you need to make a different reasoning.

  1. You need a target value. Seems like you want to use 20A as a target. It should be something like 80% of your main fuse rating maximum.
  2. If your car is using 16A and the rest of the household is using 6A (seems like you are measuring that separately?), then that is 16+6 = 22A. That is 2A over the target value, so you should decrease the allowed current for the charger by 2 or even something less than that, maybe like 0,4*2 to not overshoot the target. So if the old setting was 16, then it should now be 15,2 (which then is rounded to 15A before sending it to the charger).
  3. This calculation needs to be done periodically, like every 20-30 seconds maximum. There is no point whatsoever to calculate this more often than what the current readings are received. This is tricky to do with home assistant, I have solved that by setting the value of an “input_text” with an automation that is triggered every 20 seconds.
  4. You should consider having an hysteresis to avoid that the charger changes between to consecutive values back and forth. So if the consumption is between 19 and 20A for instance, then do nothing.

And, well, if you have a 3-phase electrical system it all becomes more complicated of course.

Did you get any further with this @lucruc ?

Well, yes but not in a very nice way. I wanted to have these all sensors kind of like a analoge regulator.
Until I get a Easee Load Balancer to put in my Swedish meter-port, I just made it work.
Perhaps there will be better solutions when this becomes an official integration. It would have been different if I had a 3-phase EV and not just a 1-phase PHEV, then I would have to spend some more time on this to make it work nicer :slight_smile:

But I’m happy to tell how I did. Bet there will be plenty of contributors telling me there is better ways :smiley:

Script for start
Note: You should also make three more for the stop, pause and resume.
It does start a sequence by setting the current to 8A since I found it to be creeping to 40A under some circumstances. Never set it lower than 6A since it will be the maintenance load limit for the Easee charger (and other chargers too btw). Starting from 8A will take a few polls from the Home Electric Meter (HEM) to ramp up, but with frequent polling it’s about 2 minutes. Starting from 40A would take relatively long time to ramp down and could mean you run your home in 20-40A for tens of minutes, I’ve run mine in 25-27 several times. Not good but workable with healthy wiring and slow regular fuses.

alias: Easee Start
sequence:
  - service: easee.set_circuit_dynamic_limit
    data_template:
      circuit_id: <NNNNN, YOUR circuit, five numbers>
      currentP1: 8 <6+2=8A>
      currentP2: 8 <6+2=8A>
      currentP3: 8 <6+2=8A>
  - service: easee.start
    data:
      charger_id: <AANNNNNN, YOUR charger ID, two capital letters and six numbers>
mode: single
icon: hass:play

Automation for increase
Note: House hold is 20A so below is set to 20-1=19. Charger fuse is 16.
I have a slider for the household fuse that I planned on using, but nah, this would probably be the only automation I’d use it for.
The action is a step up of 1A if the conditions are met.
By the way, my HEM is (if not obvious) sensor.hem_ampere_l1.

alias: Easee L1 Increase
description: ''
trigger:
  - platform: state
    entity_id: sensor.hem_ampere_l1
condition:
  - condition: and
    conditions:
      - condition: numeric_state
        entity_id: sensor.hem_ampere_l1
        below: '19' <20-1=19A>
        above: '0'
      - condition: state
        entity_id: sensor.easee_status
        state: charging
      - condition: numeric_state
        entity_id: sensor.easee_dynamic_circuit_limit
        above: '0'
        below: '16' <Circuit fuse, which is also the limit set in Easee installation>
action:
  - service: easee.set_circuit_dynamic_limit
    data_template:
      circuit_id: <NNNNN, YOUR circuit, five numbers>
      currentP1: >-
        {{ (states.sensor.easee_dynamic_circuit_limit.state|float|round(0) + 1)
        }}
mode: single
max: 3

Automation for decrease
Note: Easee shuts down at 6A, and then it’s hard to regulate so we don’t want that. Therefore 6+1=A. Still, we don’t want to go over household fuse which is 20A.
The action is a stepdown by 1A if the conditions are met.

alias: Easee L1 Decrease
description: ''
trigger:
  - platform: state
    entity_id: sensor.hem_ampere_l1
condition:
  - condition: and
    conditions:
      - condition: numeric_state
        entity_id: sensor.hem_ampere_l1
        above: '20' <Household fuse>
      - condition: state
        entity_id: sensor.easee_status
        state: charging
      - condition: numeric_state
        entity_id: sensor.easee_dynamic_circuit_limit
        above: '7' <6+1=7A>
action:
  - service: easee.set_circuit_dynamic_limit
    data_template:
      circuit_id: <NNNNN, YOUR circuit, five numbers>
      currentP1: >-
        {{ (states.sensor.easee_dynamic_circuit_limit.state|float|round(0) - 1)
        }}
mode: single
max: 3

As said, not a pretty solution but it works for me. If Easee just did not have a load balancer for P12 on it’s way, I would probably spend more time to it.
Let me know how it works and if anyone have any better input. The chargebot appdaemon would work but I don’t want to alter my Hass too much for this application. I have about 80 zwave & zigbee units in my house and Easee is one only.

@lucruc this is brilliant, thank you for sharing. I’m using using a slightly modified version of this and it’s working flawlessly.

Could it be beneficial to use this method instead of Tibber’s corresponding implementation?

EDIT: Sorry, I was referring to Hellowlol/chargebot: chargebot for appdaemon (github.com)

Good thing with Tibber operator for Easee it is already configured and continously maintained. Home Assistant is always changing requiring alot of looking after when integrations or other variables change over updates.

Have no experience of chargebot but I would expect it is a good offline service not needing cloud service through Tibber/Easee.

Thx for this great method of load balancing. I used your automations as a base for my setup.
I have 2 Easee chargers on a 3 phase circuit. I measure each phase with a Shelly 3EM. So I created 5 similar automations.
One decrease for each phase, and one increase for each charger.
Works great so far!

1 Like

Thanks for the script. I am new to hass, and tried to find a way to load balancing e-go charger. I have adapted scripts for 3 phases, e-go charger and shelly 3em power meter. I have set my shelly 3em to update measurementes every 2 seconds, so charging ramps down from 16A to 6A in 20 seconds. If ramp down seems to be too slow i may just drop charging current to 6A, and let it ramp up again from there.

This has been working for couple of days, so i leave it here, hope it helps.
For this to work hass needs to have homeassistant-goecharger-mqtt

For decreasing charging current:

- id: '1648324411434'
  alias: Decrease_ev_charge_amps
  description: Decrease EV charger amps to avoid overcurrent
  trigger:
  - platform: state
    entity_id: sensor.shelly_3em_mainpwr_current_0
  - platform: state
    entity_id: sensor.shelly_3em_mainpwr_current_1
  - platform: state
    entity_id: sensor.shelly_3em_mainpwr_current_2
  condition:
  - condition: and
    conditions:
    - condition: state
      entity_id: sensor.go_echarger_<Go-Charger serial>_car
      state: Charging
    - condition: device
      type: is_current
      device_id: 0472bf0cfb8b1bb51b1ba67ff7b5205d
      entity_id: number.go_echarger_<Go-Charger serial>_amp
      domain: sensor
      above: 7
    - condition: or
      conditions:
      - type: is_current
        condition: device
        device_id: cbb84a832bca9a53d3670601a8094f28
        entity_id: sensor.shelly_3em_mainpwr_current_0
        domain: sensor
        above: 22
      - type: is_current
        condition: device
        device_id: cbb84a832bca9a53d3670601a8094f28
        entity_id: sensor.shelly_3em_mainpwr_current_1
        domain: sensor
        above: 22
      - type: is_current
        condition: device
        device_id: cbb84a832bca9a53d3670601a8094f28
        entity_id: sensor.shelly_3em_mainpwr_current_2
        domain: sensor
        above: 22
  action:
  - service: goecharger_mqtt.set_config_key
    data:
      serial_number: <Go-Charger serial>
      key: amp
      value: '{{ (states.number.go_echarger_<Go-Charger serial>_amp.state |float|round(0) - 1)}}'
  mode: single
  max: 3

For increasing charging current:

- id: '1648389547513'
  alias: Increase_ev_charge_amps
  description: Increase EV charger amps
  trigger:
  - platform: state
    entity_id: sensor.shelly_3em_mainpwr_current_0
  - platform: state
    entity_id: sensor.shelly_3em_mainpwr_current_1
  - platform: state
    entity_id: sensor.shelly_3em_mainpwr_current_2
  condition:
  - condition: and
    conditions:
    - condition: state
      entity_id: sensor.go_echarger_<Go-Charger serial>_car
      state: Charging
    - condition: device
      type: is_current
      device_id: 0472bf0cfb8b1bb51b1ba67ff7b5205d
      entity_id: number.go_echarger_<Go-Charger serial>_amp
      domain: sensor
      below: 16
    - type: is_current
      condition: device
      device_id: cbb84a832bca9a53d3670601a8094f28
      entity_id: sensor.shelly_3em_mainpwr_current_0
      domain: sensor
      below: 19
    - type: is_current
      condition: device
      device_id: cbb84a832bca9a53d3670601a8094f28
      entity_id: sensor.shelly_3em_mainpwr_current_1
      domain: sensor
      below: 19
    - type: is_current
      condition: device
      device_id: cbb84a832bca9a53d3670601a8094f28
      entity_id: sensor.shelly_3em_mainpwr_current_2
      domain: sensor
      below: 19
  action:
  - service: goecharger_mqtt.set_config_key
    data:
      serial_number: <Go-Charger serial>
      key: amp
      value: '{{ (states.number.go_echarger_<Go-Charger serial>_amp.state |float|round(0) + 1)}}'
  mode: single
  max: 3
6 Likes

Just an easy question. The script, do you make it run thru an automation or what? I made the script and automatisations as above but the dynamic limit usually starts at 40A and it takes alot of time to get down to right level. So should I just automate the script for exemple when easee starts?

Stupid question hoping you are still active.

How do I get/find my Circuit_id and Charger_id?

On https://easee.cloud using your account.

Thanks a lot for this, made my life a lot easier.

Works like charm except I need max power to L1 (charging only from that…) so controlling L2&L3 is irrelevant (don’t want to have power decreasing on L1 if L2 or L3 load gets too high, they have their own control). However have to do a switcher between 3phase and 1phase controlling if a 3 phase car is plugged.

I have changed script after those old ones.

I have now P1 (HAN) port in electricity meter, and it outputs current readings in 10 second intervalls. That old one rises/lowers current 1A/every measurement, so it Takes 100 secondsfrom 16A to 6A.
Now i have modified it so, that it sets current in one step.

This is to be modified for each own needs

sensor.p1_meter_current_phase_1 = L1 Current in amps (A)
sensor.p1_meter_current_phase_1 = L2 Current in amps (A)
sensor.p1_meter_current_phase_1 = L3 Current in amps (A)
min_charge_current = minimum current charger allows (A)
max_charge_current = maximum current charger allows (A)
max_total_current = breaker size. This is max target total current for L1-L3 (A)
number.go_echarger_xxxxxx_amp = charger current setting entity (A)

alias: "!Uusi kuromanhallinta"
description: Control EV charger amps to avoid overcurrent
triggers:
  - entity_id:
      - sensor.p1_meter_current_phase_1
      - sensor.p1_meter_current_phase_2
      - sensor.p1_meter_current_phase_3
    trigger: state
conditions:
  - condition: state
    entity_id: sensor.go_echarger_XXXXXX_car
    state: Charging
    enabled: true
actions:
  - data:
      value: >
        {% set min_charge_current = 6 %}
        {% set max_charge_current = 16 %}
        {% set max_total_current = 25 %}

        {% set c1 = states('sensor.p1_meter_current_phase_1')|float %}
        {% set c2 = states('sensor.p1_meter_current_phase_2')|float %}
        {% set c3 = states('sensor.p1_meter_current_phase_3')|float %}
        {% set measured_current = [c1, c2, c3] | select('is_number') | map('float') | max | default(none) %}

        {% set current_charger_setting = states('number.go_echarger_XXXXXX_amp')|float %}

        {% set new_current = max_total_current - measured_current + current_charger_setting %}
        {% if new_current > max_charge_current %}
          {% set new_current = max_charge_current %}
        {% endif %}
        {% if new_current < min_charge_current %}
          {% set new_current = min_charge_current %}
        {% endif %}

        {{ new_current|round(0, 'floor') }}
    target:
      entity_id: number.go_echarger_XXXXXX_amp
    action: number.set_value
mode: single
max: 3

Edit. automation edited a bit.

3 Likes

I get the error message

Message malformed: extra keys not allowed @ data[‘trigger’]

when I try.
do you have any suggestions for a fix?

I edited code in previous post. Does it now work?