IR transmitter will turn something off, but not on (ESPhome)

With an IR reciever I’ve succesfully taken the raw codes from the remote of my electric fireplace. With the IR transmitter I can now turn of the fireplace, but I cannot turn it on. Though I cannot see in the codes why it wouldn’t work.

When you turn off the fireplace with the remote, the dispay on the remote also goes off. When you turn off the fireplace with HA, the display on the remote stays on. When you press the on/off button, the display on the remote will go off, but the fireplace will not turn on. So there is some kind of difference between an off and on command.

Here are the commands the remote sends when turning on and off:

Off:
[23:27:01][I][remote.raw:028]: Received Raw: 5558, -2487, 5502, -2478, 529, -479, 557, -509, 529, -481, 556, -479, 558, -480, 558, -1545, 531, -508, 528, -1545, 529, -1546, 529, -480, 557, -481, 557, -509, 528, -482, 555, -481, 556, -509, 530, -483, 553, -483, 554, -1545, 531, -1544, 
[23:27:01][I][remote.raw:041]:   530, -1546, 530, -1544, 530, -1544, 530, -1546, 530, -1545, 530

On:
[23:27:07][I][remote.raw:028]: Received Raw: 5559, -2462, 5527, -2480, 529, -508, 528, -481, 556, -510, 528, -483, 555, -480, 556, -1546, 529, -479, 558, -1546, 529, -480, 557, -483, 554, -482, 556, -481, 555, -510, 529, -480, 556, -509, 529, -509, 532, -1542, 529, -1545, 531, -1546, 
[23:27:07][I][remote.raw:041]:   530, -1543, 531, -1544, 530, -1546, 530, -1544, 530, -1546, 529

And here is my ESPhome:

remote_receiver:
  pin:
    number: GPIO5
    inverted: True
  dump: raw

remote_transmitter:
  pin: GPIO4
  # RF uses a 100% carrier signal
  carrier_duty_percent: 50%

switch:
  - platform: template
    name: Haard
    turn_off_action:
      - remote_transmitter.transmit_raw:
          carrier_frequency: 38kHz
          code: [5559, -2487, 5504, -2480, 529, -482, 555, -482, 556, -483, 555, -509, 530, -479, 557, -1546, 530, -481, 556, -1547, 530, -1546, 535, -476, 556, -483, 555, -509, 529, -508, 529, -509, 529, -482, 556, -482, 556, -481, 556, -1545, 531, -1547, 530, -1544, 531, -1544, 531, -1547, 531, -1544, 531, -1545, 531]
    turn_on_action:
      - remote_transmitter.transmit_raw:
          carrier_frequency: 38kHz
          code: [5556, -2486, 5502, -2480, 528, -482, 555, -484, 554, -481, 556, -481, 555, -489, 550, -1547, 529, -508, 528, -1545, 529, -1546, 530, -481, 556, -509, 529, -480, 557, -482, 556, -507, 529, -509, 530, -480, 556, -510, 528, -1545, 529, -1545, 530, -1546, 530, -1545, 529, -1545, 530, -1546, 529, -1545, 530]
     

I cannot see why the fireplace ignores the ‘on’ command. Does anyone know what the remote could be doing differently when turning on? And what I could try?

Sounds like your recordings have been polluted or they are incomplete.
Try to record again.

I’ve recorded 9 on commands and asked ChatGPT to make one command out of them, using the most frequent numbers for each position.

This worked and now I can turn the fireplace on and off!

One question: how do I keep the switch in HA from turning off?

What have you made in HA?
Is it a button helper or a switch?
A switch should not turn off again, but a button helper will.

I’ve made the switch in EPShome (the one in the first post). Through the integration it appears as a switch in HA automatically.

Well, the remote_transmitter’s state is on when it is transmitting and off otherwise.
You will have to keep the state in HA with a template switch/light that calls the on/off functions on the ESPHome.