Need help with ceiling fan

hello all,
I have a SUNMORY ceiling fan from amazon and I want to integrate it to ESPHome.
the remote is RF and the FCC ID is 2A8BN-F29,
I have the RAW data and an esp32 and CC1101 module
I have a code from dbuezas working but as a push button and I will like to act as switch for the light
also I will like to change my code so I can adjust the fan speed.

# light on/off
button:
  - platform: template
    name: Light
    on_press:
      - lambda: get_cc1101(transciver).beginTransmission();
      - remote_transmitter.transmit_raw:
          # prettier-ignore
          code: [729, -247, 242, -732, 745, -228, 736, -233, 241, -765, 225, -765, 719, -261, 704, -256, 236, -741, 256, -735, 249, -760, 222, -755, 246, -751, 246, -750, 220, -772, 220, -772, 220, -773, 221, -747, 247, -746, 248, -743, 245, -744, 741, 
                 -236, 261, -723, 242, -762, 244, -738, 244, -739, 245, -764, 716, -261, 235, -749, 714, -256, 711, -246, 729, -247, 218]
          repeat:
            times: 3
            wait_time: 4.733ms
      - lambda: get_cc1101(transciver).endTransmission();

that snip is what I have as light ON/OFF I have the same code for my speeds but cant use the light card or fan template
thanks
Miguel

Why so? Explain better.
Do you have separate codes for the fan and the light?
Wouldn’t it work with fan like this? (use the code to turn on fan)

 fan:
  - platform: template
    id: fan1
    name: "Ceiling Fan"
    on_turn_on:
      - lambda: get_cc1101(transciver).beginTransmission();
      - remote_transmitter.transmit_raw:
          # prettier-ignore
          code: [729, -247, 242, -732, 745, -228, 736, -233, 241, -765, 225, -765, 719, -261, 704, -256, 236, -741, 256, -735, 249, -760, 222, -755, 246, -751, 246, -750, 220, -772, 220, -772, 220, -773, 221, -747, 247, -746, 248, -743, 245, -744, 741, 
                 -236, 261, -723, 242, -762, 244, -738, 244, -739, 245, -764, 716, -261, 235, -749, 714, -256, 711, -246, 729, -247, 218]
          repeat:
            times: 3
            wait_time: 4.733ms
      - lambda: get_cc1101(transciver).endTransmission();

as per light card, I don’t see my light device as switch only as push button.
i dont kow how to set it as a switch or light

as per fan goes, this is my code.

output:
  - platform: template
    id: ceiling_fan
    type: float 
    write_action:
      - lambda: get_cc1101(transciver).beginTransmission();
      - if:
          condition:
            lambda: return ((state == 0));
          then:
            # action for off
          #  - lambda: get_cc1101(transciver).beginTransmission();
            - remote_transmitter.transmit_raw:
                code: [767, -210, 263, -725, 742, -226, 757, -222, 244, -736, 271, -732, 744, -234, 747, -212, 265, -723, 264, -723, 289, -717, 259, -738, 248, -737, 247, -755, 247, -727, 271, -723, 248, -746, 247, -744, 243, -744, 243, -743, 739, -234, 264, 
                 -726, 735, -234, 747, -223, 255, -741, 752, -233, 252, -721, 271, -720, 742, -236, 753, -210, 266, -726, 743, -222, 246]
                repeat: 
                  times: 3
                  wait_time: 4.733ms
          #  - lambda: get_cc1101(transciver).endTransmission();
            
      - if:
          condition:
            lambda: return ((state > 0) && (state < 0.4));
          then:
            # action for speed 1
            - remote_transmitter.transmit_raw:
                code: [767, -210, 263, -725, 742, -226, 757, -222, 244, -736, 271, -732, 744, -234, 747, -212, 265, -723, 264, -723, 289, -717, 259, -738, 248, -737, 247, -755, 247, -727, 271, -723, 248, -746, 247, -744, 243, -744, 243, -743, 739, -234, 264, 
                 -726, 735, -234, 747, -223, 255, -741, 752, -233, 252, -721, 271, -720, 742, -236, 753, -210, 266, -726, 743, -222, 246]
                repeat: 5
      - if:
          condition:
            lambda: return ((state > 0.4) && (state < 0.7));
          then:
            # action for speed 2
            - remote_transmitter.transmit_raw:
                code: [767, -210, 263, -725, 742, -226, 757, -222, 244, -736, 271, -732, 744, -234, 747, -212, 265, -723, 264, -723, 289, -717, 259, -738, 248, -737, 247, -755, 247, -727, 271, -723, 248, -746, 247, -744, 243, -744, 243, -743, 739, -234, 264, 
                 -726, 735, -234, 747, -223, 255, -741, 752, -233, 252, -721, 271, -720, 742, -236, 753, -210, 266, -726, 743, -222, 246]
                repeat: 5
            
      - if:
          condition:
            lambda: return ((state > 0.7));
          then:
            # action for speed 3
            - remote_transmitter.transmit_raw:
                code: [767, -210, 263, -725, 742, -226, 757, -222, 244, -736, 271, -732, 744, -234, 747, -212, 265, -723, 264, -723, 289, -717, 259, -738, 248, -737, 247, -755, 247, -727, 271, -723, 248, -746, 247, -744, 243, -744, 243, -743, 739, -234, 264, 
                 -726, 735, -234, 747, -223, 255, -741, 752, -233, 252, -721, 271, -720, 742, -236, 753, -210, 266, -726, 743, -222, 246]
                repeat: 5

      - lambda: get_cc1101(transciver).endTransmission();

fan:
  - platform: speed
    id: ceilingfan
    output: ceiling_fan
    name: "Ceiling Fan"
    speed_count: 3

but I only see is as a slider and not as a 3 speed fan.

thanks,
Miguel

The way I did it was by creating a bunch of switches for code I wanted to send (on, off, high, medium, low):

switch:

########## - Dining Room Fan Switches - ##########

  - platform: template
    name: "Dining Room Fan On"
    id: drf_on
    turn_on_action:
      - lambda: get_cc1101(transciver).beginTransmission();
      - remote_transmitter.transmit_raw:
          code: [722, -699, 302, -746, 310, -748, 302, -732, 323, -730, 344, -693, 358, -349, 692, -359, 671, -383, 681, -724, 308, -721, 359, -378, 670, -384, 655, -351, 706, -344, 716, -356, 669, -384, 676, -741, 306, -720, 333, -700, 360, -711, 322, -737, 344, -693, 307, -396, 672]
          repeat:
            times: 10
            wait_time: 10ms
      - lambda: get_cc1101(transciver).endTransmission();

then creating a template fan that called those switches:

######### - Only Fans - ##########

  - platform: template 
    name: "Dining Room Fan"
    id: DR_Fan
    speed_count: 3
    on_turn_on:
      - switch.turn_on: drf_speed_hi
      #- lambda: 'id(DR_Fan).speed = 3;' 
    on_turn_off:
      - switch.turn_on: drf_speed_off
      #- switch.turn_off: DR_Light
    on_speed_set:
      then:
        - if:
            condition:
              lambda: 'return id(DR_Fan).speed == 3;' 
            then:
              - switch.turn_on: drf_speed_hi
        - if:
            condition:
              lambda: 'return id(DR_Fan).speed == 2;'
            then:
              - switch.turn_on: drf_speed_med
        - if:
            condition:
              lambda: 'return id(DR_Fan).speed == 1;' 
            then:
              - switch.turn_on: drf_speed_lo

This is for a couple fans that are 309mhz but I have two more that use the same remote yours does. I’m working on setting those up too.

My full code is here:

Could you share your raw data for this remote? I’ve captured the fan on/off toggle but I’m having trouble accurately capturing raw data for any of the other buttons.