Control the EV charging power with regard to the solar PV output and grid power reading

How to set the Controlling ocpp charging piles through solar photovoltaic power generation in the Home assistant

Abstract: Control the EV charger from OCPP ,charger the EV by the solar excess in the Home assistant.

This tutorial is the subsequent tutorial of Monitor your solar PV system in Home Assistant

Effect of this solution

sim5 Power_A:solar pv output
sim5 Power_B:grid power(positive:import energy from grid,negative:export energy to the grid)
sim3 Set power:EV charging power
charger Maximum Current:the maximum charge current set on the EV charger, the AC charger only accepts the current parameter(not power), so the final control parameter would be the current, not the power.

It shows the charging power always follows the solar PV output and the grid power is always nearly zero in the below pic.

It means nearly all of the PV output is utilized.

Premise

The sketch map of the system like below:

Please note, that this tutorial assumes both solar, grid, and charger are single-phase.
If your system is a three phase system, just need to make some little changes in the configuration in YAML.

WEM3080T is a three-phase energy meter of IAMMETER. It also supports split-phase usage.
We use Phase A to monitor the solar output, and phase B to monitor the grid exchange.

Before the main tutorial, there are two independent and more basic tutorials that are recommended to have a try.

tutorial 1: simulated a solar and load and integrate these data into Home Assistant

This is a basic and independent tutorial, which is recommended for trying before.
It will show you some basic operation like below

  1. simulated a solar PV output and a load profile in IAMMETER-simulation
  2. Use the IAMMETER`s HACS to read the data into the Home Assistant

For more details ,please refer to Integrate the simulated 3phase energy meter in Home assistant.

tutorial 2: Control the current of the EV charger by OCPP from the Home assistant

This is also a basic and independent tutorial, showing you how to communicate with the EV charger by OCPP in the home assistant and set the charging current.

Please refer to Control the Current of the EV charger(OCPP) from Home assistant

Monitor the solar and charge the EV from the solar excess

In fact, this chapter is the advanced version of the above two tutorials.

The main work is divided into the following steps:

  1. Integrate the reading of the solar inverter`s output power and grid power into the HA.
  2. Control the charging current of the EV charger from the HA.
  3. Control the charging current automatically with regard to the grid power in the Home Assistant.

Integrate the reading of solar power and grid power into the Home assistant

Considering the reader of this tutorial may not have the meter that can be installed on the grid and solar side, we use IAMMETER-simulator to prepare these data.

Simulated a solar pv output

simulated a load profile

After you complete the above two steps, you will get a simulated WEM3080T. It would be integrated into the home assistant easily like a real WEM3080T.
The data of phase A will be the simulated solar output you just configured in the simulator.
The data of phase B will be the simulated grid power (computed by the solar power and load power you had configured in the simulator).

Then you will be able to read both solar power and the grid power into the HA, as tutorial 1 described.

Control the charging current of the EV charger from the HA

If you already have an EV charger that can be connected to HA via OCPP, you can use it directly.
Otherwise, you can also use the IAMMETER-simulator to simulate an EV charger (OCPP client) attached to a specific battery capacity,as the tutorial 2 described.

Control the Current of the EV charger(OCPP) from Home assistant

Control the charging current automatically with regard to the grid power in the Home Assistant

This chapter is the core of this tutorial.

Because the AC EV charger only accepts the setting of current, not the power setting,we need to calculate the power first ,then convert the power to the corresponding current.

In fact, if you want to build an automatic control logic for the charging current,you need to answer this question.

when and how to increase/decrease the charging current.

We use a very simple control logic as the below diagram.

  • logic 1: When the grid power is less than threshold 1, it increases the charging current.
  • logic 2: When the grid power is greater than threshold 2, it decreases the charging current.

The negative grid power means there is an exporting energy to the grid. On the contrary, the positive power means it is importing energy from the grid. So if the grid power is a negative value, the less the value is, the more exporting power it means.

Please note, that all of the parameters in these two logic are open. You will choose the proper parameters regarding your own situation, or even you choose another control logic that does not need such parameters below.

Threshold 1: The threshold of the grid power that began to increase the charging current.

Threshold 2: The threshold of the grid power that began to decrease the charging current.

Step: The step value when the charging current increases.

For example:

  1. if you set the threshold 1 to zero. This means only the solar surplus power (solar output power- load power) can be used to charge the EV. It will increase the percentage of solar in the charging process, but will also bring a longer charging time(please note, most EV chargers limit the minimum charging power to 1.6kW, which is asked by the OCPP protocol).
  2. If threshold 1 is set to 1kW, it means except for the solar surplus power, the charger can also get some power from the grid. The maximum grid power that can be used for EV charging is 1kw. When the grid power is less than 1Kw, the HA will increase the charging current gradually(by the parameter of “step”).
  3. If threshold 2 is set to 2kw, it means when the grid power is greater than 2kW, the HA will decrease the current gradually.

If you use this control logic listed above, the threshold 2 must be higher than the threshold 1.

Add the intermediate parameter “charging power” in HA

This charging power is named “sim3 Set power” in HA.
It is an intermediate parameter, which is used to calculate the “charger Maximum Current” that would be set to the EV charger (via OCPP) finally.

Add input_number in “configuration.yaml”

click “File editor”

open “configuration.yaml”, add this code:

input_number:
  sim3_box1:
    name: sim3 Set Power
    #initial: 0
    min: 0
    max: 10000
    step: 1
    mode: box
    unit_of_measurement: W

image-20230717132437785

CHECK CONFIGURATION, RESTART

Logic 1: When the grid power is less than threshold 1, it increases the charging current

This tutorial set the threshold 1 as -300, the step value as 300.

Condition: grid power <-300 W

Operation: charing power =charging power +300

That means when the grid power is less than -300 w(the exporting power to grid is greater than 300w),the HA will increase the charging power 300W, the charing current(the charging current is the parameter that will be set to the EV charger finally) will also increase (300/220) A.( use the reference of the voltage as 220V,if your system is 110V, please change the value from 220 to 110V)

Please note, that all of the parameters are just an example in this tutorial. You can change the parameter accordingly in your usage. Or even change the condition and operation

ADD Triggers

ADD Actions

service: input_number.set_value
data:
  value: "{{ states('input_number.sim3_box1')|float + 300 }}"
target:
  entity_id: input_number.sim3_box1
service: number.set_value
data:
  value: "{{ (states('input_number.sim3_box1')|float/220)|round(1) }}"
target:
  entity_id: number.charger_maximum_current

Add an Delay for this trigger operation(optional)

logic 2: when and how to decrease the charging current

This tutorial set the threshold2 as 0 W.

Condition: grid power > 0 W

Operation: charing power = charging power - grid power

This means when the grid power is greater than 0 w, the HA will decrease the charging power , subtract the grid power from the charging power.

Please note, that all of the parameters are just an example in this tutorial. You can change the parameter accordingly in your usage. Or even change the condition and operation.

ADD Actions

service: input_number.set_value
data:
  value: "{{ states('input_number.sim3_box1')|float-states('sensor.sim5_power_b')|float }}"
target:
  entity_id: input_number.sim3_box1
service: number.set_value
data:
  value: "{{ (states('input_number.sim3_box1')|float/220)|round(1) }}"
target:
  entity_id: number.charger_maximum_current
enabled: true

Configure the Dashboard(optional)

Add the required entities to the dashboard

sim5 Power_A - SolarPV Power

sim5 Power_B - Grid power, positive(power consumption),negative(feed power)

sim3 Set Power/charger Maximum Current - OCPP charging power/current

why use simulator? how to upgrade to the real hardware?

We need to do such works in the home assistant.

  1. Read the solar PV output power.
  2. Read the grid power
  3. Control the EV charger current (The AC ev charger only accepts the setting of current, not the power)
  4. Build an automation in HA, and control the current of the charger based on the grid power.

Considering the reader of this tutorial may not have the meter that can be installed on the grid and solar side and report solar PV power and grid power to the home assistant, or do not have an EV charger that supports OCPP, we use the IAMMETER simulator to simulate the data and return it to the home assistant.

The IAMMETER-simulator can be used to simulate a load profile, solar output, and a battery that is connected to an EV charger and it does not need the complicated wiring work.
It also keeps the same API as the WEM3080T, it can be integrated into the HA as the same method.
So the IAMMETER-simulator can help you to evaluate the total solution before you pay the money.

If you think this solution is fit for your demands after the experiment with the simulator, you can purchase real hardware and only need to do such works below.

  1. install the real hardware in your system.
  2. Replace the IP in configuration from the simulator to the real hardware.

Control EV charger in IAMMETER

IAMMETER-cloud can also be used to control the EV charger now via OCPP.
If you have the IAMMETER`s energy meter installed on the grid side and also have an EV charger that supports OCPP.

You can have a try.

Connect EV charger to IAMMETER via OCPP

Reference

Monitor your solar PV system in Home Assistant

IAMMETER-Simulator: simulate solar pv, load profile, and has the same API as WEM3080T

Use IAMMETER`s energy meter in the home assistant

Interesting idea. What’s the minimum charge current you are able to set? I have found that the J1772 standard does not allow charging below 6A. So is that where you would set the threshold?