esphome:
  name: port-expander
  friendly_name: Arduino Port Expander

#-----------------------------------------------
  includes:
      - arduino_port_expander.h
#-----------------------------------------------

esp8266:
  board: nodemcuv2


# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "/P6cevEpmOPivhpqgy0DkSEVsseB4iqh8J1vEbpj9vk="

ota:
  - platform: esphome
    password: "85e740a543cd965ed8e036290f1f5345"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Port-Expander Fallback Hotspot"
    password: "COvHtD6Yamjw"

captive_portal:

# ------------------------------------------------------------
# ------------------------------------------------------------
# ------------------------------------------------------------

# Arduino ->  ESP  (NodeMCU v3)
#-------------------------------
# A4      ->  GPIO4 (D2)
# A5      ->  GPIO5 (D1)
i2c:
  id: i2c_component  

custom_component:
  - id: ape
    lambda: |-
      auto ape_component = new ArduinoPortExpander(i2c_component, 0x08, true);
      return {ape_component};

# ------------------------------------------------------------

binary_sensor:
  - platform: custom
    lambda: |-
      return {
              ape_binary_sensor(ape, 9), //  9 = GPIO9  = 9
              ape_binary_sensor(ape, 14) // 14 = GPIO14 = A0
             };

    binary_sensors:
      - id: binary_sensor_1
        name: Binary Sensor 1
        filters:
          - invert:
            
      - id: binary_sensor_2
        name: Binary Sensor 2
        filters:
          - invert:
# ------------------------------------------------------------

sensor:
  - platform: custom
    lambda: "return {ape_analog_input(ape, 1)};"   # 1 = A1 (von A0-A7, au�er A4/A5, da diese f�r I2C verwendet werden)

    sensors:
      - name: Feuchtigkeit
        id: feuchtigkeit

        filters:
          - calibrate_linear:
            - 0  -> 100
            - 1023 -> 0

# ------------------------------------------------------------

output:
  - platform: custom
    type: binary
    lambda: |-
      return {ape_binary_output(ape, 3),
              ape_binary_output(ape, 4)};
    outputs:
      - id: output_pin_3
        inverted: false

      - id: output_pin_4
        inverted: false


switch:
  - platform: output
    name: Switch pin 3
    output: output_pin_3

light:
  - platform: binary
    name: Switch pin 4
    output: output_pin_4