Skip to content

Instantly share code, notes, and snippets.

@AMajland
Last active July 10, 2024 20:02
Show Gist options
  • Save AMajland/6ffc6814df2a92e99cff2c901447efee to your computer and use it in GitHub Desktop.
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

Bjarke88 commented Sep 15, 2023

for a noob can you highlight what fields i should change to my own values?
and my energy meter only has one output for excess power can that work with this?

@Bjarke88
Copy link

Bjarke88 commented Sep 18, 2023

what value is expected here: input_select.ev_test_charge ?

what type of sensor is this: sensor.eheexpyg_status?

@AMajland
Copy link
Author

That is the helper i use to shift between charging according to the easee own schedule or 1 / 3 phase solar charging.

Se comment above from May 1

@Bjarke88
Copy link

That is the helper i use to shift between charging according to the easee own schedule or 1 / 3 phase solar charging.

Se comment above from May 1

ok thanks but what with this: sensor.eheexpyg_status ?

@AMajland
Copy link
Author

@Bjarke88 to create a helper variable go to settings, Helpers and create helper.

The EV Charge mode is a drowdown where you (or an automation) can select one of the possibilities.

The sensor.eheexpyg_status is the status of my primary charger that i use for solar charging . Just replace the seriel number parts with yours.. If you go to developer tools, states and search for "config_ledStripBrightness" under attributes you will probably only have one entity that matches

@Bjarke88
Copy link

Thanks

can you give a hint to how you create this part:
image

@AMajland
Copy link
Author

Settings, Devices and services, Helpers

and create helper

The type is a dropdown with the 3 options

@Bjarke88
Copy link

service: easee.set_circuit_dynamic_limit
data:
charger_id: CHARGERID
currentP1: >-
{% set current = ( ((states('sensor.askeengen_146_power') | float) ) /
(states('sensor.watts_live_11d1042220001670_voltage_l1') | float) ) + 1.4
%} {%if current > 16.0 %}{% set current = 16.0 %} {% endif %} {{ current
}}
currentP2: "0"
currentP3: "0"
time_to_live: "1"

what sensor is you expecting to be here: sensor.watts_live_11d1042220001670_voltage_l1

@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)

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