Here some additional useful stuff.
I have created some automations and scripts to set the Alfen charger to 1 or 3 phases and to different Ampere by selecting the Watt via a simple slider in a dashboard.
First, create 2 helpers:
input_number.car_charger_watt with values from 1 to 10 (this is in kW)
input_number.car_charger_ampere with values from 6 to 14 (below 6 A, the car will not charge, at more than 14 A my electricity circuit shuts off)
In your dashboard add the slider of the entity input_number.car_charger_watt
Now, based on the W you select, we need to define the A.
- alias: Watt has changed to < 4 -> select 1 phase
id: 'f27a3c48-775c-471f-bd6d-33d23c638826'
description: ''
trigger:
- platform: state
entity_id: input_number.car_charger_watt
condition: []
action:
- condition: numeric_state
entity_id: input_number.car_charger_watt
below: 4
- service: script.set_charger_to_1_phase
data: {}
mode: single
- alias: Watt has changed to > 4 -> select 3 phases
id: '71d739ea-2973-4bfc-be0f-680846cd8e77'
description: ''
trigger:
- platform: state
entity_id: input_number.car_charger_watt
condition: []
action:
- condition: numeric_state
entity_id: input_number.car_charger_watt
above: 4
- service: script.set_charger_to_3_phases
data: {}
mode: single
The scripts that are called are:
set_charger_to_1_phase:
alias: "laadpaal - zet op 1 fase"
sequence:
- service: modbus.write_register
data:
address: 1215
unit: 1
hub: laadpaal
value: 1
set_charger_to_3_phases:
alias: "laadpaal - zet op 3 fases"
sequence:
- service: modbus.write_register
data:
address: 1215
unit: 1
hub: laadpaal
value: 3
Next step, we need to define the A based on the W we want to charge.
The following automation runs when the A is changed via the slider in the dashboard.
- alias: Wattage has changed = define Ampère
id: 'fefe7ddf-8730-4d3e-af5c-0e6b18b9ede5'
description: ''
trigger:
- platform: state
entity_id: input_number.car_charger_watt
condition: []
action:
- service: input_number.set_value
target:
entity_id: input_number.car_charger_ampere
data:
value: >-
{% set W = states('input_number.car_charger_watt') | float %}
{% if 0.9 < W < 1.4 %} 6
{% elif 1.4 < W < 1.7 %} 7
{% elif 1.7 < W < 1.9 %} 8
{% elif 1.9 < W < 2.1 %} 9
{% elif 2.1 < W < 2.3 %} 10
{% elif 2.3 < W < 2.5 %} 11
{% elif 2.5 < W < 2.7 %} 12
{% elif 2.7 < W < 2.9 %} 13
{% elif 2.9 < W < 4.7 %} 6
{% elif 4.7 < W < 5.4 %} 7
{% elif 5.4 < W < 6.1 %} 8
{% elif 6.1 < W < 6.8 %} 9
{% elif 6.8 < W < 7.5 %} 10
{% elif 7.5 < W < 8.4 %} 11
{% elif 8.4 < W < 9.1 %} 12
{% elif 9.1 < W < 9.8 %} 13
{% endif %}
mode: single
Now, we have defined the Ampere, but you cannot send that number to the charger like this. It needs to be converted. That is what the next automation does.
- alias: Ampere has changed = define the value to send to the register
id: '9550cbe2-2979-4c7f-9974-ec7eaebc249e'
description: ''
trigger:
- platform: state
entity_id: input_number.car_charger_ampere
condition: []
action:
- service: script.send_ampere_to_charger
data:
registervalue: '{{registervalue}}'
variables:
registervalue: >-
{% set A = states('input_number.car_charger_ampere') | float %}
{% if A == 6 %}[0x40c0, 0x0000]
{% elif A == 7 %}[0x40e0, 0x0000]
{% elif A == 8 %}[0x4100, 0x0000]
{% elif A == 9 %}[0x4110, 0x0000]
{% elif A == 10 %}[0x4120, 0x0000]
{% elif A == 11 %}[0x4130, 0x0000]
{% elif A == 12 %}[0x4140, 0x0000]
{% elif A == 13 %}[0x4160, 0x0000]
{% endif %}
mode: single
Now that the Ampere is formatted in the value that the charger understands, we need to send the value to the charger via the following script.
send_ampere_to_charger:
alias: "laadpaal - send Ampère to charger register"
sequence:
- service: modbus.write_register
data:
address: 1210
unit: 1
hub: laadpaal
value: "{{ registervalue }}"
Notes:
- Carefully read above which code is for automations and which for scripts.
- With these automations and scripts, you do not need the Perl script that Lieven mentioned earlier.
- Because these automations and scripts are triggered by a change in the requested Watt, it will be easy (I hope) to implement an automation to charge with solar power only. Eg. measure how much kW is sent back to the grid and use this amount (or a bit less) to define the Watt for your car charger.
Hope this helps.