Convert brightness buttons into a slider?

Hi there. I have created a “copy” of the remote controller of my LED strip to be able to control it from Home Assistant.

The remote controller has 6 buttons to set the brightness: 10%, 20%… 100%. so I followed a guide and created 6 buttons on my ESP32 as a temporary solution.

What I really want is that these 6 buttons to be exposed as a slider with 6 positions (similar to a fan with 3 speeds) and if it is possible, include the on/off button into the “slider”

This is my current yaml code:

remote_transmitter:
  pin: GPIO4
  carrier_duty_percent: 50%

button:

  - platform: template
    name: "On/Off"
    on_press:
      - remote_transmitter.transmit_nec:
          address: 0x7F80
          command: 0xED12


  - platform: template
    name: "Delay"
    on_press:
      - remote_transmitter.transmit_nec:
          address: 0x7F80
          command: 0xE51A

  - platform: template
    name: "Modo"
    on_press:
      - remote_transmitter.transmit_nec:
          address: 0x7F80
          command: 0xE11E

  - platform: template
    name: "100 %"
    on_press:
      - remote_transmitter.transmit_nec:
          address: 0x7F80
          command: 0xFE01
  - platform: template
    name: "80 %"
    on_press:
      - remote_transmitter.transmit_nec:
          address: 0x7F80
          command: 0xFC03

  - platform: template
    name: "60 %"
    on_press:
      - remote_transmitter.transmit_nec:
          address: 0x7F80
          command: 0xFB04

  - platform: template
    name: "40 %"
    on_press:
      - remote_transmitter.transmit_nec:
          address: 0x7F80
          command: 0xF906

  - platform: template
    name: "20 %"
    on_press:
      - remote_transmitter.transmit_nec:
          address: 0x7F80
          command: 0xF807
  - platform: template
    name: "10 %"
    on_press:
      - remote_transmitter.transmit_nec:
          address: 0x7F80
          command: 0xF609

  - platform: template
    name: "Más"
    on_press:
      - remote_transmitter.transmit_nec:
          address: 0x7F80
          command: 0xFD02

  - platform: template
    name: "Menos"
    on_press:
      - remote_transmitter.transmit_nec:
          address: 0x7F80
          command: 0xF906

Any help will be very much aprreciated.

You could use template number, it is slider as default.
Something like this:

number:
  - platform: template
    name: "Template number"
    optimistic: true
    min_value: 0
    max_value: 5
    step: 1
    set_action:
      then:
        - remote_transmitter.transmit_nec:
            address: 0x7F80
            command: !lambda |-
              if (x == 0) {
                return 0xED12;
              } else if (x == 1) {
                return 0xE51A;
                # and so on...

I’ll try, thank you, but I would like a more elegant solution (I’m trying with a template light but no success yet).

It is not working. The LED is not responding.

I had typo there, corrected it.

Do you get errors?

That was it. Now it works.

Sorry for that!

If it doesn’t please aesthetically, you can try similar way with template fan (or whatever component you find that can be adjusted with slider step count).