ESP-01 mechanical switch

Hi everyone, recently I purchased this ESP-01. Before configurate it, I can control the relay on home assistant without any issue. But Trying to setup a mechanical switch it doesn’t toggle the relay status, can any one help me please, this is my code. Thanks in advance:

*Edit: I connected ground pin and the specified pin to the mechanical switch

esphome:
  name: prueba

esp8266:
  board: esp01 #also tried esp01-1m

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "mykey"

ota:
  password: "mypass"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Prueba Fallback Hotspot"
    password: "xxxxxx"

captive_portal:

switch:
  - platform: gpio
    pin: GPIO0
    name: "Luz_cocina"
    id: Luz_cocina
    inverted: True

binary_sensor:
  - platform: gpio
    pin: GPIO3
    id: Apagador
    internal: true

    on_press:
      then:
        - switch.turn_on: Luz_cocina

    on_release:
      then:
        - switch.turn_off: Luz_cocina

1 Like

There’s the problem.
GOIO0 should not be used, it’s used in the boot process of an ESP.

1 Like

On a ESP-01 you have probably made the best choices for pins. GPIO00 is a suitable output pin and GPIO03 is really the only safe choice for input pin.

Maybe post the log showing what happens when you push the button connected to GPIO03.

Also stick with the 2 digit pin schema - it will make your code more consistent when you use ESP32s.

Unfortunately I having other issues, the esp sometimes connect to my wifi, sometimes doesn’t. When it connects I can’t connect to it, always says that can not connect to the API, I think it is a esp hardware issue or deep sleep function (although I set power_save_mode:high )

Hello , new here , i allso want to add a phosical button and i got stuck .
The funny thing is ,if i touch gpio 2 and ground with my hand it do the job and trigger the gpio 0 and actuates the relay .
Don’t know why does not do the job from the button ?
Does anyone have suggestions?

Thanks in advance

captive_portal:

switch:

  - platform: gpio

    pin: 0

    id: relay

    name: "apasaL"

    inverted: true

    on_turn_on:

    - delay: 500ms

    - switch.turn_off: relay

binary_sensor:

  - platform: gpio

    pin: 2

    name: "btn"

    on_press:

      then:

        - switch.turn_on: relay

I made it work using tasmota, ESPHome didn’t work on any setup I tried