E3DC modbus write coil

Hi there,

i have an E3DC system with battery, solar panels and Wallbox.

The integration using modbus works fine

Using the service modes.write_register is easy.

But I want to reduce the number of possibilities to control the callbox charging behavior and I need the service modus.write_coil
But I have no idea how set it up:

I need the change the value of the 2nd Bit in the uint16 register 40087 to stop / start charging. 1 = charging, 0 = charging stopped.

What do I have to put into the state field?

Thanks for any help.

BTW: happy to exchange ideas regarding the E3DC system and Homeassistant

@wall121
I did as follows

alias: e3dc Wallbox laden toggle
sequence:
  - if:
      - condition: state
        entity_id: binary_sensor.e3dc_wallbox_0_charging_open
        state: "off"
    then:
      - service: script.write_register_turn_off_bit
        data:
          bit: 3
          hub: e3dc
          unit: 1
          address: 40087
          sensor_value: sensor.e3dc_wallbox_0_ctrl
    else:
      - service: script.write_register_turn_on_bit
        data:
          bit: 3
          hub: e3dc
          unit: 1
          address: 40087
          sensor_value: sensor.e3dc_wallbox_0_ctrl
mode: single

here the two simple ‘helper’ scripts:

Write Register turn on bit

alias: Write Register turn on bit
sequence:
  - service: modbus.write_register
    data:
      hub: "{{ hub }}"
      unit: "{{ unit }}"
      address: "{{ address }}"
      value: >-
        {{ states(sensor_value) | int(default=0) | bitwise_or(2 ** (bit | int -
        1)) }}
  - service: homeassistant.update_entity
    data:
      entity_id: "{{ sensor_value }}"

Write Register turn off bit

alias: Write Register turn off bit
sequence:
  - service: modbus.write_register
    data:
      hub: "{{ hub }}"
      unit: "{{ unit }}"
      address: "{{ address }}"
      value: >-
        {{ states(sensor_value) | int(default=0) | bitwise_and(65535 - (2 **
        (bit | int - 1))) }}
  - service: homeassistant.update_entity
    data:
      entity_id: "{{ sensor_value }}"

and you need the modbus sensors, here the one needed for controlling the wallbos

# -----------
# modbus E3DC
# magic byte
#    expected at 400001
#    found at 40000
#    => offset -1
# -----------
  - name: e3dc
    type: tcp
    host: 192.168.178.111
    port: 502
    delay: 5
    timeout: 5
    sensors:
      - name: E3DC Wallbox 0 CTRL
        unique_id: e3dc_wallbox_0_ctrl
        data_type: uint16
        address: 40087```