Alfen Eve Pro EV chargepoint interface via TCP modbus

Hi all,

based on this topic I got the balancing working.
Got 2 questions:

  1. 3 phase loading at 6A is 4100 W, but if I single phase load i’m not pushing back solar on 2 phases and using the net on 1 phase.

I’d like to put load balancing per phase, having different Ampere per phase.
I see modbus adresses per phase, but I’m not sure if this is possible / good for the car or not:
example:

  • Phase 1: 6A
  • Phase 2: 9A
  • Phase 3: 5A (not used as below 6A)
  1. I have an alfen station with removable cable, but i mostly leave it plug in. To start a new sessions, the alfen pole required the cable to be removed from the pole, as it’s in status “B1”. Through backoffice you can do a soft status reset, does anyone know if/how we can do a CS reboot (or status reset) through either Modbus or Homeassistant?

Thanks, and great topic!

Yes, you can create a sensor via modbus to READ the current phases.
This part in the code below creates the sensor sensor.charger_use_1_or_3_phases

      - name: charger_use_1_or_3_phases
        slave: 1
        address: 1215
        data_type: uint16

full code

modbus:
  - name: car_charger
    type: tcp
    host: 192.168.1.2
    port: 502
    sensors:
      - name: charger_use_1_or_3_phases
        slave: 1
        address: 1215
        data_type: uint16
      - name: car_charger_name
        unique_id: 'd7494313-3ce8-4871-9c8b-546fa826d45f'
        slave: 200
        address: 100
        count: 17
        data_type: string
      - name: charger_temperature
        slave: 200
        address: 1102
        data_type: float32
        unit_of_measurement: °C
      - name: charger_active_max_current
        slave: 200
        address: 1100
        data_type: float32
        unit_of_measurement: A
      - name: charger_real_power
        unique_id: '5d2cee9c-2485-4af4-a9a2-a901321924c0'
        slave: 1
        address: 344
        data_type: float32
        unit_of_measurement: W
      - name: charger_mode3_state
        slave: 1
        address: 1201
        count: 5
        data_type: string
        scan_interval: 5
      - name: charger_actual_applied_maxcurrent
        slave: 1
        address: 1206
        data_type: float32
        unit_of_measurement: A
      - name: charger_modbus_maxcurrent
        slave: 1
        address: 1210
        data_type: float32
        unit_of_measurement: A
      - name: charger_socket1_current_valid_time
        slave: 1
        address: 1208
        data_type: uint32
        unit_of_measurement: s
      - name: charger_energy_delivered
        slave: 1
        address: 374
        count: 4
        data_type: float64
        unit_of_measurement: Wh
        device_class: energy
        state_class: total_increasing
1 Like

Do you have any info on how the P1 load balancing works?
In general, it will of course charge the car with the “excess/injection”, but how does it react in the following situations?

  1. Not enough injection continuously
    The minimum required charge for my car is 1300 W. In winter, when I do not have a continuous minimum of 1300 W injection, it would nearly never start charging my car or continuously start/stop. Therefore, I created a script that always charges at min. 1300 W and it increases when (occasionally) I have some more injection. But, it will never stop charging, only when the target SOC is reached.
    I call this the “start now mode” (min. 1300 W + solar excess)

  2. Enough injection
    When I have enough injection (1300 W) during 5 minutes, I start charging the car. The 5 minutes is to avoid that it starts charging just the first moment that it reaches this 1300 W (maybe followed by a drop). Then, every minute, I check if there is still enough injection. If not enough injection, it will stop charging the car. If there is more injection than before, it even increases the power of the car charger.
    To avoid that it stops when it does not have 1300 W, I added a “buffer” of 300 W, meaning that it will not stop charging if there is only 1000 W injection; it can consume max. 300 W from the grid. The reasoning is that it is economically more interesting to put your own solar energy in your car (1000 W) than to sell this 1000 W to the grid for only a few €. The cost of (temporarily) using 300 W from the grid is just a small cost that allows you to continue to charge the car with solar. In addition, this makes that the car does not stop charging that often. It only stop charging when there is less than 1000 W injection. Of course, you can change the buffer to your preferences.
    I call this the “solar charging mode” (sun + max. 300 W grid consumption)

As you see, when you manage the power of your car charger by yourself instead of the P1, you can manage all the situations to your own preference.

I really wonder how the Alphen reacts to the P1 active load balancing.

Hi Bart,

Thank you very much for sharing the code for the sensor reading out the current phases!

I’m looking to create an automation doing the same as your point 2: Start charging at 1300W and increase if needed and decrease when needed.

Would you mind sharing how you have it set up so I have a starting point to build on?

Much appreciated!

This is part of the solution. I won’t post the complete configuration in this thread, because this topic is about the Alfen charger and TCP modbus. There are other threads on charging on solar excess power.

These are 2 automations. The first to start the “sun only charging”.
The second to adjust every minute when the sun only charging is busy.
The scripts define the wattage for the car charger and then send it via scripts to the charger.
I also send a notification to my phone when it starts and stops charging. It helps me to debug also.
I can probably simplify the automations (eg. leave some conditions out).

I also use quite a lot of helpers:
input_number.car_charge_sun_start_wattage: the -1300 W required to start charging the car
input_boolean.car_charge_mode_sun: toggle to choose the sun only mode
input_boolean.car_charge_sun_busy: toggle to keep track if the sun charging mode is on or not

and some sensors:
sensor.net_power: gives the grid consumption or injection in Watt
sensor.charger_real_power: the current wattage of the car charger

- alias: "🚗 car 1 // 🔋 charge // mode sun // start - als er voldoende injectie is"
  id: 'fff013ea-12e1-427f-8283-617a0f2e94ad'
  description: ''
  # start when the wattmater is below the number defined in input_number.car_charge_sun_start_wattage
  trigger:
  - platform: time_pattern
    minutes: /1
  - platform: numeric_state
    entity_id: sensor.net_power
    below: input_number.car_charge_sun_start_wattage
    for: "00:05:00"
  condition:
  - condition: numeric_state
    entity_id: sensor.net_power
    below: input_number.car_charge_sun_start_wattage
  - condition: or
    conditions:
    - condition: state
      entity_id: sensor.charger_status
      state: 'connected'            
    - condition: state
      entity_id: sensor.charger_status
      state: 'charging'
  - condition: state
    entity_id: input_boolean.car_charge_mode_sun
    state: 'on'
  - condition: state
    entity_id: input_boolean.car_charge_sun_busy
    state: 'off'
  action:
  # toggle the switches to keep track of the status
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id:
        - input_boolean.car_charge_sun_busy
        - input_boolean.car_charge_busy
  # define charger Watt based on injection
  - service: input_number.set_value
    target:
      entity_id: input_number.car_charger_watt
    data:
      value: >-
          {% set charger = states('sensor.charger_real_power') | float(default=0) / 1000 %}        
          {% set maxpower = states('input_number.car_charge_minimum_wattage') | float(default=0) %}
          {% set net = states('sensor.net_power') | float(default=0) %}
          {% if net + charger < maxpower %}
          {{ [(-net + charger) / 1000, maxpower] | max }}
          {% elif net + charger > maxpower %}
          {{ maxpower }}
          {% endif %}
  - wait_template: ''
    timeout: '00:00:05'
  - service: script.charger_define_phase_1_or_3_based_on_watt
  - service: script.charger_define_ampere_based_on_watt     
  - service: script.charger_define_and_write_register_based_on_ampere
  - service: notify.bart_phone
    data:
      title: Auto is gestart met laden op zonne-energie
      message: >
        Zon nu {{ states('sensor.solar_power')}} W | Net: {{ states('sensor.net_power')}} W | Auto laadt nu aan {{states('input_number.car_charger_watt') | round(1)}} kW<br>
        Auto: {{states('sensor.car_1_soc') | round()}}%. Doel: {{ states('input_number.car_charge_target_percentage') | round(0)}}%
      data:
        tag: car_charging_sun
        color: green
        notification_icon: "mdi:car-electric"
        actions:
        - action: URI
          title: meer info
          uri: /dashboard-car/car-charging
  mode: single   

- alias: "🚗 car 1 // 🔋 charge // mode sun //  bezig - check elke minuut tijdens zonneladen"
  id: '258101bc-919c-4944-96e4-bb290cbe8922'
  trigger:
  - platform: time_pattern
    minutes: /1    
  condition:
  - condition: state
    entity_id: input_boolean.car_charge_mode_sun
    state: 'on'  
  # only if charger cable is connected to home charger or already charging
  - condition: or
    conditions:    
    - condition: state
      entity_id: sensor.charger_status
      state: 'connected'            
    - condition: state
      entity_id: sensor.charger_status
      state: 'charging'
  # only when sun is up
  - condition: state
    entity_id: sun.sun
    state: above_horizon
  # only if charging is busy in sun mode 
  - condition: state
    entity_id: input_boolean.car_charge_sun_busy
    state: 'on'
  action:
    - if:
        - condition: template
          value_template: "{{ wattage > 1300 }}"
      then:
        - service: input_number.set_value
          target:
            entity_id: input_number.car_charger_watt
          data:
            value: >-
              {% set charger = states('sensor.charger_real_power') | float(default=0) / 1000 %}        
              {% set net = states('sensor.net_power') | float(default=0) %}
              {{ wattage / 1000 }}
        - wait_template: ''
          timeout: '00:00:05'
        - service: script.charger_define_phase_1_or_3_based_on_watt
        - service: script.charger_define_ampere_based_on_watt
        - service: script.charger_define_and_write_register_based_on_ampere
      else:
        - service: script.stop_charger
          data: {}
        # wait 5 minutes to avoid too frequent start/stop = result in charging faillure
        - service: notify.bart_phone
          data:
            title: Zonneladen gestopt
            message: >
              Zon: {{ states('sensor.solar_power')}} W | Net: {{ states('sensor.net_power')}} W | Auto: {{states('input_number.car_charger_watt') | round(1)}} kW<br>
              Nu: {{states('sensor.car_1_soc') | round()}}%.        
        - wait_template: ''
          timeout: '00:05:00'          
  variables:
      wattage: >
        {% set charger = states('sensor.charger_real_power') | float(default=0) %}        
        {% set maxpower = states('input_number.car_charge_sun_max_netwattage') | float(default=0) %}
        {% set net = states('sensor.net_power') | float(default=0) %}
        {{ - (net - maxpower - charger) }}
  mode: single
2 Likes

Hi, just bumped into your message, I have the exact same issue. Have you been able to solve this issue?

Hi Tnx for the modbus read codes…
I would like to read the total charged by charger into HA
I believe it would be this code added to the configuration.yaml
But I get a NaN on the sensor… al the rest is working fine.
Anyone know’s what the problem is
(I would also like to convert it to kWh so a “scale: 0.001” would also be added, but I would like to have it working)

- name: laadpaal_total_charged
  slave: 1
  address: 390
  count: 4
  data_type: float64
  unit_of_measurement: Wh

Hey Wim,

just do:

      - name: laadpaal_energy_delivered_sum_1
         slave: 1
         address: 374
         count: 4
         data_type: float64
         unit_of_measurement: Wh
         device_class: energy
         state_class: total_increasing

With the additional parameters you can also add the reading to your energy dashboard.

Best regards,
Lieven

Tnx Lieven,

That worked like a charm :slight_smile:

Is the alfen HA integration still maintained. The code does not allow to add a charger anymore. Always reults in an error (see earlier post). The github repo does not allow to post issues.

Hi Lieven,

When I add this to my configuration.yaml I get the error that this entity had no unique ID. I have solved this by setting unique_id manually but still I’m not seeing any data on the energy dashboard. Even when I switch from day to week or month. When I add laadpaal_energy_delivered_sum_1 to an entity card on my dashboard it show a good value. Any ideas?

Hey @rtdegraaf

hmm not really to be honest. I have pasted my complete configuration for the chargepoint in the first post of this thread. Maybe there is something missing in your configuration, can you compare yours to what I posted?

Best regards,
Lieven

Hi stefaan…
I installed it last week, but I went back to modbus read and I disabled the integration.
I have troubles with my EMS and the modbusread so I went back to this integration.

I could not add a new charger, but then I realised that the previous integration was disabled.
So I enabled it and the integration works fine.

Altough te reboot problem still exists.

grts

Hi Lieven,

Thanks for your reply. I have not changed anything but it is working since a few days. Maybe it needed some time or a reboot, I really don’t know :sweat_smile:

Kind regards,

Ronald

1 Like

Hi,
Last couple of days, I’ve been trying to get this to work for my own Alfen Single Eve Pro charger.

I imported the flow made by Luuk and adjusted it for my just 1 phase installation.
At the end of the flow, there the Node to set the values to write to the Modbus:
msg.payload = {
value: msg.payload,
‘fc’: 16,
‘unitid’: 1,
‘address’: 1210,
‘quantity’: 2
}
return msg

When I try this in a simple flow to test the Modbus to the Alfen, I keep getting the following error:
“Error: Quantity should be less or equal to register payload array length: 32 Addr: 1210 Q: 2”

Any idea what and why this is wrong for my Alfen?

Thanks

Hey @RuyteRo,

According to the information I find here the information you pass to ‘value’ should be an array of 2 16-bit values.

Can you add a debug node to your flow that prints msg.payload to verify that you are actually feeding an array to the value field?

Regards,
Lieven

Hi Lieven,

Thanks for the reply.
Seemed that I copied too little of Luuk’s code.
I now don’t have an error anymore, but the payload still is not complete, since I don’t see any current values changing on the Alfen charger.

A debug gives this:

{
“payload”: {
“address”: 1210,
“length”: 2
},
“topic”: “button.nodered_24228d7c73b632b3”,
“data”: {
“entity_id”: “button.nodered_24228d7c73b632b3”,
“state”: “2023-04-28T20:50:39.179097+00:00”,
“attributes”: {
“friendly_name”: “TestButton”
},
“last_changed”: “2023-04-28T20:50:39.179139+00:00”,
“last_updated”: “2023-04-28T20:50:39.179139+00:00”,
“context”: {
“id”: “01GZ4T3NEATM0GT9986Y1FQRBQ”,
“parent_id”: null,
“user_id”: “7ef34882131b4c8c935779d2192fa262”
}
},
“_msgid”: “816342591dd2c67a”,
“messageId”: “644c319fe1096ae715b3c5e0”,
“input”: {
“topic”: “button.nodered_24228d7c73b632b3”,
“messageId”: “644c319fe1096ae715b3c5e0”,
“payload”: {
“value”: [
16720,
0
],
“unitid”: 1,
“fc”: 16,
“address”: 1210,
“quantity”: 2,
“messageId”: “644c319fe1096ae715b3c5e0”
},
“queueLengthByUnitId”: {
“unitId”: 1,
“queueLength”: 0
},
“queueUnitId”: 1,
“unitId”: 1
},
“values”: {
“value”: [
16720,
0
],
“unitid”: 1,
“fc”: 16,
“address”: 1210,
“quantity”: 2,
“messageId”: “644c319fe1096ae715b3c5e0”
}
}

I’m not yet really understanding how to get this payload correct to set the charging current on the charger.

Any tips are welkom

Regards

It actually was working, without me noticing it :sweat_smile:

Hi Pascal,

Did you get this working (loadbalance over P1) and reading data over modbus at the same time?

Regards,

Scalli

Could not find the answer to my question in this thread:

I have set my Alfen to Energy Management System as datasource, I can succesfully read values from the charger in HA with modbus.

I want the charger to do the Active Loadbalancing. For this the charger needs P1 data. Since you cannot have EMS and P1 active, the charger needs to get this information from the EMS (HA > Modbus).

Question: what DSMR parameters does the charger need and how do I send them over Modbus ?