IR transmitter not working

I am out of things to try, I would appreciate some clarification here.

First I had a D1-Mini setup with Arduino IRSend to control an AC/Heat pump and that was working well but after getting into ESPhome I am trying to migrate everything into the same environment.

I am following the documentation from ESPhome, I added a IR receiver to my D1mini and using the remote from my heat pump I press the LED button (to toggle on/off the LED display on the heat pump) and from the ESPhome log I get this:

[14:25:16][D][remote.raw:028]: Received Raw: -4412, 4313, -583, 1552, -532, 538, -530, 1606, -582, 485, -583, 485, -530, 537, -582, 1553, -534, 533, -532, 536, -531, 536, -584, 485, -530, 537, -584, 1551, -531, 537, -552, 514, -532, 537, -530, 1606, -582, 1554, -530, 1605, -532, 1604, 
[14:25:16][D][remote.raw:028]:   -532, 1605, -535, 1601, -531, 1605, -531, 1605, -584, 1553, -584, 1552, -532, 1604, -532, 1604, -532, 1604, -532, 1607, -529, 1605, -532, 1604, -532, 1606, -531, 1604, -585, 1552, -531, 1604, -532, 1605, -584, 1553, -531, 1605, -584, 1553, -530, 537, 
[14:25:16][D][remote.raw:028]:   -585, 1552, -531, 1606, -530, 1604, -532, 538, -583, 1551, -532, 537, -583, 1552, -585, 5125, -4356, 4368, -583, 486, -583, 1552, -584, 486, -528, 1606, -530, 1607, -584, 1551, -584, 485, -583, 1554, -583, 1553, -529, 1605, -532, 1605, -531, 1607, 
[14:25:16][D][remote.raw:028]:   -570, 496, -532, 1606, -530, 1605, -585, 1552, -585, 482, -584, 485, -583, 484, -530, 537, -585, 483, -585, 484, -530, 537, -583, 483, -584, 484, -585, 484, -583, 484, -583, 485, -582, 487, -580, 487, -583, 484, -530, 538, -529, 538, -530, 537, -531, 
[14:25:16][D][remote.raw:041]:   537, -585, 481, -532, 537, -530, 538, -583, 484, -531, 537, -530, 1605, -583, 485, -584, 484, -584, 485, -529, 1606, -584, 485, -529, 1605, -584, 485, -585

Then I set up my code like this:

remote_receiver:
  pin: D4
  dump: all

remote_transmitter:
  pin: D2
  # Infrared remotes use a 50% carrier signal
  carrier_duty_percent: 50%

switch:
  - platform: template
    name: Toggle LED
    turn_on_action:
      - remote_transmitter.transmit_raw:
          carrier_frequency: 38kHz
          code: [-4412, 4313, -583, 1552, -532, 538, -530, 1606, -582, 485, -583, 485, -530, 537, -582, 1553, -534, 533, -532, 536, -531, 
                536, -584, 485, -530, 537, -584, 1551, -531, 537, -552, 514, -532, 537, -530, 1606, -582, 1554, -530, 1605, -532, 1604,
                -532, 1605, -535, 1601, -531, 1605, -531, 1605, -584, 1553, -584, 1552, -532, 1604, -532, 1604, -532, 1604, -532, 1607, 
                -529, 1605, -532, 1604, -532, 1606, -531, 1604, -585, 1552, -531, 1604, -532, 1605, -584, 1553, -531, 1605, -584, 1553, 
                -530, 537, -585, 1552, -531, 1606, -530, 1604, -532, 538, -583, 1551, -532, 537, -583, 1552, -585, 5125, -4356, 4368, -583, 
                486, -583, 1552, -584, 486, -528, 1606, -530, 1607, -584, 1551, -584, 485, -583, 1554, -583, 1553, -529, 1605, -532, 1605, 
                -531, 1607, -570, 496, -532, 1606, -530, 1605, -585, 1552, -585, 482, -584, 485, -583, 484, -530, 537, -585, 483, -585, 484, 
                -530, 537, -583, 483, -584, 484, -585, 484, -583, 484, -583, 485, -582, 487, -580, 487, -583, 484, -530, 538, -529, 538, -530, 
                537, -531, 537, -585, 481, -532, 537, -530, 538, -583, 484, -531, 537, -530, 1605, -583, 485, -584, 484, -584, 485, -529, 1606, 
                -584, 485, -529, 1605, -584, 485, -585]

When I activate the button from HA, looking at the log I can see this:

[15:18:19][D][switch:021]: 'Toggle LED' Turning ON.
[15:18:19][D][remote_transmitter:066]: Sending remote code...

Looking at the IRled from my phone cam I can also see the activity but nothing is received at the heat pump which is about 9 feet in front of the D1mini.

Any suggestion I can try?

Try setting inverted: true. This is my code. You can also look at this thread as it has loads of info to get it working.

remote_receiver:
  pin: 
    number: GPIO15
    inverted: True
    mode: INPUT_PULLUP
  dump: raw

remote_transmitter:
  pin: GPIO2
  carrier_duty_percent: 50%

switch:
  - platform: template
    name: 'SR AC'
    optimistic: True
    assumed_state: True
    turn_on_action:
      - remote_transmitter.transmit_raw:
          code: [ MY CODE]
          carrier_frequency: 38kHz
    turn_off_action:
      - remote_transmitter.transmit_raw:
          code: [ MY CODE]
          carrier_frequency: 38kHz

Thanks for your help, adding the following lines worked.
It is not 100% reliable but I may just replace the D1mini with an ESP32.

I had problems with using raw codes. If you got an arduino or another esp laying around, try to test it with the IRremote (or IRremoteESP8266 version if using an esp) lib, the IRReceiverDumpv2 example works well. IF you got NEC or other protocols decoded, then you can those. For me, decoding protocols properly dont work on ESPHome, no matter if I used an esp8266 or an ESP32. Only rc5 codes worked to decode. But on the esp32 i had issues with a few rc5 codes only got decoded a few times while the rest worked like a charm.

My code does not get detected (or decoded) as a known device.
What I am working with is an A/C Heat Pump from Perfect Aire.

I am still learning but a bit confused. With an Arduino sketch using some code from the examples I am able to read the code from the remote and copy it in my sketch and successfully send it everytime.
on Arduino I am using
IRremoteESP8266.h and IRsend.h and the IR code looked like this:

uint16_t ledToggle[199] = {4440, 4316,  534, 1606,  532, 536,  586, 1550,  534, 536,  586, 480,  586, 484,  530, 1606,  586, 482,  584, 482,  586, 482,  532, 536,  584, 486,  530, 1606,  584, 484,  584, 482, 580, 488,  586, 1552,  588, 1550,  536, 1604,  586, 1552,  588, 1550,  586, 1552,  586, 1554, 584, 1552,  586, 1550,  586, 1552,  586, 1552,  532, 1604,  534, 1606,  586, 1552,  586, 552, 532, 1606,  532, 1606,  586, 1552,  586, 1554,  530, 1606,  586, 1552,  586, 1552,  584, 552, 588, 1552,  584, 486,  532, 1606,  586, 1550,  534, 1606,  584, 482,  532, 1604,  534, 536, 586, 1552,  582, 5130,  4362, 4370,  586, 482,  584, 1554,  586, 482,  584, 1552,  534, 1606,  530, 1606,  586, 484,  532, 1606,  586, 1554,  530, 1608,  586, 1554,  584, 1552,  586, 484,  532, 1606,  532, 1606,  532, 1606,  532, 536,  584, 484,  586, 482,  586, 482,  588, 480,  532, 536, 586, 482,  532, 536,  584, 482,  586, 484,  586, 484,  584, 482,  532, 536,  532, 536,  532, 536, 586, 480,  586, 484,  586, 480,  586, 482,  586, 482,  588, 484,  530, 536,  586,482,  586, 484, 586, 1550,  588, 484,  584, 482,  586, 482,  584, 1552,  532, 538,  584, 1552,  588, 482,  584};

and the command to send the code is:

irsend.sendRaw(ledToggle, 199, 38);

Note that there are no minus sings in the values above.

With ESPhome the code looks like this (inverted)

code: [4412, -4309, 586, -1550, 585, -482, 530, -1604, 586, -483, 528, -539, 585, -482, 584, -1549, 586, -482, 584, -483, 585, -482, 585, -482, 529, -538, 529, -1606, 585, -483, 584, -482, 584, -482, 586, -1549, 585, -1551, 529, -1605, 534, -1601, 586, -1549, 586, -1550, 585, -1550, 531, -1604, 586, -1549, 529, -1605, 587, -1550, 583, -1552, 585, -1550, 585, -1550, 585, -1549, 587, -1550, 530, -1605, 529, -1607, 585, -1551, 584, -1551, 529, -1605, 586, -1549, 587, -1549, 586, -1550, 585, -482, 585, -1550, 530, -1607, 584, -1551, 529, -561, 506, -1605, 587, -482, 584, -1550, 586, -5120, 4410, -4312, 585, -484, 583, -1552, 584, -481, 531, -1605, 586, -1550, 586, -1549, 586, -482, 530, -1606, 584, -1551, 529, -1606, 586, -1550, 585, -1551, 584, -483, 529, -1607, 584, -1551, 585, -1551, 529, -542, 526, -538, 529, -538, 529, -539, 584, -483, 584, -483, 529, -539, 583, -484, 585, -481, 529, -539, 585, -481, 530, -540, 583, -483, 584, -482, 530, -538, 585, -506, 561, -481, 531, -537, 585, -483, 583, -483, 585, -484, 584, -483, 584, -483, 584, -483, 530, -1605, 584, -484, 583, -484, 584, -484, 584, -1550, 585, -484, 582, -1553, 583, -485, 584]

If I compare both codes, there is somewhat of a correlation so I tried adding a minus to every second number from the first code. Then, I was able to get it working only once. Using the later code It worked about 5 times out of 20.

Since when I read the code from the remote, I get slightly different values every time, I am thinking either my IR receiver and/or transmitter are low quality and not doing their job but then again, it worked every time with the Arduino sketch with the same hardware.

my receiver is a VS1838B but I don’t have a part number on the trx. Perhaps the processing part in ESPhome is too demanding for the esp8266?

As I am writing this something came to mind, I may try to read the the code from the transmitter like a dozen times and average each number but that’s a lot of work if i consider each button on the remote.

I also got the receiver that you’re using and for me in esphome, only rc5 codes are getting properly decoded. Even on an esp32. My transmitter is a single ir led, connected directly to 3,3v and the pin im using. Since im not using an amplifiying circuit, i have to put the led directly in front of the ir receiver of my amplifier, but thats not a problem, because im using 5 pieces of dupont wires which are still connected and taped the rceiver to the top of the amp and the ir led infront of the ir receiver of the amp. Maybe you need to use an npn transistor as amplifiying circuit for the ir transmitter (if its just an ir led with 2 legs) or place it dirctly infront of your appliance.

My transmitter is a 2 legs but connected to a transistor pulling 5V to it.
If its been working flawlessly before, I wonder why not with ESPhome?