EV Charger control with Modbus TCP

Good to know there is a possibility to control Wallbe using HA. Nice work!
I am still not sure what to get: Go-eCharger Home+ or Wallbe. Where Go-e has an official API and 22kW but Wallbe looks better, is cheaper and would be sufficient, since I would put all the logic anyway to HA automations.

Can you set the current to whatever you want (except 0) or are there standards / levels to be aware of?
(I saw youā€™re using Reg 528 to set the current. Are the possible values there e.g. 10,20,30,40ā€¦?)

I have a 20.5kWp PV installation and want to charge the car mainly using solar-energy. So, with some hysteresis, HA could set the charging current always a bit lower than the current unused solar-energy current is.

I found also this project to control wallbe: https://github.com/andig/evcc/

1 Like

Hi @andreas.w ,

The charging cable communication defines the maximum current the car can take. Minimum value there is 6A. It really is Amps, so 11kW with three phases is the same as single phase 3.6kw (both being 16A@230V).

Wallbe supports any discrete values up from 6A.

That evcc is a great finding!

Hi all,

wanted to quickly mention that Iā€™ve developed https://github.com/andig/evcc as a comprehensive EV charge controller software. Iā€™d like to add hassio integration (https://github.com/andig/evcc/issues/235) but could use some community help. Please join us on Github if interested.

Kind regards,
Andi

2 Likes

Hi @jruoho,

thanks for your work!
I have set up a pv ev charging algorithm (similar to evcc) in homeassistant with automations with the help of your documentation! (I am still testing and plan to show it laterā€¦)
But I donā€™t like the idea of forcing my wallbe into an error state to disable charging. Is there another way of switching the charging off maybe via the ā€œChargerEnableā€ address?

Thanks
Sebastian

Hi Sebastian (@S3b4st1an),

Check the link from @andig - there are instructions what dip to change to require separate enable. I am using it also nowadays, with the addition of physical enable button. Separate enable helps with wife acceptance factor, when there is an easy work around for the case when computers fail :slight_smile:

I can add now that evcc meanwhile also has an api, both rest and mqtt that should ease integration with hassio and others.

Cheers,
Andi

1 Like

I have seen the mentioned dip switch (10).
So if I understand correctly a script with:

- service: modbus.write_register
      data_template:
        hub: wallbe
        unit: 255
        address: 413
        value: 1

will start charging and:

- service: modbus.write_register
      data_template:
        hub: wallbe
        unit: 255
        address: 413
        value: 0

will stop charging if the dip switch ist set to ā€œonā€?

Other question: Can you tell me more about the physical switch you are using?

Hi @S3b4st1an,

If you have changed the dip, then the address 400 should be enough. ā€œonā€ (1) to enable charging and ā€œoffā€ (0). Additionally you only need to set the address 528 to correct value (range 60ā€¦160).

The reset (413) I use only if nothing works :slight_smile:

1 Like

Hi @miki_lbc,

Thanks for sharing :slight_smile:
I guess itā€™s good to have links in both direction: https://community.home-assistant.io/t/phoenix-contact-ev-charger-with-modbus-tcp-2902802

Next step would be a proper integration :slight_smile:

1 Like

Hi, bringing up this topic again. Today I also got my wallbe ECO 2.0 installed. Itā€™s fully operational and also the web interface is available on http://192.168.0.8 (incl. access with the ā€œsecretā€ password, but Iā€™m not going to make use of that). I thought I could easily add the basic sensors as a first step, so I added the config from the first post of this thread:

modbus:
  - name: wallbe
    type: tcp
    host: 192.168.0.8
    port: 502

together with

sensor: !include sensor.yaml

and the sull sensor.yaml, also from the first post. Unfortunately, no entities or sensors are shows, but config is accepted. Did the syntax change in the meantime or is anything else missing for a simple start without switches - just sensors? Even if the wallbox is not accessible or parameters are wrong, I had guessed that I get the sensors (with wrong data or errors), but I just get nothing.

Thanks,
Tobias

Hi Tobse,
the syntax has indeed changed at some point.

Here is a piece of my current, working, config:

- name: wallbe
  type: tcp
  host: 192.168.0.8
  port: 502
  switches:
    - name: ChargerOvercurrentDisable
      slave: 255
      write_type: coil
      address: 409
    - name: ChargerEnable
      slave: 255
      write_type: coil
      address: 400
    - name: ChargerReset
      slave: 255
      write_type: coil
      address: 413
  sensors:
    - name: ChargeCurrent
      slave: 255
      address: 528
      input_type: holding
      scale: 0.1
      data_type: int16
      unit_of_measurement: A
    - name: EVState_raw
      slave: 255
      address: 100
      input_type: input
      data_type: string
      count: 1
    - name: EVErrorCodeHex
      slave: 255
      address: 107
      input_type: input
      data_type: int16

Thanks, after a lot of playing around last night, I also got it running - at least the sensors:

# wallbox
modbus:
  - name: wallbe
    type: tcp
    host: 192.168.0.8
    port: 502
    sensors:
    - name: Lade-Zeit
      unit_of_measurement: h
      slave: 255
      address: 102
      precision: 1
      scale: 0.000277777777
    - name: Lade-Strom
      slave: 255
      address: 528
      scale: 0.1
      unit_of_measurement: A
      device_class: current
    - name: Lade-Status
      slave: 255
      address: 100
      device_class: battery

but the switches from your syntax are something I might take over, as well as the additional error code sensor ;-).

In addition to the basic sensors, I created one for the status, assigning texts and icons to the states (info taken from the Phoenix documentation), so I have a more beautiful display on Lovelace. Unfortunately itā€™s in German, but might also give others an idea how do to such ā€œmappingsā€:

template:
  - sensor:
      - name: "Wallbox Status"
        state: >
          {% if is_state('sensor.lade_status', '65') %}
            kein Fahrzeug
          {% elif is_state('sensor.lade_status', '66') %}
            Fahrzeug lƤdt nicht
          {% elif is_state('sensor.lade_status', '67') %}
            Fahrzeug lƤdt
          {% elif is_state('sensor.lade_status', '68') %}
            Fahrzeug lƤdt
          {% elif is_state('sensor.lade_status', '69') %}
            Fehler, nicht bereit
          {% elif is_state('sensor.lade_status', '70') %}
            Laden nicht verfĆ¼gbar
          {% else %}
            Unbekannt
          {% endif %}
        icon: >
          {% if is_state('sensor.lade_status', '65') %}
            mdi:power-plug-off
          {% elif is_state('sensor.lade_status', '66') %}
            mdi:car-outline
          {% elif is_state('sensor.lade_status', '67') %}
            mdi:battery-charging
          {% elif is_state('sensor.lade_status', '68') %}
            mdi:battery-charging
          {% elif is_state('sensor.lade_status', '69') %}
            mdi:battery-alert
          {% elif is_state('sensor.lade_status', '70') %}
            mdi:battery-alert
          {% else %}
            mdi:battery-unknown
          {% endif %}

Note that I read the register as int16 (default), so I have to switch by ASCII codes, not the actual string representation Aā€¦F. That allows displaying something like the following:

image

Hi Tobse,
I will also use Wallbe Eco 2.0s in my Home assist. I have add you code, but I only get Lade-Strom and not the other things. Have you got an idea?

Hm, not really :-(. But in the meantime, my configuration slightly changed. Maybe the one I posted earlier had some issues - donā€™t remember. This is my current sensor configuration for the wallbe:

# wallbox
modbus:
  - name: wallbe
    type: tcp
    host: 192.168.0.8
    port: 502
    sensors:
    - name: wallbe Lade-Zeit S
      unique_id: wallbe_lade_zeit_s
      unit_of_measurement: s
      slave: 255
      address: 102
      input_type: input
    - name: wallbe eingestellter Lade-Strom # read
      unique_id: wallbe_eingestellter_lade_strom
      slave: 255
      address: 300
      input_type: holding
      scale: 0.1
      unit_of_measurement: A
      device_class: current
    - name: wallbe Vorgabe Lade-Strom # read/write
      unique_id: wallbe_vorgabe_lade_strom
      slave: 255
      address: 528
      input_type: holding
      scale: 0.1
      unit_of_measurement: A
      device_class: current
    - name: wallbe Status Raw
      unique_id: wallbe_status_raw
      slave: 255
      address: 100
      input_type: input
      device_class: battery
    - name: wallbe Lade-FehlerCode Hex
      unique_id: wallbe_lade_fehlercode_hex
      slave: 255
      address: 107
      input_type: input
      data_type: int16

And BTW, in addition to and based on this configuration, I was also finally able to implement some buttons on my Dashboard:

image

Hereā€™s the yaml:

type: horizontal-stack
title: Lade-Leistung setzen
cards:
  - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: call-service
      service: modbus.write_register
      data:
        address: 528
        slave: 255
        value: 0
        hub: wallbe
      target: {}
    icon: mdi:gauge-empty
    name: Aus
  - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: call-service
      service: modbus.write_register
      data:
        address: 528
        slave: 255
        value: 60
        hub: wallbe
      target: {}
    name: 4kW
    icon: mdi:gauge-low
    show_state: false
  - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: call-service
      service: modbus.write_register
      data:
        address: 528
        slave: 255
        value: 120
        hub: wallbe
      target: {}
    name: 8kW
    icon: mdi:gauge
  - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: call-service
      service: modbus.write_register
      data:
        address: 528
        slave: 255
        value: 160
        hub: wallbe
      target: {}
    name: 11kW
    icon: mdi:gauge-full

Niceā€¦I will check it :slightly_smiling_face:

Can you set it for example on ā€œ4KWā€ when the car is connected? Is that not a problem for the car?

I donā€™t have an EV or electric car charger but Iā€™m interested in the combination with HA.
Is it after integration of Etrel Inch with Modbus TCP possible to limit charging power to balance your network. In Belgium you pay extra if your 15 minute month peak is higher than 2.5KW.
So Iā€™d like to consume own production by loading a car and/or limit power consumption of whole house below the highest peak of that month or below 2.5kW. I would like to add in HA some IFTTT like functions to do that; based on production info from Inverter PV, P1 port digital meter, ā€¦
So is this possible?
Iā€™m just starting in HA and can install ā€˜predefinedā€™ integrations; but no experience with writing code ā€¦

Hello, please I have problem with webasto chargeing and evcc, if I connect car, and dont have freeCharging enabled, it will not started charging, is there any way how to evcc or HA start charging with indetifier regarding vehicle?
Thank you in advance
Jozef

maybe will help you my automation used for this, I use shelly pro 3em:
and in configuration yaml I have this restfull:

set_evcc_max_current:
    url: "http://x.x.x.x:7070/api/loadpoints/{{ loadpoint_id }}/maxcurrent/{{ current }}"
    method: POST
    headers:
      Content-Type: application/json
    content_type: 'application/json'

automation yaml:

alias: Dynamic EV Charger Current Adjustment
description: Dynamically adjusts EV charger current based on individual phase currents
trigger:
  - platform: state
    entity_id:
      - sensor.michka_3em_phase_a_current
      - sensor.michka_3em_phase_b_current
      - sensor.michka_3em_phase_c_current
    for:
      seconds: 10
action:
  - choose:
      - conditions:
          - condition: template
            value_template: |-
              {{ states('sensor.michka_3em_phase_a_current') | float >= 30 or
                 states('sensor.michka_3em_phase_b_current') | float >= 30 or
                 states('sensor.michka_3em_phase_c_current') | float >= 30 }}
        sequence:
          - service: rest_command.set_evcc_max_current
            data:
              loadpoint_id: 1
              current: "6"
      - conditions:
          - condition: template
            value_template: |-
              {{ states('sensor.michka_3em_phase_a_current') | float < 30 and
                 states('sensor.michka_3em_phase_b_current') | float < 30 and
                 states('sensor.michka_3em_phase_c_current') | float < 30 }}
        sequence:
          - service: rest_command.set_evcc_max_current
            data:
              loadpoint_id: 1
              current: >
                {% set max_current_allowed = [16, (30 -
                states('sensor.michka_3em_phase_a_current') | float), 
                  (30 - states('sensor.michka_3em_phase_b_current') | float),
                  (30 - states('sensor.michka_3em_phase_c_current') | float)] | min %}
                {{ max_current_allowed | int }}
    default:
      - service: notify.mobile_app_iphone_4
        data:
          message: Current level adjusted dynamically based on phase currents.
mode: restart

very nice , how to you take solarpanels in account ?