ESPHome Pylontech battery integration - can someone spot the mistake I am making?

I hope a kind soul will help me. I am fairly new to this whole area of ESP32 and custom sensors so should probably have started with something a little easier but the main project that would help me is to have remote access to the state of my Pylontech batteries. So I decided to try to put together the hardware and integrate using the ESPHome Pylontech integration. I cobbled together what I thought was the appropriate wiring and soldered it up using a MAX3232 RS232 to TTL converter connected to an ESP32.

Following the schematic on the Pylontech Monitoring Github, I made an RJ45 connector with standard T-568B config on one end and then connected Pin 3 (white/green) to IN on the MAX3232 and Pin 6 (green) to OUT on the MAX3232 and finally Pin 8 (brown) to the NEGATIVE on the MAX3232.


Then I connected the TTL side up to the ESP32 and flashed and programmed it using some example YAML I found on this forum. Below is a photo showing the connections and the YAML that I used. Hopefully someone can spot the error that I have made because the device and sensors have been created fine but the device logs are showing NaN errors for the values and in HA all sensors show “unavailable” so clearly something has gone wrong.

substitutions:
  name: esphome-web-fd3ee8
  friendly_name: Pylontech Monitor

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  min_version: 2024.6.0
  name_add_mac_suffix: false
  project:
    name: esphome.web
    version: '1.0'

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:
  hardware_uart: UART1

# Enable Home Assistant API
api:

# Allow Over-The-Air updates
ota:
- platform: esphome

# Allow provisioning Wi-Fi via serial
improv_serial:

wifi:
  # Set up a wifi access point
  ap: {}

# In combination with the `ap` this allows the user
# to provision wifi credentials to the device via WiFi AP.
captive_portal:

dashboard_import:
  package_import_url: github://esphome/example-configs/esphome-web/esp32.yaml@main
  import_full_config: true

# Sets up Bluetooth LE (Only on ESP32) to allow the user
# to provision wifi credentials to the device.
esp32_improv:
  authorizer: none

# To have a "next url" for improv serial
web_server:

uart:
  - id: uart_pylontech
    tx_pin: GPIO1 # tx pin for pylontech uart
    rx_pin: GPIO3 # rx pin for pylontech uart
    baud_rate: 115200 # baudrate for pylontech uart
    debug:
      direction: BOTH
      dummy_receiver: false
      after:
        delimiter: "\n"
      sequence:
        - lambda: UARTDebug::log_string(direction, bytes);

pylontech:
  - id: pylontech0
    uart_id: uart_pylontech
    update_interval: 20s

sensor:
  - platform: pylontech
    battery: 1
    voltage:
      id: bat1_voltage
      name: "Battery 1 Voltage"
    current:
      id: bat1_current
      name: "Battery 1 Current"
    coulomb:
      name: "Battery 1 Resistance"
    temperature:
      name: "Battery 1 Temperature"
  
  - platform: pylontech
    battery: 2
    voltage:
      id: bat2_voltage
      name: "Battery 2 Voltage"
    current:
      id: bat2_current
      name: "Battery 2 Current"
    coulomb:
      name: "Battery 2 Resistance"
    temperature:
      name: "Battery 2 Temperature"

  - platform: pylontech
    battery: 3
    voltage:
      id: bat3_voltage
      name: "Battery 3 Voltage"
    current:
      id: bat3_current
      name: "Battery 3 Current"
    coulomb:
      name: "Battery 3 Resistance"
    temperature:
      name: "Battery 3 Temperature"

  - platform: pylontech
    battery: 4
    voltage:
      id: bat4_voltage
      name: "Battery 4 Voltage"
    current:
      id: bat4_current
      name: "Battery 4 Current"
    coulomb:
      name: "Battery 4 Resistance"
    temperature:
      name: "Battery 4 Temperature"

  - platform: pylontech
    battery: 5
    voltage:
      id: bat5_voltage
      name: "Battery 5 Voltage"
    current:
      id: bat5_current
      name: "Battery 5 Current"
    coulomb:
      name: "Battery 5 Resistance"
    temperature:
      name: "Battery 5 Temperature"

  - platform: pylontech
    battery: 6
    voltage:
      id: bat6_voltage
      name: "Battery 6 Voltage"
    current:
      id: bat6_current
      name: "Battery 6 Current"
    coulomb:
      name: "Battery 6 Resistance"
    temperature:
      name: "Battery 6 Temperature"

  - platform: template
    id: pylontech_power
    name: "Pylontech power"
    unit_of_measurement: W
    lambda: |-
      auto pwr1 = id(bat1_voltage).state * id(bat1_current).state;
      auto pwr2 = id(bat2_voltage).state * id(bat2_current).state;
      auto pwr3 = id(bat3_voltage).state * id(bat3_current).state;
      auto pwr4 = id(bat4_voltage).state * id(bat4_current).state;
      auto pwr5 = id(bat5_voltage).state * id(bat5_current).state;
      auto pwr6 = id(bat6_voltage).state * id(bat6_current).state;

      auto pwr = pwr1 + pwr2 + pwr3 + pwr4 + pwr5 +pwr6;
      id(combined_charge_power).publish_state(max(pwr, 0.0f));
      id(combined_discharge_power).publish_state(max(-pwr, 0.0f));
      return pwr;
    update_interval: 5s
    device_class: power
    state_class: measurement

  - platform: template
    id: combined_charge_power

  - platform: template
    id: combined_discharge_power

  - platform: integration
    name: "Pylontech charging"
    sensor: combined_charge_power
    time_unit: h
    state_class: total_increasing
    device_class: energy
    unit_of_measurement: "Wh"

  - platform: integration
    name: "Pylontech discharging"
    sensor: combined_discharge_power
    time_unit: h
    state_class: total_increasing
    device_class: energy
    unit_of_measurement: "Wh"

text_sensor:
  - platform: pylontech
    battery: 1
    base_state:
      id: bat1_base_state
      name: "Battery 1 Base State"
    voltage_state:
      id: bat1_voltage_state
      name: "Battery 1 Voltage State"
    current_state:
      id: bat1_current_state
      name: "Battery 1 Current State"
    temperature_state:
      id: bat1_temperature_state
      name: "Battery 1 Temperature State"

  - platform: pylontech
    battery: 2
    base_state:
      id: bat2_base_state
      name: "Battery 2 Base State"
    voltage_state:
      id: bat2_voltage_state
      name: "Battery 2 Voltage State"
    current_state:
      id: bat2_current_state
      name: "Battery 2 Current State"
    temperature_state:
      id: bat2_temperature_state
      name: "Battery 2 Temperature State"

  - platform: pylontech
    battery: 3
    base_state:
      id: bat3_base_state
      name: "Battery 3 Base State"
    voltage_state:
      id: bat3_voltage_state
      name: "Battery 3 Voltage State"
    current_state:
      id: bat3_current_state
      name: "Battery 3 Current State"
    temperature_state:
      id: bat3_temperature_state
      name: "Battery 3 Temperature State"

  - platform: pylontech
    battery: 4
    base_state:
      id: bat4_base_state
      name: "Battery 4 Base State"
    voltage_state:
      id: bat4_voltage_state
      name: "Battery 4 Voltage State"
    current_state:
      id: bat4_current_state
      name: "Battery 4 Current State"
    temperature_state:
      id: bat4_temperature_state
      name: "Battery 4 Temperature State"

  - platform: pylontech
    battery: 5
    base_state:
      id: bat5_base_state
      name: "Battery 5 Base State"
    voltage_state:
      id: bat5_voltage_state
      name: "Battery 5 Voltage State"
    current_state:
      id: bat5_current_state
      name: "Battery 5 Current State"
    temperature_state:
      id: bat5_temperature_state
      name: "Battery 5 Temperature State"

  - platform: pylontech
    battery: 6
    base_state:
      id: bat6_base_state
      name: "Battery 6 Base State"
    voltage_state:
      id: bat6_voltage_state
      name: "Battery 6 Voltage State"
    current_state:
      id: bat6_current_state
      name: "Battery 6 Current State"
    temperature_state:
      id: bat6_temperature_state
      name: "Battery 6 Temperature State"

Try set logger on UART0 and uart_pylontech on UART2, pins GPIO17 and 16. Please check the pinout, I am writting this from memory.