Make this switch to a on-off (binary) light instead?

Hello, I have installed ESPHome on a Nedis esp8266 IR transmitter and works well. I use the template switch to turn some lights on/off. That works well, but I would rather ESPhome publish this as a light to Home Assistant - but I cannot seem to wrap my head around how to set up that code.

The button is fine as-is. That is a light-effect that could be added to the light (blinking/flickering - candelight effect).

Anyone could help me rewrite this ESPHome code?

switch:
  - platform: template
    name: "Juletrelys"
    optimistic: true
    assumed_state: true
    restore_mode: RESTORE_DEFAULT_OFF
    turn_on_action:
      - remote_transmitter.transmit_raw:
          code: [2000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,2000,-5600,
                 2000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,2000,-5600,
                 2000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,2000,-5600]
          carrier_frequency: 38kHz
          repeat:
            times: 5
            wait_time: 16ms
    turn_off_action:
      - remote_transmitter.transmit_raw:
          code: [2000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,1000, -400,1000, -400,1000, -400,2000,-5600,
                 2000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,1000, -400,1000, -400,1000, -400,2000,-5600,
                 2000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,1000, -400,1000, -400,1000, -400,2000,-5600]
          carrier_frequency: 38kHz
          repeat:
            times: 5
            wait_time: 16ms

button:
  - platform: template
    name: "Juletrelys Blinking"
    on_press:
      - remote_transmitter.transmit_raw:
          code: [2000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,1000, -400,1000,-1000, 400, -400,2000,-5600,
                 2000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,1000, -400,1000,-1000, 400, -400,2000,-5600,
                 2000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,1000, -400,1000,-1000, 400, -400,2000,-5600]
          carrier_frequency: 38kHz
          repeat:
            times: 5
            wait_time: 16ms

I have played a little but it seems I am not on the right path. Do I have to create a template based output and reference that from light? Sorry to be a little confused here.

I think you need to set up a template output Template Output — ESPHome

And then make a binary light from it.Binary Light — ESPHome

Thanks, I kindof understood that but I was a bit stuck on how to proceed. I have since tried to experiment a bit and come to this setup:

light:
  - platform: binary
    name: "Juletrelys"
    restore_mode: RESTORE_DEFAULT_OFF
    output: none
    on_turn_on:
      - output.turn_on: ir_on_transmitter
    on_turn_off:
      - output.turn_on: ir_off_transmitter


button:
  - platform: template
    name: "Juletrelys Normal"
    on_press:
      - output.turn_on: ir_on_transmitter
  - platform: template
    name: "Juletrelys Blinking"
    on_press:
      - output.turn_on: ir_blink_transmitter

output:
  - platform: template
    type: binary
    id: none
    write_action:
      - remote_transmitter.transmit_raw:
          code: [ 0 ]
  - platform: template
    type: binary
    id: ir_on_transmitter
    write_action:
      - remote_transmitter.transmit_raw:
          code: [2000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,2000,-5600,
                 2000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,2000,-5600,
                 2000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,2000,-5600]
          carrier_frequency: 38kHz
          repeat:
            times: 5
            wait_time: 16ms
  - platform: template
    type: binary
    id: ir_off_transmitter
    write_action:
      - remote_transmitter.transmit_raw:
          code: [2000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,1000, -400,1000, -400,1000, -400,2000,-5600,
                 2000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,1000, -400,1000, -400,1000, -400,2000,-5600,
                 2000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,1000, -400,1000, -400,1000, -400,2000,-5600]
          carrier_frequency: 38kHz
          repeat:
            times: 5
            wait_time: 16ms
  - platform: template
    type: binary
    id: ir_blink_transmitter
    write_action:
      - remote_transmitter.transmit_raw:
          code: [2000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,1000, -400,1000,-1000, 400, -400,2000,-5600,
                 2000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,1000, -400,1000,-1000, 400, -400,2000,-5600,
                 2000,-1000, 400,-1000, 400, -400,1000,-1000, 400,-1000, 400, -400,1000, -400,1000,-1000, 400, -400,2000,-5600]
          carrier_frequency: 38kHz
          repeat:
            times: 5
            wait_time: 16ms

This works well and I get light entity that turns on and off the lights. But there is a few odd things.

Like for instance this:

light:
  - platform: binary
    name: "Juletrelys"
    restore_mode: RESTORE_DEFAULT_OFF
    output: none

Since output is required for the light I have to put sth here. I put none and had to add a dummy output with ID none to do nothing. All the automation in handled in the on_turn_on and on_turn_off parts of the light. Is there a better workaround to this?

Secondly I wonder if it is possible to add the blinking button as a effect to the light? If I for instance change to monocromatic and add the effect? But how can I then reference the output to send the IR signal? Seems to me that the effects part of the lights component only work for lights directly connected to GPIOs and not over a remote transmitter. Am I right?