Nodemcu momentary push button (gate)

So I am trying to use my nodemcu with my slide gate remote. I have soldered the wires, and have them connected at D2 and GND. I create the node in esp home (code below) and it appears as the device and entity when I upload via USB to the nodemcu. However, when I click on the entity, the gate does not open (the gate remote has a small red led, which flashes when pressing the button physically or when I disconnect one of the pins from nodemcu and reconnect it again). What am I doing wrong here?
I tried using GPOI id: 4, instead of the id: D2. I tried installing the node without the change of BAUD rate, but still no result (I have it set to 9600, because it says so on the actual nodemcu).

esphome:
  name: node_of_gate
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: "secret"
  password: "secret"
  manual_ip:
    static_ip: 10.0.0.33
    gateway: 10.0.0.1
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Gate Node Try Fallback Hotspot"
    password: "RJwzzzzHn7ED"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

switch:
  - platform: gpio
    pin: D2
    id: relay
  - platform: template
    name: "Gate Remote"
    icon: "mdi:gate"
    turn_on_action:
    - switch.turn_on: relay
    - delay: 500ms
    - switch.turn_off: relay

uart:
  tx_pin: D0
  rx_pin: D1
  baud_rate: 9600

why do you need UART if you only use pin D2?

Yesterday I had issues with UART and it was solved by either disabling logger or having logger at UART1:

logger:
  hardware_uart: UART1

See post: SDS011 or UART bug?

Like I said in the original post, I have tried with both UART and without. No help.

Did you measured the voltage across the button? Maybe it needs more than 3.3 volts. Otherwise you could bridge the button with a relay and control the relay with the esp. That should work in almost every case.

Yes, there is enough voltage. The button led does light up when I disconnect and reconnect either of the pins to the nodemcu, and the gate starts opening. It just does not control from HA, I feel like I am missing something in the configuration, but I do not know what. I have also tried multiple nodemcu’s, same result.

  • I still don’t know what you need UART for?
  • Does it work if you connect the cable that leads to D2 to 3.3v instead of D2?
  • You could try to hook up a led to d2 to see if it gets switched.

I did a momentary switch with this:

switch:
  - platform: gpio
    pin: GPIO12
    id: relay
    name: computer
    on_turn_on:
      - delay: 500ms
      - switch.turn_off: relay
  • I removed that part
  • I am sorry I did not understand this - did you mean connecting to D2 and 3.3v instead of D2 and GND?
  • I tried connecting led to D2 and GND, it does work - led turns on and then turns off.

I appreciate your help. Any ideas why it does not work with my remote?

The fact that the remote is only triggering if you reconnect the cable could have many reasons. For example a capacitor that charges up if you disconnect the cable, and discharges if you connect again. But if you have the cable connected it can’t charge.
You can try to bridge the button to test if a relay would work.
Also some pictures of the remotes circuit could help.

I meant that you could connect the cable from (remote > D2) to (remote > 3.3v).
But as the D2 pin lights up the led that shouldn’t work either.

How would i try to bridge the button to test? I am sorry I am probably annoying you, but this is my first ever try with a nodemcu and its confusing as hell.

You bridge them by connecting both pins with a wire.(so the switch isn’t part of the circuit)


Also I don’t know if those two are the right ones as there are 5 pins.
Another attempt would be to install the esp directly to the receiver sou you don’t have to use the remote at all.

You dont see the other ends of the wires, but i can connect them there with another double pin wire. Same thing happens - led turn on for about 5 seconds and the gate starts opening, then the led shuts off. If i disconnect and reconnect the wire its all the same again.
I assume by receiver you mean inside the gate motor. I will try that only as a last resort because I would break my warranty.

As a stupid solution i thought of this - i power the nodemcu via usb brick, put that brick into a smart outlet that is off. Then make an automation that turns on the outlet, delay 1sec, turn off outlet. It would work, but not the best solution :slight_smile:

Please don’t do that! :joy:
Use two relays like these:


(Make sure they can be controlled with 5v)

Connect one relay to the first button and the other to the other button.
Each relay has 3 terminals:

  • NC > (normally closed) you don’t need this one
  • COM > one cable of a button
  • NO > (normally opened) other cable of the button

At the other side you have 4 pins:

  • GND > (ground) to gnd on the node mcu
  • IN1 > to D2 Pin or any other digital output
  • IN2 > to D3 Pin or any other digital output
  • VCC > to 5v of the mcu

With the thre pins VCC, VCC, GND you can change if the relay turns on if there ist voltage at the IN pin or, when it is pulled to ground. You can leave it to VCC, VCC

As an alternative you could use a sonoff 2CH/dual channel and use it with the sonoff integration or flash it with ESPhome. You don’t need your nodemcu for this solution as an esp is already build in, but the relay solution is cheaper and easier. (Flashing with an UART/FTDI adapter isn’t hard as well)

I only need the one button because I only have the slide gate and no garage or anything like that. Anyway thank you very much kind sir for your help. I think I will either buy a sonoff wifi switch and just control it outside HA or just use my stupid solution with the socket :smiley:

for a sonoff I would use one of these:


as it operates at 5v so you don’t have to handle with mains.

And as I said, there is a sonoff integration to easily use it with HA

Thank you for the help. I ended up ordering a couple 5v single channel relays. When you said connect vcc to the 5v of nodemcu, you mean the vin on the nodemcu is the 5v, right?

Yes, except you have an additional VU pin then use that one.

  • VU Pin (if available)
  • Vin Pin (if no VU available)

But search for yourself, there are plenty of information and videos about controlling a relay with an esp and similar micro controllers.

Okay, thanks mate. I will reply to this topic next week when I get the relay and test it out. Stay safe.

What voltage is that battery ? I powered my remote from the ESP.

Are you sure the wires are soldered correctly? If you connect the end of the wires together, does your remote react ?

Battery is 12v. Yes of course it gives reaction. The led lights up, gates start opening, led lights off after like 5-6 seconds. These are definitely the correct wires because no other two pins give out any reaction.

I’d find a 12V adapter and buy a shelly. Power the remote and the shelly from the 12V supply, and hook the wires up to the relay. Costs you like 15$.