Etrel Inch Modbus TCP communication

Hi,

I’m integrating my Etrel Inch home charger similar to this post:

https://community.home-assistant.io/t/ev-charger-control-with-modbus-tcp/112784

It also supports Modbus TCP. An overview of its registers can be found here:

https://etrelchargingsolutions.atlassian.net/wiki/spaces/Home/pages/2236121092/Modbus+Communication+with+Inch+products

I can read out the read registers, but I’m having trouble to write to the registers. I want to be able to set the “Set Current Setpoint” or the “Set Power Setpoint”

Should I define the write registers as sensors?
Since the values are float32, I cannot set them as a switch.

# Etrel
modbus:
  - name: Etrel Inch
    type: tcp
    host: 10.0.0.209
    port: 502
    sensors:
    - name: Etrel_Power_set_point
      slave: 255
      address: 11
      write_type: holding

Similar as in the example, I’m trying to set the values using the modbus.write_register service, linked to a button.

type: horizontal-stack
title: Laadsnelheid instellen
cards:
  - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: call-service
      service: modbus.write_register
      data:
        address: 11
        slave: 255
        value: 0
        hub: Etrel Inch
      target: {}
    icon: mdi:gauge-empty
    name: Uit
  - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: call-service
      service: modbus.write_register
      data:
        address: 11
        slave: 255
        value: 4
        hub: Etrel Inch
      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: 11
        slave: 255
        value: 8
        hub: Etrel Inch
      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: 11
        slave: 255
        value: 11
        hub: Etrel Inch
      target: {}
    name: 11kW
    icon: mdi:gauge-full

But when doing so I get the following error:

Logger: homeassistant.components.websocket_api.http.connection
Source: components/modbus/modbus.py:176
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 14 maart 2023 om 12:47:05 (14 occurrences)
Last logged: 16:40:37

[139736414885664] 'Etrel Inch'
[139736643361552] 'Etrel Inch'
[139736228614288] 'Etrel Inch'
[139736393687600] 'Etrel Inch'
[139736429082560] 'Etrel Inch'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 199, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1808, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1845, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/components/modbus/modbus.py", line 176, in async_write_register
    hub = hub_collect[
KeyError: 'Etrel Inch'

1 Like

Something like [0x0000, 0x0001]

I think that is an example in docs

1 Like

could you post your configuration with read registers? I have the same wall box.
thank you

I’d try getting rid of the blank space in “Entrel Inch”, make it entrel_inch everywhere. The error indicates it can’t find “Entrel Inch”, so I suspect the code is sluggifying the hub name (e.g, removing the space) in some spots but not all. If that ends up being true you have a workaround and please submit a bug report.

please:

in my configuration.yaml file:

# Modbus (Etrel)
modbus: !include configurations/Etrel-Modbus.yaml

in my /config/configurations/Etrel-Modbus.yaml file

- type: tcp
  host: 10.0.0.209
  port: 502
  name: etrel_inch
  sensors:
      # inputs
    - name: Etrel_connection_status
      slave: 255
      address: 0
      input_type: input
      data_type: int16
      count: 1
    - name: Etrel_target_current
      unit_of_measurement: A
      slave: 255
      address: 4
      input_type: input
      data_type: float32
      count: 2
      device_class: current
    - name: Etrel_current_L1
      unit_of_measurement: A
      slave: 255
      address: 14
      input_type: input
      data_type: float32
      count: 2
      device_class: current
    - name: Etrel_active_power_total
      unit_of_measurement: kW
      slave: 255
      address: 26
      input_type: input
      data_type: float32
      count: 2
      device_class: power
    - name: Etrel_imported_energy_total
      unit_of_measurement: kWh
      slave: 255
      address: 30
      input_type: input
      data_type: float32
      precision: 1
      count: 2
      device_class: energy
    - name: Etrel_running_session_duration
      unit_of_measurement: h
      slave: 255
      address: 32
      input_type: input
      data_type: int64
      precision: 2
      count: 4
      scale: 0.000278
      device_class: duration
    - name: Etrel_running_session_departure_time
      unit_of_measurement: s
      slave: 255
      address: 36
      input_type: input
      data_type: int64
      count: 4
      device_class: timestamp
    - name: Etrel_EV_max_power
      unit_of_measurement: kW
      slave: 255
      address: 44
      input_type: input
      data_type: float32
      precision: 1
      count: 2
      device_class: power
    - name: Etrel_EV_planned_energy
      unit_of_measurement: kWh
      slave: 255
      address: 46
      input_type: input
      data_type: float32
      count: 2
      device_class: energy
1 Like

thanks for the suggestions.
I’ve changed the hub name to etrel_inch everywhere.
I’ve also changed the value to [0x0000, 0x0001]

but I’m still getting the error:

Logger: homeassistant.components.websocket_api.http.connection
Source: components/modbus/modbus.py:178
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 09:31:37 (6 occurrences)
Last logged: 09:43:21

[139938712302304] 'etrel_inch'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 199, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1808, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1845, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/components/modbus/modbus.py", line 178, in async_write_register
    hub = hub_collect[
KeyError: 'etrel_inch'

I also notice the values are changed after saving the code editor

 - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: call-service
      service: modbus.write_register
      data:
        address: 11
        slave: 255
        value: # here I saved the value [0x0000, 0x0001]
          - 0
          - 1
        hub: etrel_inch
      target: {}
    name: 4kW
    icon: mdi:gauge-low
    show_state: false

thank you, i will look at it and try a write to registers

in documentation, these 2 lines looks like disabled
Connector 1 • Set power setpoint
Connector 1 • Cancel power setpoint

try to write to
Connector 1 • Set current setpoint

good suggestion, tried this also. Still no success.

I’ve also tried to write the register with the program QModMaster.
I’ve got it working with the following settings:

I write value “18” to register 8 (2 registers, data format float) and the setting is reflected in the input register on address 4 = “Connector 1 • Target current from power mgm or modbus”

I just need to try to do the same in home assistant

1 Like

Progress!
after upgrading to 2023.3.6 it seems to work. I no longer get the KeyError error.
There was indeed a Modbus bugfix in 2023.3.5.

releasing the set current works:

      action: call-service
      service: modbus.write_register
      data:
        address: 10
        slave: 255
        value: 1
        hub: etrel_inch

setting the target current to a particular value does also work.
I can set the value to 10.0 per Modbus documentation, but I still need to figure out how to convert float to “network order float hexadecimal”

      action: call-service
      service: modbus.write_register
      data:
        address: 8
        slave: 255
        value: [0x4120, 0x0000]
        hub: etrel_inch

edit:

it works! :grinning:

using: Floating point to hex converter

type: horizontal-stack
title: Laadsnelheid instellen
cards:
  - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: call-service
      service: modbus.write_register
      data:
        address: 8
        slave: 255
        value: 0
        hub: etrel_inch
      target: {}
    icon: mdi:gauge-empty
    name: Uit
  - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: call-service
      service: modbus.write_register
      data:
        address: 8
        slave: 255
        value:
          - 16656
          - 0
        hub: etrel_inch
      target: {}
    icon: mdi:gauge-low
    name: 2kW
  - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: call-service
      service: modbus.write_register
      data:
        address: 8
        slave: 255
        value:
          - 16779
          - 13107
        hub: etrel_inch
      target: {}
    name: 4kW
    icon: mdi:gauge
    show_state: false
  - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: call-service
      service: modbus.write_register
      data:
        address: 8
        slave: 255
        value:
          - 16896
          - 0
        hub: etrel_inch
      target: {}
    name: 8kW
    icon: mdi:gauge-full
  - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: call-service
      service: modbus.write_register
      data:
        address: 10
        slave: 255
        value: 1
        hub: etrel_inch
      target: {}
    name: Auto
    icon: mdi:autorenew

behold, the changes!

1 Like

great work.
Can you set the value when the car is not connected?
I don’t have EV and when I take your example, nothing happens.

service: modbus.write_register
data:
  address: 8
  hub: etrel_inch
  value:
    - 16896
    - 0

where can I set the target current in etrel web dashboard?

yes, you can.
The example is when no EV connected. The plot is from readregister on address 4 named “Connector 1 • Target current from power mgm or modbus”
I changes according the value written to writeregister on address 8

Also writing any value to address 10 releases the target current (and resets it to the maximum value of my installation which is 32A)

you can’t. I can only be set via modbus

I am integrating my etrel inch car charger as well, but as a secondary modbus device. My primary modbus device is an RTU over IP device which i adress with the integrated tcp protocol. (Toshiba heatpump)

When i add the etrel device as described above I get many errors.

Is it even possible to adress both of these modbus devices from Home Assistant and if Yes, which special adjustments do i need to make to let this run smoothly?

what errors do you get?
it is possible to integrate more modbus slaves over TCP, every slave has different ip address

This is my code in config.yaml.

modbus:
  - name: Toshiba
    close_comm_on_error: true
    delay: 5
    timeout: 2
    type: tcp
    host: 192.168.1.9 # IP Adress of dongle
    port: 502

   
    sensors:
      - name: Verwarming aan/uit
        slave: 1
        address: 0
        input_type: holding
        data_type: int16
        scan_interval: 30
        count: 1
  
      - name: Temperatuur verwarmen/koelen
        unit_of_measurement: °C
        state_class: measurement
        slave: 1
        address: 3
        input_type: holding
        data_type: int16
        scan_interval: 30
        count: 1
        scale: 1   
 
      - name: Heet water temperatuur setpoint
        unit_of_measurement: °C
        state_class: measurement
        slave: 1
        address: 5
        input_type: holding
        data_type: int16
        scan_interval: 30
        count: 1
        scale: 1
  
  type: tcp
  host: 192.168.1.250
  port: 502
  name: etrel_inch
  sensors:
      # inputs
    - name: Etrel_connection_status
      slave: 255
      address: 0
      input_type: input
      data_type: int16
      count: 1
``

The errors i get are the following: 

Invalid config for [input_number]: expected a dictionary for dictionary value @ data[‘input_number’][‘host’]. Got ‘192.168.1.250’ expected a dictionary for dictionary value @ data[‘input_number’][‘name’]. Got ‘etrel_inch’ expected a dictionary for dictionary value @ data[‘input_number’][‘port’]. Got 502 expected a dictionary for dictionary value @ data[‘input_number’][‘sensors’]. Got [{‘name’: ‘Etrel_connection_status’, ‘slave’: 255, ‘address’: 0, ‘input_type’: ‘input’, ‘data_type’: ‘int16’, ‘count’: 1}] expected a dictionary for dictionary value @ data[‘input_number’][‘type’]. Got ‘tcp’. (See /config/configuration.yaml, line 236).

try this

modbus:
  - name: Toshiba
    close_comm_on_error: true
    delay: 5
    timeout: 2
    type: tcp
    host: 192.168.1.9 # IP Adress of dongle
    port: 502
    sensors:
      - name: Verwarming aan/uit

  - name: etrel_inch
    type: tcp
    host: 192.168.1.250
    port: 502
    sensors:
      - name: Etrel_connection_status
        slave: 255
        address: 0
        input_type: input
        data_type: int16
        count: 1

Your proposal also gives errors,
errors are gone if I add modbus 2: but sensor is not visible.

modbus:
  - name: Toshiba
    close_comm_on_error: true
    delay: 5
    timeout: 2
    type: tcp
    host: 192.168.1.9 # IP Adress of dongle
    port: 502
    sensors:
      - name: Verwarming aan/uit

modbus 2:
  - name: etrel_inch
    type: tcp
    host: 192.168.1.250
    port: 502
    sensors:
      - name: Etrel_connection_status
        slave: 255
        address: 0
        input_type: input
        data_type: int16
        count: 1

you must paste the error :slight_smile:

but try this, copy etrel_modbus from here: hass-addons/etrel_inch at main · GiZMoSK1221/hass-addons · GitHub to your config dir.
and add to configuration.yaml code from hass-addons/configuration.yaml at ae9ffebd8077e261b03e4181758c32926e71adb4 · GiZMoSK1221/hass-addons · GitHub

thanks. My issue was that I did not get an error, so nothing to share (but also no sensors)…

Using your new post it did work and I am getting data. Great! Some sensors I have to convert. Like session departure time is now: 1682161200