Reading RS232 data from weighing Scale using ESPHOME

Hi, I used custom components to read rs232 data from a weighing scale through esp8266 using max232 mini board. By esphome logs I can see the correct continuous serial data, but I cannot display the values as a sensor in homeassistant. my need is to continuously update the homeassistant sensor using the text sensor serial data. Any help is highly appreciated.

esphome:
  name: a12e
  platform: ESP8266  # Use ESP32 if applicable
  board: nodemcuv2    # Adjust this according to your ESP module
  includes:
    - uart_read_line_sensor.h

wifi:
  ssid: 
  password: 

logger:

api:
  encryption:
    key: 

ota:
  password: 

uart:
  id: uart_bus
  tx_pin: GPIO15
  rx_pin: GPIO13
  baud_rate: 9600

text_sensor:
- platform: custom
  lambda: |-
    auto my_custom_sensor = new UartReadLineSensor(id(uart_bus));
    App.register_component(my_custom_sensor);
    return {my_custom_sensor};
  text_sensors:
    id: "uart_readline"
1 Like

HI and welcome to HA. Can you please post your logs as well?

Thanks, yeah sure.

Hi Daryl, This is the ESPHome Log I’m getting

[23:28:33][C][uart.arduino_esp8266:102]: UART Bus:
[23:28:33][C][uart.arduino_esp8266:103]:   TX Pin: GPIO15
[23:28:33][C][uart.arduino_esp8266:104]:   RX Pin: GPIO13
[23:28:33][C][uart.arduino_esp8266:106]:   RX Buffer Size: 256
[23:28:33][C][uart.arduino_esp8266:108]:   Baud Rate: 9600 baud
[23:28:33][C][uart.arduino_esp8266:109]:   Data Bits: 8
[23:28:33][C][uart.arduino_esp8266:110]:   Parity: NONE
[23:28:33][C][uart.arduino_esp8266:111]:   Stop bits: 1
[23:28:33][C][uart.arduino_esp8266:115]:   Using software serial
[23:28:33][C][mdns:108]: mDNS:
[23:28:33][C][mdns:109]:   Hostname: a12e
[23:28:33][C][ota:093]: Over-The-Air Updates:
[23:28:33][C][ota:094]:   Address: a12e.local:8266
[23:28:33][C][ota:097]:   Using Password.
[23:28:33][C][api:138]: API Server:
[23:28:33][C][api:139]:   Address: a12e.local:6053
[23:28:33][C][api:141]:   Using noise encryption: YES
[23:29:19][D][text_sensor:064]: 'uart_readline': Sending state '\xffww-135.60kg'
[23:29:19][D][text_sensor:064]: 'uart_readline': Sending state 'ww-135.60kg'
[23:29:19][D][text_sensor:064]: 'uart_readline': Sending state 'ww-135.60kg'
[23:29:19][D][text_sensor:064]: 'uart_readline': Sending state 'ww-135.60kg'
[23:29:19][D][text_sensor:064]: 'uart_readline': Sending state 'ww-135.60kg'
[23:29:19][D][text_sensor:064]: 'uart_readline': Sending state 'ww-135.60kg'
[23:29:19][D][text_sensor:064]: 'uart_readline': Sending state 'ww-135.60kg'
[23:29:20][D][text_sensor:064]: 'uart_readline': Sending state 'ww-135.60kg'

ESP Uart reads the same weight as displayed in the scale.

By figuring the below configuration the values got exposed in homeassistant.

  • internal (Optional, boolean): Mark this component as internal. Internal components will not be exposed to the frontend (like Home Assistant). Only specifying an id without a name will implicitly set this to true.

I added the name for the text sensor in the code.

text_sensor:
- platform: custom
  lambda: |-
    auto my_custom_sensor = new UartReadLineSensor(id(uart_bus));
    App.register_component(my_custom_sensor);
    return {my_custom_sensor};
  text_sensors:
    name: "Weight Machine"
    id: "uart_readline"

Now I’m trying to separate ‘ww’ text from the output.
image

Finally managed to remove the ‘ww’ preffix and converted the string to float, this is my final esphome code.

uart:
  id: uart_bus
  tx_pin: GPIO15
  rx_pin: GPIO13
  baud_rate: 9600

text_sensor:
- platform: custom
  lambda: |-
    auto my_custom_sensor = new UartReadLineSensor(id(uart_bus));
    App.register_component(my_custom_sensor);
    return {my_custom_sensor};
  text_sensors:
    filters: 
    - substitute:
      - "ww -> "
    id: "uart_readline"

sensor:
  - platform: template
    update_interval: 1s
    name: "Weight"
    id: weight_sensor
    unit_of_measurement: "Kg"
    lambda: |-
      std::string x = id(uart_readline).state;
      return atof(x.c_str());
1 Like

Do you mind to share your custom components.

I moved away from custom component since it was causing lots of issue.
Instead im using the below code.

uart:
  tx_pin: GPIO17
  rx_pin: GPIO16
  baud_rate: 9600
  debug:
    direction: RX
    dummy_receiver: true
    after:
      delimiter: "\r\n"
    sequence:
      - lambda: |-
          std::string str(bytes.begin(), bytes.end());
          id(uart_readline).publish_state(str.c_str());
      
text_sensor:
  - platform: template
    #name: "Raw String"
    id: "uart_readline"
    filters: 
     - substitute:
       - "ww -> "

sensor:
  - platform: template
    update_interval: 1s
    name: "Weight"
    id: weight_sensor
    unit_of_measurement: "Kg"
    lambda: |-
      std::string x = id(uart_readline).state;
      return atof(x.c_str());

Thank you for your sharing.

I have tried the code given. but not luck yet for me.

Then I try to change the UART sequence as recommended by esphome doc and adjust the delimiter as below.

uart:
id: uart_1
tx_pin: 37
rx_pin: 39
baud_rate: 9600
debug:
direction: RX
dummy_receiver: true
after:
delimiter: “\r\x02,*!”
bytes: 120
sequence:
- lambda: UARTDebug::log_string(direction, bytes);

then only the shows some value like below, but I dont know how to generate the sensor so that it can get the value from there.

[15:35:57][C][logger:246]: Logger:
[15:35:57][C][logger:246]: Max Level: VERBOSE
[15:35:57][C][logger:246]: Initial Level: VERBOSE
[15:35:57][C][logger:252]: Log Baud Rate: 115200
[15:35:57][C][logger:252]: Hardware UART: USB_CDC
[15:35:57][C][logger:259]: Task Log Buffer Size: 768
[15:35:57][C][uart.idf:155]: UART Bus 0:
[15:35:57][C][uart.idf:156]: TX Pin: GPIO37
[15:35:57][C][uart.idf:157]: RX Pin: GPIO39
[15:35:57][C][uart.idf:159]: RX Buffer Size: 256
[15:35:57][C][uart.idf:161]: Baud Rate: 9600 baud
[15:35:57][C][uart.idf:161]: Data Bits: 8
[15:35:57][C][uart.idf:161]: Parity: NONE
[15:35:57][C][uart.idf:161]: Stop bits: 1
[15:35:57][C][captive_portal:099]: Captive Portal:
[15:36:03][D][uart_debug:158]: <<< “Date 2025.07.21 Time 15:25:45 Gross 262 g Tare 0 g Net 262 g\r\n\r\n”
[15:36:13][D][uart_debug:158]: <<< “Date 2025.07.21 Time 15:25:55 Gross 136 g Tare 0 g Net 136 g\r\n\r\n”
[15:36:18][D][uart_debug:158]: <<< “Date 2025.07.21 Time 15:26:00 Gross 125 g Tare 0 g Net 125 g\r\n\r\n”
[15:36:28][D][uart_debug:158]: <<< “Date 2025.07.21 Time 15:26:11 Gross 261 g Tare 0 g Net 261 g\r\n\r\n”