Custom UART Text Sensor doesn't want to show my value

Hello all,

I’ve been searching trying now for hours without finding a solution for my problem.

I have a on old RFID Card Reader from a door access system which communicates by UART.
I would like to get the Card ID into a text sensor via ESPHome (Wemos D1).

Inside the Arduino IDE I can successfully get the data. Also with the UART Debugging Function from the esphome-website I get the readings from the Reader.

debug:
    direction: BOTH
    dummy_receiver: false
    after:
      delimiter: "\n"
    sequence:
      - lambda: UARTDebug::log_string(direction, bytes);

This is the value that I get from the reader, when using the debugging from ESPHome.

\x02n110A1C000E1F003038\x03d

So now my problem. I am unable to get any value with the Custom UART Text Sensor.
I configured everything as mentioned in the ESPHome Cookbook ( Custom UART Text Sensor — ESPHome, but the Text Sensor won’t update, when I try to read a card.

From my point of view it looks like that the RFID Reader is not sending \n as delimiter, but I am not that experienced in this type of communication to verify this.

Does anybody have an Idea what I am missing here or what else I could try to get this working with ESPHome?

Thanks in advance. :slight_smile:

Can you post the Arduino code?

Of course :slight_smile:

String readString;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
   while (Serial.available()) {
    delay(2);  //delay to allow byte to arrive in input buffer
    char c = Serial.read();
    readString += c;
  }

  if (readString.length() >0) {
    Serial.println(readString.substring(5,20));

    readString="";
  } 
}

That code gives me this as output: A1C000E1F003038

Are the beginning and end of the string fixed? Aka never change.

Providing more lines of sample data would help in the quest for delimination.

Yes the beginning and the end is fix:

\x02n110A1C000E1F003038\x03d

Start: \x02
Card ID: n110A1C000E1F003038
End: \x03d

So it looks like you need to either customize the uart_read_line_sensor.h to deliminate on \x03d and substring the header.

Or you could bulk replace everything in the uart_read_line_sensor.h while loop with the Arduino while code. Obviously the Serial.println won’t work but you can replace that with the appropriate publish_state

1 Like

Big thank you. That was the solution. :slight_smile:

Nice work.

Perhaps you could post the customized uart_read_line_sensor.h that you landed on. This helps others searching for the same solution in the future.