How to use Remote Receive Automations?

Hi,

I am trying to build an IR retransmitter to control my AV setup locked away in a cupboard.

I have managed to get the IR receiver to pick up the Sony codes from the remote and I can send commands from HA to the IR transmitter. Now to put them together.

I think I should use a remote_receiver automation on_sony. Something such as

remote_receiver:
  pin: 
    number: GPIO18
    inverted: true
  dump: all
  idle: 25ms
  on_sony:
    [xxx]

where the [xxx] should be a lambda function which calls remote_transmitter.transmit_sony with the data passed from the receiver in the [remote_base::SonyData] (ESPHome: esphome::remote_base::SonyData Struct Reference) variable.

What’s the syntax to access to data and nbits data in the variable passed by the receiver? I presume it’s obvious if you know C++, but I alas do not.

Thanks!

Well, for posterity the answer is here:

It is of course quite simple: the “x variable” the docs allude to are literally a structure “x” which contains the data formatted in the required format.

remote_receiver:
  pin: 
    number: GPIO18
    inverted: true
  dump: sony
  idle: 25ms
  on_sony:
    then:
    - remote_transmitter.transmit_sony:
        data: !lambda |-
          return x.data;
        nbits: !lambda |-
          return x.nbits;
        repeat:
          times: 4
          wait_time: 25ms
    - logger.log:  "Sent the Sony code to IR transmitter."
1 Like