Skip to content

Instantly share code, notes, and snippets.

@AMajland
Last active April 19, 2025 06:11
Show Gist options
  • Select an option

  • Save AMajland/6ffc6814df2a92e99cff2c901447efee to your computer and use it in GitHub Desktop.

Select an option

Save AMajland/6ffc6814df2a92e99cff2c901447efee to your computer and use it in GitHub Desktop.
# Automations.yaml
alias: PV to EV Dynamic
trigger:
- platform: time_pattern
seconds: /20
condition: []
action:
- choose:
- conditions:
- condition: state
entity_id: input_select.ev_test_charge
state: Solar 3 Phase
sequence:
- service: easee.set_circuit_dynamic_limit
data:
charger_id: CHARGERID
currentP1: >-
{% set min_voltage =
min(states('sensor.ams_cf58_u1'),states('sensor.ams_cf58_u2'),states('sensor.ams_cf58_u3'))
%} {% set current = ( ((states('sensor.pv_to_ev_power') | float)
) / (min_voltage | float ) / 3.0 + 0.5) %} {%if current < 6.0
%}{% set current = 6.0 %} {% endif %} {{ current }}
currentP2: >-
{% set min_voltage =
min(states('sensor.ams_cf58_u1'),states('sensor.ams_cf58_u2'),states('sensor.ams_cf58_u3'))
%} {% set current = ( ((states('sensor.pv_to_ev_power') | float)
) / (min_voltage | float ) / 3.0 + 0.5) %} {%if current < 6.0
%}{% set current = 6.0 %} {% endif %} {{ current }}
currentP3: >-
{% set min_voltage =
min(states('sensor.ams_cf58_u1'),states('sensor.ams_cf58_u2'),states('sensor.ams_cf58_u3'))
%} {% set current = ( ((states('sensor.pv_to_ev_power') | float)
) / (min_voltage | float ) / 3.0 + 0.5) %} {%if current < 6.0
%}{% set current = 6.0 %} {% endif %} {{ current }}
time_to_live: "1"
- conditions:
- condition: state
entity_id: input_select.ev_test_charge
state: Solar 1 Phase
sequence:
- service: easee.set_circuit_dynamic_limit
data:
charger_id: CHARGERID
currentP1: >-
{% set current = ( ((states('sensor.pv_to_ev_power') | float) ) / (states('sensor.ams_cf58_u1') | float) ) + 1.4 %}
{%if current > 16.0 %}{% set current = 16.0 %}
{% endif %}
{{ current }}
currentP2: "0"
currentP3: "0"
time_to_live: "1"
mode: single
alias: PV to EV Phases
description: >-
Change 1 to 3 phases - check every 1 min. 10min min for 10min to change to 3.
Avererage below for 10min to go back
trigger:
- platform: time_pattern
minutes: /1
condition:
- condition: not
conditions:
- condition: template
value_template: "{{ states('sensor.CHARGERID_status') == 'disconnected' }}"
action:
- choose:
- conditions:
- condition: state
entity_id: input_select.ev_test_charge
state: Scheduled
sequence:
- service: easee.set_circuit_dynamic_limit
data:
charger_id: CHARGERID
currentP1: "32"
currentP2: "32"
currentP3: "32"
time_to_live: "15"
- conditions:
- condition: state
entity_id: input_select.ev_test_charge
state: Solar 1 Phase
for:
hours: 0
minutes: 10
seconds: 0
- condition: numeric_state
entity_id: sensor.pv_to_ev_power_10m_min
above: 3680
sequence:
- service: input_select.select_option
target:
entity_id: input_select.ev_test_charge
data:
option: Solar 3 Phase
- conditions:
- condition: state
entity_id: input_select.ev_test_charge
state: Solar 3 Phase
for:
hours: 0
minutes: 10
seconds: 0
- condition: numeric_state
entity_id: sensor.pv_to_ev_power_10_min_avg
below: 3680
sequence:
- service: input_select.select_option
target:
entity_id: input_select.ev_test_charge
data:
option: Solar 1 Phase
mode: single
#configuration.yaml
sensor:
- platform: statistics
name: PV to EV Power (10m min)
unique_id: sensor.pv_to_ev_power_10m_min
entity_id: sensor.pv_to_ev_power
state_characteristic: value_min
max_age:
minutes: 10
- platform: statistics
name: PV to EV Power (10 min avg)
unique_id: sensor.pv_to_ev_power_10m_avg
entity_id: sensor.pv_to_ev_power
state_characteristic: average_linear
max_age:
minutes: 10
- platform: statistics
name: PV to EV Power (2 min avg)
unique_id: sensor.pv_to_ev_power_2m_avg
entity_id: sensor.pv_to_ev_power
state_characteristic: average_linear
max_age:
minutes: 2
- platform: statistics
name: N1 Meter Power Netto (10 min avg)
unique_id: sensor.n1_meter_power_netto_avg
entity_id: sensor.n1_meter_power_netto
state_characteristic: average_linear
max_age:
minutes: 10
template:
- sensor:
- name: "PV to EV Power"
unique_id: sensor.pv_to_ev_power
unit_of_measurement: W
device_class: power
state: >
{% set surplus = (0.001 + ((states("sensor.CHARGERID_power") | float(0)) - (states("sensor.n1_meter_power_netto") | float(0))) | round(0) ) %}
{% if surplus < 0.0 %}{% set surplus = 0.0 %}
{% endif %}
{{ surplus }}
@Bjarke88
Copy link

what sensor is this: sensor.pv_to_ev_power

@AMajland
Copy link
Author

See above from line 150. That is just a helper to calculate available power.
It looks at currente charge rate and the export and a bit of rounding.
If you are charging with 6kW and exporting 4kW you have 10kW available for charging.

The reason i've done it that way is that it was easy to add statistics sensors that looks at 2 and 10 min averages as welle as minimum.

I use those to decide when its time to change between 1 and 3 phase charging. In the above i will first change to 3 fase when the minum surplus has been over 3680W for 10 minutes. The other way it will first drop down to 1 phase again when the average has been below 3680W for 10minutes.

So on a day with many clous the min drop often and it will stay on one phase charging..

On a good sunny day it will stay on 3 phase even troug i use a lot of power for a short while for i.e a cup of coffe (if its get below 6A it will pause for a while)

@AMajland
Copy link
Author

Ive had to change time to live to 0.

Don't know if it is a change in the HA integration og an easee api change, but it seems that if the values are not changed in HA it will not get trough and go back to default after the minute specified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment