Happened to me yesterday… The only solution I found that really works is to use Tasmota sensors flashed to esp32 / 8266 and use it to read the code, then transmit the code from tasmota to mqtt.
I couldn’t get it to work in esphome.
You need the mqtt addon / integration and the Tasmota integration.
Here is my script code for a RF button / switch that controls a led light
alias: Pacman on-off
sequence:
- service: mqtt.publish
data:
qos: 0
retain: false
topic: cmnd/**YOUR_TASMOTA_DEVICE_HERE**/RfSend
payload: "{\"Data\":\"0x140C01\",\"Bits\":24,\"Protocol\":1,\"Pulse\":390}"
mode: single
info for read the code in tasmota: RF Communication - Tasmota
more info in this thread: ESPHome RF Receiver + Transmitter issues - #3 by dmutpuu.l