Wiring a button in ESPHOME(nodemcu)

Dear community

I have ‘killed’/fried my nodemcu (it has stopped responding ;-( ) and would like to understand what has gone wrong - and how to fix it… I have several nodemcu, but guess doing the exact same will just result in another brick :wink:

My goal - I have a big dog, and a gate in my front yard, to keep the dog inside. But the gate is not always shut, so I would like to know when it is open and closed.
So, using an esp8266/nodemcu with esphome, my plan is to add these sensors:
-door sensor, that registre when gate is open/closed.
-LED WS2812, to show status
-momentary push Button, to send signal
So door opens, if opened more than 8 seconds, backend gives signal (light or sound or message) inside. But sometimes it is needed to have the gate open for longer time, and here the push button - press that one, and the backing will react differently, maybe setting the LED at the gate at some color to show status.

So, this is what I have done:

  - platform: gpio
      number: D5
      mode: INPUT_PULLUP
    name: "FrontGate"
    device_class: door

(with one wire at D5 and the other at GND)
Works fine. Shows inside Home Assistant when gate is open and closed… And NodeRed can use it for rules.

  - platform: fastled_clockless
    chipset: WS2812
    pin: D3
    num_leds: 1
    rgb_order: RGB
    name: "FrontGate LED" 

Works also fine, I can control the light from HA, have not yet done automation.

(in the binary_sensor: section)

  - platform: gpio
      number: D1
      mode: INPUT_PULLUP
    name: "FrontGate Button"

This is where it all stopped.
I have no electronic skills - would like, but it is still a bit of a mystery. I have looked all over for descriptions of wiring of buttons with esphome, but did not really find anything. But found stuff that looked like it was for ardruino (must be the same). Here resistors where used (don’t like to mess around with that, and to my luck, some wrote that on nodemcu, that instead of resistores you can just use the internal resistor by defining a ‘PULLUP’ - hope thats what I have done.

I tried to wire the momentary push button between 3.3v and D1 - did not react in the log window in esphome.
Unpowered and rewired to GND and D1 - and now it shows in the log - it says Open and Closed (as I remember) when pushing the button. Looks okey - something to work with.
But I pushed the button like 50 times, and it all stopped. Could not get the nodemcu to respond any more. Power Supply is okay. Guess the nodemcu is toasted.

Now, I guess my button has been wired wrongly. Do I need a resistor ? what about PULLUP ?
Can someone with a bit more understand explain what has gone wrong here ?



Hi Community

No one knows this ?
If this is the wrong place to ask these questions, then please direct me to a forum for these questions :wink:


Well it may be more a general electronic/microcontroller question.

Hi Team…
Did have a discord discussion, where the conclusion where, that I had build it the right way.
So, I have build another one, and it works.
So, now I have a box with both gate sensor, push button and LED light - all works nice.



1 Like

Hi! Can you share how you connected it?

Yes - very simple.
The button is a momentary push button - one that doesn’t lock into state, but only changes when you push it.
My version only has 2 pins, and here I have soldered some wires which are connected to D1 and GND (using a nodemcu).
And then the code listed above with ‘mode: INPUT_PULLUP’

works fine :wink: