ESPHome switch not showing up

Hello! I am having a problem with my GPIO switch not showing up as an entity in HA. Can anyone help me? Thanks!

Code:

esphome:
  name: garage_door_opener
  platform: ESP32
  board: nodemcu-32s

logger:

wifi:
  ssid: "SSID"
  password: "PASS"

api:

switch:
  - platform: gpio
    pin: 22
    id: garage_door_button

script:
  - id: trigger_garage_door
    then:
      - switch.turn_on: garage_door_button
      - delay: 3s
      - switch.turn_off: garage_door_button

LOGS:

INFO ESPHome 2024.4.0
INFO Reading configuration /config/esphome/gatekeeper.yaml...
WARNING 'garage_door_opener': Using the '_' (underscore) character in the hostname is discouraged as it can cause problems with some DHCP and local name services. For more information, see https://esphome.io/guides/faq.html#why-shouldn-t-i-use-underscores-in-my-device-name
INFO Starting log output from 192.168.1.39 using esphome API
INFO Successfully connected to garage_door_opener @ 192.168.1.39 in 0.103s
INFO Successful handshake with garage_door_opener @ 192.168.1.39 in 0.025s
[14:49:11][I][app:100]: ESPHome version 2024.4.0 compiled on Apr 22 2024, 14:04:26
[14:49:11][C][wifi:580]: WiFi:
[14:49:11][C][wifi:408]:   Local MAC: C0:49:EF:6B:EA:68
[14:49:11][C][wifi:413]:   SSID: [redacted]
[14:49:11][C][wifi:416]:   IP Address: 192.168.1.39
[14:49:11][C][wifi:420]:   BSSID: [redacted]
[14:49:11][C][wifi:421]:   Hostname: 'garage_door_opener'
[14:49:11][C][wifi:423]:   Signal strength: -59 dB ▂▄▆█
[14:49:11][C][wifi:427]:   Channel: 6
[14:49:11][C][wifi:428]:   Subnet: 255.255.255.0
[14:49:11][C][wifi:429]:   Gateway: 192.168.1.1
[14:49:11][C][wifi:430]:   DNS1: 1.1.1.1
[14:49:11][C][wifi:431]:   DNS2: 8.8.8.8
[14:49:11][C][logger:166]: Logger:
[14:49:11][C][logger:167]:   Level: DEBUG
[14:49:11][C][logger:169]:   Log Baud Rate: 115200
[14:49:11][C][logger:170]:   Hardware UART: UART0
[14:49:11][C][switch.gpio:068]: GPIO Switch 'garage_door_button'
[14:49:11][C][switch.gpio:091]:   Restore Mode: always OFF
[14:49:11][C][switch.gpio:031]:   Pin: GPIO22
[14:49:11][C][mdns:115]: mDNS:
[14:49:11][C][mdns:116]:   Hostname: garage_door_opener
[14:49:11][C][api:139]: API Server:
[14:49:11][C][api:140]:   Address: garage_door_opener.local:6053
[14:49:11][C][api:144]:   Using noise encryption: NO

I basically need to power on a pin on my ESP32 board for 3 seconds, to activate my garage door remote, thats it, but the switch entity is not begin detected.

If you only give your switch (or any component) an id and not a name it will be internal to the ESP only and not shared with HA.

Give it a name and it will show up in HA:

switch:
  - platform: gpio
    pin: 22
    id: garage_door_button
    name: Garage Door Button

Note there is a better way to do this. Delete the switch and script and use a button instead.

output:
  - platform: gpio  # Internal to the ESP
    pin: 22
    id: garage_door_button

button:
  - platform: output # Shared with HA. 
    name: "Garage Door"
    output: garage_door_button
    duration: 3s # does it really need to be pressed this long?

But now I am seeing with the button solution, that pin 22 or “D22” on the board is powered on, not doing anything when I press the button, it should only be powered on if someone presses the button in HA, and also then for 3 seconds.

esphome:
  name: garage_door_opener
  platform: ESP32
  board: nodemcu-32s

wifi:
  ssid: "SSID"
  password: "PASS"

api:

output:
  - platform: gpio
    pin: 22
    id: garage_door_button

button:
  - platform: output
    name: "Garage Door"
    output: garage_door_button
    duration: 3s
  • internal (Optional, boolean): Mark this component as internal. Internal components will not be exposed to the frontend (like Home Assistant). Only specifying an id without a name will implicitly set this to true.

It applies to all & any components, so far I know.

Hello fellow people!

I am currently making a system where I can control my old garage door system, by doing some soldering on my remote and the ESP32 board, and I have got it working so if I power pin 22 on my remote, the door opens.

I am seeing, that pin 22 or “D22” on the board is powered on, not doing anything when I press the button, even tough it should be only powered when the button is pressed and also then for 2 seconds.

Can someone help me? Code is attached below.

esphome:
  name: garage_door_opener
  platform: ESP32
  board: nodemcu-32s

wifi:
  ssid: "SSID"
  password: "PASS"

api:

output:
  - platform: gpio
    pin: 22
    id: garage_door_button

button:
  - platform: output
    name: "Garage Door"
    output: garage_door_button
    duration: 3s

LOGS:

INFO ESPHome 2024.4.0
INFO Reading configuration /config/esphome/gatekeeper.yaml...
WARNING 'garage_door_opener': Using the '_' (underscore) character in the hostname is discouraged as it can cause problems with some DHCP and local name services. For more information, see https://esphome.io/guides/faq.html#why-shouldn-t-i-use-underscores-in-my-device-name
INFO Starting log output from 192.168.1.39 using esphome API
INFO Successfully connected to garage_door_opener @ 192.168.1.39 in 0.092s
INFO Successful handshake with garage_door_opener @ 192.168.1.39 in 0.016s
[16:43:09][I][app:100]: ESPHome version 2024.4.0 compiled on Apr 22 2024, 16:38:17
[16:43:09][C][wifi:580]: WiFi:
[16:43:09][C][wifi:408]:   Local MAC: C0:49:EF:6B:EA:68
[16:43:09][C][wifi:413]:   SSID: [redacted]
[16:43:09][C][wifi:416]:   IP Address: 192.168.1.39
[16:43:09][C][wifi:420]:   BSSID: [redacted]
[16:43:09][C][wifi:421]:   Hostname: 'garage_door_opener'
[16:43:09][C][wifi:423]:   Signal strength: -42 dB ▂▄▆█
[16:43:09][C][wifi:427]:   Channel: 6
[16:43:09][C][wifi:428]:   Subnet: 255.255.255.0
[16:43:09][C][wifi:429]:   Gateway: 192.168.1.1
[16:43:09][C][wifi:430]:   DNS1: 1.1.1.1
[16:43:09][C][wifi:431]:   DNS2: 8.8.8.8
[16:43:09][C][logger:166]: Logger:
[16:43:09][C][logger:167]:   Level: DEBUG
[16:43:09][C][logger:169]:   Log Baud Rate: 115200
[16:43:09][C][gpio.output:010]: GPIO Binary Output:
[16:43:09][C][gpio.output:011]:   Pin: GPIO22
[16:43:09][C][output.button:010]: Output Button 'Gate'
[16:43:09][C][output.button:011]:   Duration: 3.0s
[16:43:09][C][mdns:115]: mDNS:
[16:43:09][C][mdns:116]:   Hostname: garage_door_opener
[16:43:09][C][api:139]: API Server:
[16:43:09][C][api:140]:   Address: garage_door_opener.local:6053
[16:43:09][C][api:144]:   Using noise encryption: NO

You mean pin 22 always providing power (state on) after board is powered on ?
Would be nice to have debug output to see styte changes of button & output.

logger:
  level: DEBUG

Added logs

I’ve used a switch for this purpose and it it works well.

switch:
  - platform: gpio
    pin: 
      number: GPIO14 # D5
      mode: output
      inverted: true
    id: north
    name: "Garage Door North Button"
    icon: "mdi:garage"
    on_turn_on:
    - delay: 500ms
    - switch.turn_off: north

Also while button pressed too, not only configuration.

22 is not the same as D22.

You do realize that 22 (which is short for GPIO22) is not the same as D22.

There was no need to start a new topic about this. I have merged them.