Rc switch transmit with lambda, how?

Hi all i’m trying to send my 433 codes with lambdas i have figured out how to send nexa but rc switch structure are different i have tried a few things but i’m not really sure where to go from here, this is where i’m at now:

any ideas?

switch:
- platform: template
  name: "lambda_nexa"
  optimistic: true  
  turn_on_action:
    then:
      - lambda: |-  
          auto call = id(my_tx).transmit();
          esphome::remote_base::NexaData data = {15739910, 0,0,1,0 };
          esphome::remote_base::NexaProtocol().encode(call.get_data(), data);
          call.set_send_times(10);
          call.set_send_wait(10000);          
          call.perform();
  turn_off_action:
    then:
      - lambda: |-  
          auto call = id(my_tx).transmit();
          esphome::remote_base::NexaData data = {15739910, 0,0,0,0 };
          esphome::remote_base::NexaProtocol().encode(call.get_data(), data);
          call.set_send_times(10);
          call.set_send_wait(10000);          
          call.perform();



- platform: template
  name: "lambda_rc"
  optimistic: true  
  turn_on_action:
    then:
      - lambda: |-  
          auto call = id(my_tx).transmit();
          esphome::remote_base::RCSwitchData data = {6173042};
          esphome::remote_base::RCSwitchBase().transmit(call.get_data(), 6173043,4);          
          call.set_send_times(10);
          call.perform();
  turn_off_action:
    then:
      - lambda: |-  
          auto call = id(my_tx).transmit();
          esphome::remote_base::RCSwitchData data = {6173043,4};
          call.set_send_times(10);
          call.perform();

What are you actually trying to accomplish, why you need to use lambda?

What is your actual RC Switch data? What protocol?
Nexa and RC Switch have completely different type of structure.

rc switch protocol 4 with code: ‘010111111111011000100000’

and i like to use lambda because my brain prefers it.
ye i noticed rc switch are totally different from the other transmitters in esphome that is whats giving me the trouble.

Documentation is much better for yaml…

I think you need length there:
void transmit(RemoteTransmitData *dst, uint64_t code, uint8_t len) const;

And protocol:

const RCSwitchBase RC_SWITCH_PROTOCOLS[9] = {RCSwitchBase(0, 0, 0, 0, 0, 0, false)

Try something like this:

 - lambda: |-
          auto call = id(my_tx).transmit();
          uint64_t code = 6288992;  // dec 010111111111011000100000
          esphome::remote_base::RC_SWITCH_PROTOCOLS[4].transmit(call.get_data(), code, 24);
          call.set_send_times(10);
          call.set_send_wait(10000); 
          call.perform();

Wow thank you this fixed so many small annoying things
I can finally use the code directly from arduino rc switch in esphome and i don’t have to deal with all this 010111111111011000100000
And i can set protocol in my api service
and my brain is happy!!! thank you

api:
  services:

    - service: rf_send_rc_lambda
      variables:
        code: int
        protocol_: int
      then:
        - lambda: |-  
            auto call = id(my_tx).transmit();
            //uint64_t code = 6288992;  // dec 010111111111011000100000
            esphome::remote_base::RC_SWITCH_PROTOCOLS[protocol_].transmit(call.get_data(), code, 24); //thank you Karosm.
            call.set_send_times(10);
            call.set_send_wait(0); 
            call.perform();


    - service: rf_send_rc
      variables:
        code: string
      then:
        - remote_transmitter.transmit_rc_switch_raw:
            code: !lambda 'return code;'
            protocol: 4
            repeat:
              times: 10
              wait_time: 0s

Happy it helped!