Using entso-e and ev smart charging to optimise pv & home battery

Hello,

I have a dynamic energy contract, where electricity prices follow the hourly spot market. I also have a solar PV installation with home battery.
I noticed that on a normal, sunny day, my battery would be fully charged around noon at which point the PV would begin exporting to the grid. However, usually the prices are lowest at this hour, so this was not ideal. I wanted to delay the charge time of the battery so that I could export while prices are higher, and still make sure the battery would be charged completely at the end of the day.

I combined the entso-e plugin with the ev smart charging plugin to attempt to optimise the solar output. My PV installation consists of

The result is not perfect, but as it is quite simple to setup I thought I’d share it here. I see it as a poor man’s EMHASS, which despite seemingly good documentation I can’t seem to wrap my head around. :slight_smile:

I assume you have the integration with your PV installation and entso-e (or nordpool or …) already active.

  1. EV smart charge plugin base configuration

Three items are required for the base configuration.

  • The ev smart charging plugin will use the data from the entso-e plugin (the hourly prices of the electricity) to set the charge times for the battery.
  • For the battery SOC I configured the home battery SOC instead (provided by the huawei integration).
  • Finally the plugin requires a ‘switch’ entity that would toggle the EV charger ON or OFF. In my case, the switch will not start a charger, but will instead determine if the solar output is used to charge the battery (ON state), or if the output is exported to the grid (OFF state). For this I had to create a template sensor which I put in configuration.yaml:
switch:
  - platform: template
    switches:
      charger_optimal:
        friendly_name: "PV to battery"
        unique_id: Hjarta01
        value_template: "{{ is_state('select.battery_excess_pv_energy_use_in_tou', 'charge') }}"
        turn_on:
          service: select.select_option
          data:
            entity_id: select.battery_excess_pv_energy_use_in_tou
            option: charge
        turn_off:
          service: select.select_option
          data:
            entity_id: select.battery_excess_pv_energy_use_in_tou
            option: fed_to_grid

I provide the code here but of course this will depend on your PV integration!

My configuration of the smart charging plugin then looks like this:

  1. Determine charge speed
    An EV charger of course has a constant charge speed, which the plugin uses to determine the amount of time needed to charge the battery, and thus when to plan the charge times. This charge speed is a percentage per hour in the plugin, so a value of 50 would mean that the battery would be charged in 2 hours.
    For this I’m using an automation that will crudely base the charge speed on the total solar forecast for the day: (using Forecast.Solar)
alias: Estimate Charge Speed
description: Estimate home battery charge speed based on solar forecast
trigger:
  - platform: state
    entity_id:
      - sensor.energy_production_today
condition: []
action:
  - service: number.set_value
    data:
      value: >-
        {{ [[(trigger.to_state.state | float(0) - 1) * 2.5, 5] | max, 50] | min
        }}
    target:
      entity_id: number.ev_smart_charging_charging_speed
mode: single

I have a 5Ah battery, and the max speed it can charge at is 2.5Ah. The numbers are quite arbitrary, and I believe a much better calculation might be possible here.
The estimated kWh value from Forecast.Solar is reduced by 1 and then multiplied by 2.5. The value is clamped between 5 as a minimum value and 50 as a maximum value, as this is the max charge speed the battery can handle.

  1. Connect/Disconnect battery at sunrise/sunset
    Telling the EV charge plugin that the battery is disconnected on sunset and connected at sunrise seemed to help stabilize the plugin’s smart charging schedule. These are simple automations so you might as well copy them :slight_smile:
alias: Sunrise keep charger on
description: >-
  Keep charger on after charging to 100% to keep home battery topped up while
  the sun in shining
trigger:
  - platform: sun
    event: sunrise
    offset: 0
condition: []
action:
  - type: turn_on
    device_id: 22824c9444d09a51745e0b22d4fa3c14
    entity_id: switch.ev_smart_charging_keep_charger_on
    domain: switch
  - type: turn_on
    device_id: 22824c9444d09a51745e0b22d4fa3c14
    entity_id: switch.ev_smart_charging_ev_connected
    domain: switch
mode: single
alias: Sunset keep charger off
description: >-
  Reset keep charger on setting after sunset. This makes sure the smart charging
  is active for the next day
trigger:
  - platform: sun
    event: sunset
    offset: 0
condition: []
action:
  - type: turn_off
    device_id: 22824c9444d09a51745e0b22d4fa3c14
    entity_id: switch.ev_smart_charging_keep_charger_on
    domain: switch
  - type: turn_off
    device_id: 22824c9444d09a51745e0b22d4fa3c14
    entity_id: switch.ev_smart_charging_ev_connected
    domain: switch
mode: single
  1. Further tweaking of the plugin settings
    Finally you can try playing with the plugin settings, I’m quite happy with the following values:
    (sorry can’t show these yet as I’m only allowed one embedded image as new user, I’ll update it later)

There it is, hope some might find it interesting!