Need remote transmitter lambda example for sending raw code

I’m trying to make a remote transmitter lambda call using a raw code. There is a good example in the docs using the Pioneer protocol as show below:

// Example - transmit using the Pioneer protocol
auto call = id(my_transmitter).transmit();
esphome::remote_base::PioneerData data = { rc_code_1, rc_code_2 };
esphome::remote_base::PioneerProtocol().encode(call.get_data(), data);
call.set_send_times(2);
call.perform();

Looking for a similar example for raw code. This is what I have tried to put together so far but I’m at my limit of my coding knowledge and ability to make connection between RemoteTransmitData and the TransmitCall.

script:
  - id: thermostat_script
    then:
    - lambda: |-               
        std::vector<int32_t> hvac_code;
        hvac_code = {+4500,-2700...+4450,-50100};
        // Call remote transmitter using selected code
        auto call = id(my_remote_transmitter).transmit();
        esphome::remote_base::RemoteTransmitData * RTD;
        RTD.set_data(hvac_code);
        RTD.set_carrier_frequency(38);
        esphome::remote_base::RawAction<esphome::remote_base::RemoteTransmitData>().encode(RTD);
        call.get_data(RTD);
        call.perform();

Not sure if this would work for you but ESPHome has a method to send raw data: Remote Transmitter - raw.

Yes, I have used that before but in this case I had a bunch of lambda code in order to pre-process so I wanted to call it from within the lambda. I also wasn’t aware I could template the code value, but have since learned that I can. So I altered my approach and now pre-process and determine the code in the lambda and then return the code. I originally was trying to use a string-vector dictionary in the lambda to store the various codes with a corresponding string key, but I struggled quite a bit and gave up and just went with an if statement.

I think it would still be useful to see how to make the call from within the lambda. I found it difficult to navigate the API and figure out how to connect the various classes that appeared to be needed.

script:
  - id: thermostat_script
    then:
    - remote_transmitter.transmit_raw:
        carrier_frequency: 38kHz
        code: !lambda |-
          if (id(houghton).mode == CLIMATE_MODE_OFF || id(houghton).action == CLIMATE_ACTION_IDLE || id(houghton).action == CLIMATE_ACTION_OFF) {
            ESP_LOGD("thermostat", "Transmitting IR code for OFF");
            return {+4550,-2700,..+4450,-50100};
          } else if (id(houghton).mode == CLIMATE_MODE_COOL && id(houghton).fan_mode == CLIMATE_FAN_LOW) {
            ESP_LOGD("thermostat", "Transmitting IR code for COOL-LOW");
            return {+4500,-2700,..4450,-50100};
......
          } else { // UNKNOWN therefore OFF
            ESP_LOGD("thermostat", "Transmitting IR code for OFF");
            return {+4550,-2700,..4450,-50100};
          }

1 Like

@ncarney - Any progress on this?