Relay channel module buzzing sound

I have setup an ESP8266 D1 mini NodeMCU with a 1 channel relay module to interrupt power. It’s working fine. My little issue is the relay does not start properly when power is first plug in to the ESP8266. It has a buzzing sound and it looks as though it turned itself on. The only way for the relay to work is not have the output line plug into the esp during a cold startup.

Is there a setting in esphome that can delay sending power to the relay before the esp has boot up fully or my setting below can be improve to prevent this? My concern is if there was a power outage and I am not at home when the power is back on to manually fix that buzzing sound.

substitutions:
  name: toilet_airfreshener
  platform: ESP8266
  board: nodemcuv2

esphome:
  name: $name
  platform: $platform
  board: $board

wifi:
  ssid: 'rice'
  password: !secret ssid_pass
  fast_connect : true
  power_save_mode: none
  manual_ip:
    static_ip: 192.168.1.89
    subnet: 255.255.255.0
    gateway: 192.168.1.1

captive_portal:

logger:

api:
  password: !secret ota_pass
ota:
  password: !secret ota_pass

switch:
  - platform: gpio
    name: $name
    id: relay
    pin: D4
    icon: mdi:spray
    restore_mode: ALWAYS_OFF
    on_turn_on:
      - delay: 12s
      - switch.turn_off: relay

sensor:
  - platform: wifi_signal
    name: $name wifi signal

binary_sensor:
  - platform: status
    name: $name status

  - platform: gpio
    pin: D5
    name: 'motion tr1 occupancy'
    device_class: motion

D4 is a poor choice of GPIO to use. See the table lower down on this page: ESP8266 Pinout Reference: Which GPIO pins should you use? | Random Nerd Tutorials

1 Like

Thanks for the reference. Of all the pins I can choose, I chose the wrong one D4 for a relay module.

These are suggested pins to use for relays. I ended up using D1. No more buzzing sound from a cold start.