esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

Pylontech 3000A invalid line: found only 13 items #5889

Open RonnyKempe opened 3 months ago

RonnyKempe commented 3 months ago

The problem

Plyontech Component seems to have problems parsing the Answer from my 4 Year old Pylontech Stack. This is returned from the Master Battery 19:19:48 [D] [pylontech:081] invalid bat_num in line Power Volt Curr Tempr Tlow Thigh Vlow Vhigh Base.St Volt.St Curr.St Temp.St Coulomb Time B.V.St B.T.St
19:19:48 [W] [pylontech:085] invalid line: found only 13 items in 1 50831 0 30000 28000 29000 3378 3392 Idle Normal Normal Normal 105% 2024-06-08 01:21:48 Normal Normal
19:19:48 [W] [pylontech:085] invalid line: found only 13 items in 2 50820 0 30000 28000 29000 3379 3391 Idle Normal Normal Normal 106% 2024-06-08 01:21:47 Normal Normal
19:19:48 [W] [pylontech:085] invalid line: found only 13 items in 3 50818 0 29000 27000 27000 3377 3390 Idle Normal Normal Normal 107% 2024-06-08 01:21:47 Normal Normal

But expected seems to be // Power Volt Curr Tempr Tlow Thigh Vlow Vhigh Base.St Volt.St Curr.St Temp.St Coulomb Time B.V.St B.T.St MosTempr M.T.St // 1 50548 8910 25000 24200 25000 3368 3371 Charge Normal Normal Normal 97% 2021-06-30 20:49:45 Normal Normal 22700 Normal

Whats missing is "MosTempr" and "M.T.St"

Which version of ESPHome has the issue?

2024.5.5

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

all

What platform are you using?

ESP8266

Board

wemos

Component causing the issue

Pylontech

Example YAML snippet

uart:
  id: uart_bus
  tx_pin: 1
  rx_pin: 3
  baud_rate: 115200
  rx_buffer_size: 4096
  debug:
    direction: BOTH
    dummy_receiver: false
    after:
      delimiter: "\n"
    sequence:
      - lambda: UARTDebug::log_string(direction, bytes);
pylontech:
  - id: pylontech0
    uart_id: uart_bus
    update_interval: 20s

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: 1

    voltage_low:
      name: "Battery1 min cell voltage"
    voltage_high:
      name: "Battery1 max cell voltage"

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"

Anything in the logs that might be useful for us?

19:24:08    [W] [component:237] 
Component pylontech took a long time for an operation (188 ms).
19:24:08    [W] [component:238] 
Components should block for at most 30 ms.
19:24:08    [D] [pylontech:081] 
invalid bat_num in line 
pylon>pw
19:24:08    [D] [pylontech:081] 
invalid bat_num in line 
@
19:24:08    [D] [pylontech:081] 
invalid bat_num in line Power Volt   Curr   Tempr  Tlow   Thigh  Vlow   Vhigh  Base.St  Volt.St  Curr.St  Temp.St  Coulomb  Time                 B.V.St   B.T.St  
19:24:08    [W] [pylontech:085] 
invalid line: found only 13 items in 1     50761  -238   30000  28000  29000  3375   3386   Dischg   Normal   Normal   Normal   105%     2024-06-08 01:26:08  Normal   Normal  
19:24:08    [W] [pylontech:085] 
invalid line: found only 13 items in 2     50766  -219   29000  28000  29000  3377   3387   Dischg   Normal   Normal   Normal   106%     2024-06-08 01:26:07  Normal   Normal  
19:24:08    [W] [pylontech:085] 
invalid line: found only 13 items in 3     50749  -210   29000  27000  27000  3373   3386   Dischg   Normal   Normal   Normal   107%     2024-06-08 01:26:07  Normal   Normal  
19:24:08    [W] [pylontech:085] 
invalid line: found only 1 items in 4     -      -      -      -      -      -      -      Absent   -        -        -        -        -                    -        -       
19:24:08    [W] [pylontech:085] 
invalid line: found only 1 items in 5     -      -      -      -      -      -      -      Absent   -        -        -        -        -                    -        -       
19:24:08    [W] [pylontech:085] 
invalid line: found only 1 items in 6     -      -      -      -      -      -      -      Absent   -        -        -        -        -                    -        -       
19:24:08    [W] [pylontech:085] 
invalid line: found only 1 items in 7     -      -      -      -      -      -      -      Absent   -        -        -        -        -                    -        -       
19:24:08    [W] [pylontech:085] 
invalid line: found only 1 items in 8     -      -      -      -      -      -      -      Absent   -        -        -        -        -                    -        -       
19:24:08    [D] [uart_debug:158]    
<<< "\rpylon>"
19:24:08    [D] [pylontech:081] 
invalid bat_num in line 
Command completed successfully
19:24:08    [D] [pylontech:081] 
invalid bat_num in line 
$$
19:24:28    [D] [uart_debug:158]    
>>> "pwr\n"

Additional information

No response

camel1cz commented 1 month ago

Had the same problem + on top I had some line ending issue in parsing pylontech output and had to change the line delimiter to CR (\r or 0x0D). The integration seems to be hardcoded to one specific version of pylontech firmware.

I started to code support for more versions, but ran into some design problems combinded with lack of time and give up for now...

As quick fix: 1) create in your /config/esphome new folder (my is called my_components) 2) clone the pylontech extension into it, so you'll see file /config/esphome/my_components/pylontech/pylontech.cpp 3) in you yaml add this section to override original pylontech component with your local copy. I placed it after esphome: and esp32: sections:

external_components:
  - source: 
      type: local
      path: my_components
    components: [pylontech]

In the code, I changed in the pylontech.cpp: a) (I don't think you need it, as your lines are read correctly) constant for line ending: static const uint8_t ASCII_LF = 0x0D; b) parsing line change to:

const int parsed = sscanf(                                                                                   // NOLINT
      buffer.c_str(), "%d %d %d %d %d %d %d %d %7s %7s %7s %7s %d%% %*d-%*d-%*d %*d:%*d:%*d %*s %*s %5*s %*s",  // NOLINT
      &l.bat_num, &l.volt, &l.curr, &l.tempr, &l.tlow, &l.thigh, &l.vlow, &l.vhigh, l.base_st, l.volt_st,      // NOLINT
      l.curr_st, l.temp_st, &l.coulomb/*, mostempr_s*/);                                                           // NOLINT

c) and few lines below, change: if (parsed != 14) { to if (parsed != 13) {