It’s not so easy with esphome. For some reason unknown to me, esphome doesn’t have any sophisticated component for serial rx. You can use Uart component for tx and uart debug with dummy_receiver option like this:
uart:
baud_rate: 115200
debug:
direction: BOTH
dummy_receiver: false
after:
delimiter: "\n"
sequence:
- lambda: UARTDebug::log_string(direction, bytes);
Another option is external component. Have a look at this post:
Easy UART Parsing ESPHome Component - ESPHome - Home Assistant Community