[SOLVED] ESP01S wifi module and relay - how to mount physical button?

Hi guys. I am close to finish my first DIY WiFi switch, made of ESP8266 WiFi module and ESP01S relay. I am planning to pack it to wooden box such a this, cause it will perfectly fit with my wooden lamp, hand made by me :slight_smile: (photos at the end of post). Regarding photos, please ignore:

  • USB controller - I’m using it now in test phase cause I have it, and it is easy way to supply power to the thing
  • Little white thing connected to switch - this is some Chinese camera from broken drone, I’m using it cause it is 5V and it have LED built in, so I can test the thing is it working.

Ok, I already flashed Tasmota (I like Tasmota :slight_smile: ) on WiFi module and whole software thing is working perfectly from web interface via IP addres - switch is turning on/off LED on connected camera. Integrate it later to HA will be easy, I’m already using some other switches flashed with Tasmota, in my HA instance.

TO DO (and reason for this post): I want to solder taster button (also on picture below), so I can have possibility to turn relay on/off from physical button as well (this is mostly because of my kids and wife :slight_smile: Currently I’m controlling this lamp from HA via WiFi wall plug, but this is useless when they turn it off with physical switch :slight_smile: ). Soldered button should act exactly the same as software switch, i.e. if someone turn off the switch via physical button, I should be able to turn it on from HA and vice versa.

Questions:

  1. What PINs should be shortened on WiFi module to make that relay change the state from on to off and vice versa, i.e. where should I solder button PINs?
  2. I have no very good knowledge about circuits, but I know to solder when someone tell me what and where :slight_smile: . I guess this should work as it is now, but is there some recommendation to put some resistor and/or capacitor (which ones and where), to make thing more safety, durable, etc?

Many thanks!

1 Like

You need to configure what pin to do that.
I’m not good enough with tasmota to give you an answer how to do that, but had it been ESP-Home then I could have helped.

Huh, I am so lazy to setup whole new thing only because of this, since already like Tasmota and it is working very well for such a simple task. Not using ESP-Home yet, but yes, I was meant several times to start exploring with it :slight_smile: No matter, thanks for reply, I hope someone will jump in with solution :slight_smile:

Maybe worth checking
Frenck’s Doorbell

He used GPIO2 for an addition button on a standard ESPHome relay
image

2 Likes

Will try after work and follow up, thx.

On first look, it seems to me that Frenck’s Doorbell example will hold circuit closed only until taster button is pressed and that circuit will open again right after button is released, maybe I’m wrong? I would need to shorten some PINs and to switch relay to another position permanently. And with next button press to switch relay to first position permanently, etc. if this is possible at all.

You just need to toggle the relay pin. Completely possible.

EDIT: Oh, do you mean on some of PINs where relay it self is soldered on board? It would be appreciated if you could tell me which one, I’m not sure can I broke something if try one by one :slight_smile: thx

Sorry for stupid question :slight_smile: , but what PIN is it?
* There are input PINs from the bottom, VCC and GND, these are for supplying relay board with power
* There are output PINs from the bottom, NO, COM and NC, these are for final device (normally open, common and normally closed)
* Or do you mean on some of PINs in yellow 8 PIN header?

You are too focused on hardware.
As I said before, you need to configure the ESP to do what you want.

Since you seem adamant on tasmota, then this is as far as I can help you.
I know there are people that is good at tasmota and they can probably do the syntaxes to configure, but that is out of my reach.

You need to do like the guide linked above bend out a pin to hook up the button to, and then it’s completely black for me with tasmota.

In ESP-Home, you would set up that pin as an sensor and on trigger switch the state of the output pin controlling the relay.

Ah, understand now that I misunderstood you in your previous post, sorry for that.

Seems to be some issues with these boards.

I already read regarding removing R2 resistor and solder CH_PD to 3.3V, and already read that topic as well. I think my case isn’t related with that, cause all of them had problems with booting if I remember good. I have no problems with software booting and operating at all - everything is working as expected. I just don’t know how to mount physical toggle button :slight_smile:

Ok, so, if this could be helpful…

Actually, my mistake was misunderstood of taster button I bought on Aliexpress :rofl:
Talking about these buttons, momentary self-reset, 12mm: 12/16/19/22mm Waterproof Metal Push Button Switch LED Light Momentary Latching Car Engine Power Switch 5V 12V 24V 220V Red Blue|Switches| - AliExpress
These of 12mm (I bought) are having 4 PINs, one marked with +, another one marked with - and 2x unmarked PINs. My mistake was that I meant + and - are PINs which opening/closing circuit :shushing_face:.
Of course most of you probably knows these PINs are for power supplying built-in LED and unmarked PINs are actually Normally Open and Common. So everything is working as it should work with Tasmota now. I soldered NO and COM button PINs to GPIO2 and GND on module and assigned “Button” function to GPIO2 inside Tasmota.

Not integrated to HA yet, cause I firstly want to make wooden case and mount it on lamp, but integration to HA will be easy part.

Final product - pure DIY:

Please ignore my double taps, it is little hard for me to record and clicking another screen same time :slight_smile:
In summary ~$4

Not really related with topic, but my wooden lamp got an upgrade to v2.0 :rofl:
Basic one color white LED strip had been changed with WS2812B, relay removed and Tasmota replaced with ESPHome:

hello
i know is late after last reply of this topic but i need to integrate this in HA .
i have tried this code

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

but the button does not work , instead gpio 2 acts like a touch button , when i touch gpio 2 with my finger it do the job but when shorted to ground is not.

please help ne with the code

thanks in advance

Never being late :rofl:
Few questions:

  1. Are you talking about ESP01s? (less matter)
  2. Are you trying to:
  • Turn on the “relay” by button click
  • Then, when relay turns on, wait half second and turn it off again? (That’s what I concluded from your on_turn_on automation. I think that you copy/pasted example from here, but it is just an example)

It would be good to explain in more details what you are trying to achieve (and which board/microcontroller you are using). If you are trying (but only if my prophecy is on right track :innocent:) to make a simple switch, which you will be able to control from both sides - from HA and with physical button switch, on ESP01s, then try this:

esphome:
  name: <your-name-here>

esp8266:
  board: esp01_1m

logger:

api:

ota:

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

captive_portal:

switch:
  - platform: gpio
    pin: 0
    id: relay
    name: "<Your Name Here>"
	inverted: true

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO2
      mode: INPUT_PULLUP
      inverted: True
    name: "<Your Another Name Here>"
    on_click:
      then:
        - switch.toggle: relay

(Sorry, I didn’t tested code above, cause currently I have only one ESP01s ESPHome “switchable” device, which is running muuuuch more complex code, and which btw have no switch component at all but light instead, but I reduced that complex code to minimum and believe above example should work)

hello , yes you are right , is about esp 01 and i need to add a momentary button like a doorbell , i a new to this and testing and trying to understand how it works.
now i got tested the toggle function and it seems that i can get rid of the delay .
thanks for quick reply , i will test the code and see what happens.

just got it !!!

captive_portal:

binary_sensor:
- platform: gpio
  pin:
    number: GPIO2
    mode: INPUT_PULLUP
    inverted: True
  name: "btn"
  on_press:
    - delay: 500ms
    - switch.toggle: relay_1
    

switch:
- platform: gpio
  name: "apasaL"
  pin: GPIO0
  id: relay_1
  inverted: True
  on_turn_on:
    - delay: 500ms
    - switch.turn_off: relay_1

this code works for me to have a momentary button (like a doorbell) that is integrated in HA and is also triggered when is pressed the button on gpio 2
Processing: 20230124_195027.mp4…


Cool. I am glad you accomplished your goal!