esphome:
  name: theater_blaster
  platform: esp32
  board: lolin32

# MAC: 3c:71:bf:ab:6e:94

logger:
  baud_rate: 0
  level: INFO
  logs:
    out: INFO

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  use_address: 10.2.0.38
  
ota:

mqtt:
  broker: '10.2.0.1'
  port: 1883
  username: ''
  password: ''
  on_json_message:
    - topic: theater_blaster/ir_out/volume_up
      then:
        - remote_transmitter.transmit_nec:
            address: 0x4BB6
            command: 0x40BF
            repeat:
              times: !lambda |-
                if (x.containsKey("times")) {
                  return x["times"];
                }
                return 1;
    - topic: theater_blaster/ir_out/volume_down
      then:
        - remote_transmitter.transmit_nec:
            address: 0x4BB6
            command: 0xC03F
            repeat:
              times: !lambda |-
                if (x.containsKey("times")) {
                  return x["times"];
                }
                return 1;
  on_message:
    - topic: theater_blaster/ir_out
      payload: "input_bd"
      then:
        - remote_transmitter.transmit_nec:
            address: 0x4B36
            command: 0x31CE
    - topic: theater_blaster/ir_out
      payload: "input_cbl"
      then:
        - remote_transmitter.transmit_nec:
            address: 0x4BB6
            command: 0x708F
    - topic: theater_blaster/ir_out
      payload: "input_game"
      then:
        - remote_transmitter.transmit_nec:
            address: 0x4BB6
            command: 0xB04F
    - topic: theater_blaster/ir_out
      payload: "input_pc"
      then:
        - remote_transmitter.transmit_nec:
            address: 0x4BB6
            command: 0x39C6
            

remote_receiver:
  -  id: ir_in
     pin:
       number: GPIO27
       mode: INPUT
       inverted: True
     dump: nec
  - id: rf_in
    pin: GPIO13
    tolerance: 20%
    filter: 250us
    idle: 8ms
    dump: rc_switch
    on_rc_switch:
      then:
        - logger.log: 
            level: INFO
            tag: out
            format: "RF read; proto %d; code %08llx"
            args: [x.protocol, x.code]
        - mqtt.publish_json:
            topic: theater_blaster/rf_received
            payload: !lambda |-
              root["protocol"] = x.protocol;
              root["code0"] = static_cast<unsigned long>(x.code >> 32); 
              root["code1"] = static_cast<unsigned long>(x.code & 0xffff);
remote_transmitter:
  id: ir_out
  pin: GPIO14
  carrier_duty_percent: 50%

  
#13 rf recv
#12 rf send
#https://www.passion-radio.com/img/cms/wifi-kit-32-pinout.png

  
#on_...:
#  - remote_transmitter.transmit_nec:
#      address: 0x1234
#      command: 0x78AB
      
i2c:
  sda: 4
  scl: 15

font:
  - file: "/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf"
    id: font_vera
    size: 20
    
display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    reset_pin: 16
    address: 0x3C
    lambda: |-
      it.print(128/2, 0+6, id(font_vera), TextAlign::TOP_CENTER, "big cast erisk");
      it.print(128/2, 64-6, id(font_vera), TextAlign::BOTTOM_CENTER ,"Volume 45");
