Integrating Pylontech batteries into HA with ESPHome integration

Hi all, I’m trying to integrate my 4 pylontech batteries into HA using ESPHome and the pylontech integration available with latest update of ESPHome.

I did the hardware setup and it is correct.

Now I’m trying to edit the yaml file and I get an error in the UART part. I am following direction of the pylontech integration I found here but I’m not able to have it working.

Can someone point me to the right direction?

Following is the yaml file I’m trying to do

esphome:
  name: batterie-solare
  friendly_name: Batterie Solare

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: !secret api_key

ota:
  password: !secret ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Batterie-Solare Fallback Hotspot"
    password: !secret ap_password
captive_portal:

pylontech:
  id: pylontech0
    - uart_id: 0
    - update_interval: 60s

sensor:
  - platform: pylontech
    battery: 1
    voltage:
      id: bat1_voltage
      name: "Battery1 Voltage"
    current:
      id: bat1_current
      name: "Battery1 Current"
    coulomb:
      name: "Battery1 State of Charge"
    temperature:
      name: "Battery1 Temperature"
  
  - platform: pylontech
    battery: 2
    voltage:
      id: bat2_voltage
      name: "Battery2 Voltage"
    current:
      id: bat2_current
      name: "Battery2 Current"
    coulomb:
      name: "Battery2 State of Charge"
    temperature:
      name: "Battery2 Temperature"

  - platform: pylontech
    battery: 3
    voltage:
      id: bat3_voltage
      name: "Battery3 Voltage"
    current:
      id: bat3_current
      name: "Battery3 Current"
    coulomb:
      name: "Battery3 State of Charge"
    temperature:
      name: "Battery3 Temperature"

  - platform: pylontech
    battery: 4
    voltage:
      id: bat4_voltage
      name: "Battery4 Voltage"
    current:
      id: bat4_current
      name: "Battery4 Current"
    coulomb:
      name: "Battery4 State of Charge"
    temperature:
      name: "Battery4 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 pwr = pwr1 + pwr2 + pwr3 + pwr4;
      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: "Battery1 Base State"
    voltage_state:
      id: bat1_voltage_state
      name: "Battery1 Voltage State"
    current_state:
      id: bat1_current_state
      name: "Battery1 Current State"
    temperature_state:
      id: bat1_temperature_state
      name: "Battery1 Temperature State"

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

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

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

Please share it.

This bit doesn’t look quite right to me (basic yaml).

I think you need to review how to set up a uart bus.

That’s it. Thank you. I didn’t realize I have to setup the UART bus and THEN assign that bus to the pylontech

1 Like

Hi @clemente3905,

Please can you post a copy of your working config? I am also trying to get this working but to no avail!

Many thanks

Mike

Here it is.
I have 4 batteries connected. You must customize the yaml to suit your configuration if you have more ore less batteries.

Tell me if I can help more.

esphome:
  name: esphome-web-cd63a8
  friendly_name: Pylontech

esp32:
  board: esp32dev
  framework:
    type: arduino

uart:
  - id: uart_pylontech
    tx_pin: 1 # tx pin for pylontech uart
    rx_pin: 3 # 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);



# Enable logging
logger:
  hardware_uart: UART1

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

# Enable Home Assistant API
api:
  encryption:
    key: "...="

ota:


wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esphome-Web-Cd63A8"
    password: "...."

captive_portal:

sensor:
  - platform: pylontech
    battery: 1
    voltage:
      id: bat1_voltage
      name: "Batteria 1 Tensione"
    current:
      id: bat1_current
      name: "Batteria 1 Corrente"
    coulomb:
      name: "Batteria 1 Carica"
    temperature:
      name: "Batteria 1 Temperatura"
  
  - platform: pylontech
    battery: 2
    voltage:
      id: bat2_voltage
      name: "Batteria 2 Tensione"
    current:
      id: bat2_current
      name: "Batteria 2 Corrente"
    coulomb:
      name: "Batteria 2 Carica"
    temperature:
      name: "Batteria 2 Temperatura"  

  - platform: pylontech
    battery: 3
    voltage:
      id: bat3_voltage
      name: "Batteria 3 Tensione"
    current:
      id: bat3_current
      name: "Batteria 3 Corrente"
    coulomb:
      name: "Batteria 3 Carica"
    temperature:
      name: "Batteria 3 Temperatura"  

  - platform: pylontech
    battery: 4
    voltage:
      id: bat4_voltage
      name: "Batteria 4 Tensione"
    current:
      id: bat4_current
      name: "Batteria 4 Corrente"
    coulomb:
      name: "Batteria 4 Carica"
    temperature:
      name: "Batteria 4 Temperatura" 

  - 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 pwr = pwr1 + pwr2 + pwr3 + pwr4;
      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: "Batteria 1 Stato Base"
    voltage_state:
      id: bat1_voltage_state
      name: "Batteria 1 Stato Tensione"
    current_state:
      id: bat1_current_state
      name: "Batteria 1 Stato Corrente"
    temperature_state:
      id: bat1_temperature_state
      name: "Batteria 1 Stato Temperatura"

  - platform: pylontech
    battery: 2
    base_state:
      id: bat2_base_state
      name: "Batteria 2 Stato Base"
    voltage_state:
      id: bat2_voltage_state
      name: "Batteria 2 Stato Tensione"
    current_state:
      id: bat2_current_state
      name: "Batteria 2 Stato Corrente"
    temperature_state:
      id: bat2_temperature_state
      name: "Batteria 2 Stato Temperatura"

  - platform: pylontech
    battery: 3
    base_state:
      id: bat3_base_state
      name: "Batteria 3 Stato Base"
    voltage_state:
      id: bat3_voltage_state
      name: "Batteria 3 Stato Tensione"
    current_state:
      id: bat3_current_state
      name: "Batteria 3 Stato Corrente"
    temperature_state:
      id: bat3_temperature_state
      name: "Batteria 3 Stato Temperatura"

  - platform: pylontech
    battery: 4
    base_state:
      id: bat4_base_state
      name: "Batteria 4 Stato Base"
    voltage_state:
      id: bat4_voltage_state
      name: "Batteria 4 Stato Tensione"
    current_state:
      id: bat4_current_state
      name: "Batteria 4 Stato Corrente"
    temperature_state:
      id: bat4_temperature_state
      name: "Batteria 4 Stato Temperatura"

 
2 Likes

@clemente3905 Hi, I am trying to get this working like you did but am having some problems. Would you be kind enough to take a look at My Post here and see if you can notice the problem? Thanks!