substitutions:
  device_name: rf_bridge_87_60
  device_ip: 192.168.87.60

esphome:
  name: ${device_name}
  platform: ESP8266
  board: esp01_1m

<<: !include standard_wifi.yaml

captive_portal:

# Enable logging
logger:
  baud_rate: 0

ota:
web_server:
  port: 80

api:
  services:
    - service: send_rf_code
      variables:
        sync: int
        low: int
        high: int
        code: int
      then:
        - rf_bridge.send_code:
            sync: !lambda 'return sync;'
            low: !lambda 'return low;'
            high: !lambda 'return high;'
            code: !lambda 'return code;'
    - service: learn
      then:
        - rf_bridge.learn
    - service: start_advanced_sniff
      then:
        - rf_bridge.start_advanced_sniffing
    - service: stop_advanced_sniff
      then:
        - rf_bridge.stop_advanced_sniffing
uart:
  tx_pin: GPIO01
  rx_pin: GPIO03
  baud_rate: 19200

sensor:
  - platform: wifi_signal
    name: "${device_name} Wifi Signal Strength"
    update_interval: 60s
  - platform: uptime
    name: "${device_name} Uptime"

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO00
      inverted: True
    name: "${device_name} Pairing Button"

status_led:
  pin:
    number: GPIO13
    inverted: yes

switch:
- platform: restart
  name: "${device_name} REBOOT"

rf_bridge:
  on_code_received:
    then:
      - homeassistant.event:
          event: esphome.rf_code_received
          data:
            sync: !lambda 'char buffer [10];return itoa(data.sync,buffer,16);'
            low: !lambda 'char buffer [10];return itoa(data.low,buffer,16);'
            high: !lambda 'char buffer [10];return itoa(data.high,buffer,16);'
            code: !lambda 'char buffer [10];return itoa(data.code,buffer,16);'

  on_advanced_code_received:
  - homeassistant.event:
      event: esphome.rf_advanced_code_received
      data:
        length: !lambda 'char buffer [10];return itoa(data.length,buffer,16);'
        protocol: !lambda 'char buffer [10];return itoa(data.protocol,buffer,16);'
        code: !lambda 'return data.code;'


# api:
#   services:
#     - service: send_rf_code
#       variables:
#         sync: int
#         low: int
#         high: int
#         code: int
#       then:
#         - rf_bridge.send_code:
#             sync: !lambda 'return sync;'
#             low: !lambda 'return low;'
#             high: !lambda 'return high;'
#             code: !lambda 'return code;'
#     - service: learn
#       then:
#         - rf_bridge.learn

# uart:
#   tx_pin: 1
#   rx_pin: 3
#   baud_rate: 19200

# logger:
#   baud_rate: 0

# rf_bridge:
#   on_code_received:
#     then:
#       - homeassistant.event:
#           event: esphome.rf_code_received
#           data:
#             sync: !lambda 'char buffer [10];return itoa(data.sync,buffer,16);'
#             low: !lambda 'char buffer [10];return itoa(data.low,buffer,16);'
#             high: !lambda 'char buffer [10];return itoa(data.high,buffer,16);'
#             code: !lambda 'char buffer [10];return itoa(data.code,buffer,16);'

# Example configuration entry
# uart:
#   baud_rate: 19200

# rf_bridge:
#   on_code_received:
#     - homeassistant.event:
#         event: esphome.rf_code_received
#         data:
#           sync: !lambda 'char buffer [10];return itoa(data.sync,buffer,16);'
#           low: !lambda 'char buffer [10];return itoa(data.low,buffer,16);'
#           high: !lambda 'char buffer [10];return itoa(data.high,buffer,16);'
#           code: !lambda 'char buffer [10];return itoa(data.code,buffer,16);'            
  # on_advanced_code_received:
  #   then:
  #     - homeassistant.event:
  #         event: esphome.rf_advanced_code_received
  #         data:
  #           length: !lambda 'char buffer [10];return itoa(data.length,buffer,16);'
  #           protocol: !lambda 'char buffer [10];return itoa(data.protocol,buffer,16);'
  #           code: !lambda 'return data.code;'



# api:
#   services:
#     - service: send_rf_code
#       variables:
#         sync: int
#         low: int
#         high: int
#         code: int
#       then:
#         - rf_bridge.send_code:
#             sync: !lambda 'return sync;'
#             low: !lambda 'return low;'
#             high: !lambda 'return high;'
#             code: !lambda 'return code;'
#     - service: learn
#       then:
#         - rf_bridge.learn

# ota:

# uart:
#   tx_pin: 1
#   rx_pin: 3
#   baud_rate: 19200

# logger:
#   baud_rate: 0

# rf_bridge:
#   on_code_received:
#     then:
#       - homeassistant.event:
#           event: esphome.rf_code_received
#           data:
#             sync: !lambda 'char buffer [10];return itoa(data.sync,buffer,16);'
#             low: !lambda 'char buffer [10];return itoa(data.low,buffer,16);'
#             high: !lambda 'char buffer [10];return itoa(data.high,buffer,16);'
#             code: !lambda 'char buffer [10];return itoa(data.code,buffer,16);'
# Basic Config

# Device Specific Config

# binary_sensor:
#   - platform: status
#     name: "RF Bridge Status"





# use esphome log viewer to get binary transmission for sensor state.  Below are examples when using either single state or dual state sensors.

# # use this for single state sensors (single trigger)
#   - platform: remote_receiver
#     name: "Sensor1"
#     rc_switch_raw:
#       code: '100110011100011010101001'
#       protocol: 1



# # use this for dual state sensors (open/closed trigger)
#   - platform: remote_receiver
#     name: "Sensor 2 Open"
#     internal: yes
#     rc_switch_raw:
#       code: '001111111110111100101110'
#       protocol: 1
#     on_press:
#       - binary_sensor.template.publish:
#           id: Sensor2
#           state: ON
#   - platform: remote_receiver
#     name: "Sensor 2 Closed"
#     internal: yes
#     rc_switch_raw:
#       code: '001111111110111100100111'
#       protocol: 1
#     on_press:
#       - binary_sensor.template.publish:
#           id: Sensor2
#           state: OFF
#   - platform: template
#     name: "Sensor2 State"
#     device_class: window
#     id: Sensor2


# remote_receiver:
#   pin: 4
# #  dump: all
#   dump: rc_switch
#   filter: 100us
#   tolerance: 50%
#   idle: 2ms

# remote_transmitter:
#   pin: 5
#   carrier_duty_percent: 100%

# status_led:
#   pin:
#     number: GPIO13
#     inverted: yes


# third section
# Example configuration entry
# uart:
#   baud_rate: 19200

# rf_bridge:
#   on_code_received:
#     - homeassistant.event:
#         event: esphome.rf_code_received
#         data:
#           sync: !lambda 'char buffer [10];return itoa(data.sync,buffer,16);'
#           low: !lambda 'char buffer [10];return itoa(data.low,buffer,16);'
#           high: !lambda 'char buffer [10];return itoa(data.high,buffer,16);'
#           code: !lambda 'char buffer [10];return itoa(data.code,buffer,16);'    