Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save peyanski/b0d3f750b67b6be444fe73037a26708d to your computer and use it in GitHub Desktop.
Save peyanski/b0d3f750b67b6be444fe73037a26708d to your computer and use it in GitHub Desktop.
Adjust EV charger current based on PV & Battery SoC, with dashboard controls
alias: Smart EV Charging - Adaptive with Controls
description: Adjust EV charger current based on PV & Battery SoC, with dashboard controls
trigger:
- platform: time_pattern
minutes: "/3" # every 3 minutes
condition:
- condition: state
entity_id: input_boolean.enable_smart_ev_charging
state: "on"
action:
- variables:
pv_power_kw: "{{ states('sensor.deye_pv_power') | float(0) }}"
load_power_kw: "{{ states('sensor.deye_load_power_x_10') | float(0) }}"
battery_soc: "{{ states('sensor.deye_battery') | float(0) }}"
current_amps: "{{ states('number.ev_charger_set_charge_current') | float(6) }}"
soc_threshold: "{{ states('input_number.minimum_battery_soc_for_ev_charging') | float(80) }}"
available_kw: "{{ pv_power_kw - load_power_kw }}"
delta_amps: 2
max_amps: 32
min_amps: 6
new_amps: >
{% if battery_soc > soc_threshold %}
{% if available_kw > 0.5 %}
{{ [current_amps + delta_amps, max_amps] | min }}
{% elif available_kw < -0.5 %}
{{ [current_amps - delta_amps, min_amps] | max }}
{% else %}
{{ current_amps }}
{% endif %}
{% else %}
{{ min_amps }}
{% endif %}
- service: number.set_value
target:
entity_id: number.ev_charger_set_charge_current
data:
value: "{{ new_amps }}"
mode: single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment