Remote_transmitter Compile error

How do I make ‘protocol’ a variable in a service?

When I use this code

  services:
    - service: send_rf_code_prot
      variables:
        protocol: int
        code: string
      then:
        - remote_transmitter.transmit_rc_switch_raw: 
            code: !lambda 'return code;'
            protocol: !lambda 'return protocol;'
            repeat:
              times: 5
              wait_time: 0s

I get this error during compile

/config/sonoff-rf-bridge.yaml:42:14: error: could not convert ‘protocol’ from ‘int32_t’ {aka ‘int’} to ‘esphome::remote_base::RCSwitchBase’

I’ve tried string also and get a similar error.

Hi, did you ever solve this - I have hit the exact same problem. Just want to pass the protocol value through a service decalaration.

I found a way to set this by creating the RemoteBase Class itself:

protocol: !lambda return esphome::remote_base::RCSwitchBase(350, 10850, 350, 1050, 1050, 350, false);

Hi, I’ve come back around to looking at this but don’t quite understand.

Can you send a code snippet so I can see how it looks.

In my code I’d like to pass "protocol’ as a value of 1,4 or 5 (maybe more) but how would recreating the RemoteBase class look in my instance or does your code not change ?

Thanks in advance

Sure, here is the complete configuration of my MQTT broker:

mqtt:
  broker: 172.17.2.25
  username: rcswitch01
  on_json_message:
    topic: rcswitch01/transmit_rc_switch_type_a
    then:
    - logger.log:
        format: "Transmit RC Switch Type A group: %s device: %s state: %s"
        args: [ 'x["group"].as<String>()', 'x["device"].as<String>()', 'x["state"].as<String>()' ]
    - remote_transmitter.transmit_rc_switch_type_a:
        group: !lambda return x["group"];
        device: !lambda return x["device"];
        state: !lambda return x["state"];
        protocol: !lambda |-
          uint32_t pulse_length = x["pulse_length"];
          uint32_t sync_low = x["sync_low"];
          uint32_t sync_high = x["sync_high"];
          uint32_t zero_low = x["zero_low"];
          uint32_t zero_high = x["zero_high"];
          uint32_t one_low = x["one_low"];
          uint32_t one_high = x["one_high"];
          bool inverted = x["inverted"];

          return esphome::remote_base::RCSwitchBase(
            sync_low * pulse_length,
            sync_high * pulse_length,
            zero_low * pulse_length,
            zero_high * pulse_length,
            one_low * pulse_length,
            one_high * pulse_length,
            inverted);
        repeat:
          times: !lambda return x["repeat"];
          wait_time: !lambda return x["wait_time"];

Here is also an example json that can be sent with all the parameters:

{
  "group": "11111",
  "device": "01000",
  "state": false,
  "repeat": 5,
  "wait_time": "0ms",
  "pulse_length": 344,
  "sync_low": 1,
  "sync_high": 31,
  "zero_low": 1,
  "zero_high": 3,
  "one_low": 3,
  "one_high": 1,
  "inverted": false
}