Node MCU - 4 Channel Relay Switch controlled with ESPHome

Hi guys , I couldn’t really find some concrete code on how to flash my Node MCU connected to a 4 channel relay switch currently running on Tasmota so after using integrating various codes off the ESPHome cookbook, here’s some code to help anyone who may be stuck :slight_smile:

esphome:
  name: 4-relay-switch

esp8266:
  board: nodemcuv2

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: 

ota:
  password: 

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: 
    gateway: 
    subnet: 

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "4-Relay-Switch Fallback Hotspot"
    password: 

captive_portal:

binary_sensor:
  - platform: gpio
    pin:
      number: D1
      mode:
        input: true
        pullup: true
      inverted: true
    name: "Button 1"
    filters:
      - delayed_on: 10ms
  - platform: gpio
    pin:
      number: D2
      mode:
        input: true
        pullup: true
      inverted: true
    name: "Button 2"
    filters:
      - delayed_on: 10ms
  - platform: gpio
    pin:
      number: D3
      mode:
        input: true
        pullup: true
      inverted: true
    name: "Button 3"
    filters:
      - delayed_on: 10ms
  - platform: gpio
    pin:
      number: D5
      mode:
        input: true
        pullup: true
      inverted: true
    name: "Button 4"
    filters:
      - delayed_on: 10ms
  - platform: status
    name: "Status"

switch:
  - platform: gpio
    name: "Relay 1"
    pin: 
      number: D1
      inverted: True
  - platform: gpio
    name: "Relay 2"
    pin: 
      number: D2
      inverted: True
  - platform: gpio
    name: "Relay 3"
    pin: 
      number: D3
      inverted: True
  - platform: gpio
    name: "Relay 4"
    pin: 
      number: D5
      inverted: True

You have inputs and outputs defined on the same GPIOs. That won’t work.

Do you have buttons connected to the device? If not get rid of the binary sensors.

Thank you , I do not have buttons , so is the output the switch function and input the binary sensor?

Correct. The switches will show up in Home Assistant.