ESP32 and Relay act as push button

Hello,

    I try to make a simple push button with an esp32. What i want to do is when I push the button the relay give a signal to an relay step by step and turns the light on.

    The problem is that ... when I write the code the relay is energized ... and it turns the light on or off. What i must do to eliminate the energhize 

My code …

output:
  - platform: gpio
    id: relay_output1
    pin: 
      number: 17  # GPIO pin connected to relay 1
      inverted: false
  - platform: gpio
    id: relay_output2
    pin: 
      number: 18  # GPIO pin connected to relay 2
      inverted: false

switch:
  - platform: gpio
    id: id1
    pin: 
      number: 16
      inverted: true
    restore_mode: DISABLED
    name: "Relay 1 Switch"  # Name for the switch controlling relay 1
    on_turn_on:
      - output.turn_on: relay_output1
      - delay: 100ms
      - output.turn_off: relay_output1
    on_turn_off:
      - output.turn_on: relay_output1
      - delay: 100ms
      - output.turn_off: relay_output1
      
  - platform: gpio
    id: id2
    pin: 
      number: 19  # Replace this with the GPIO pin for the second switch
      inverted: true
    restore_mode: DISABLED
    name: "Relay 2 Switch"  # Name for the switch controlling relay 2
    on_turn_on:
      - output.turn_on: relay_output2
      - delay: 100ms
      - output.turn_off: relay_output2  # Turn off relay 2 when switch is deactivated
    on_turn_off:
      - output.turn_on: relay_output2
      - delay: 100ms
      - output.turn_off: relay_output2

Can you explain what that technically means?

You can physically wire the button to the relay and trigger it through physical means or you can do it all through code in Esphome, and you can do it so both options are usable to you…

Are you switching a mushroom!? :rofl:

1 Like

:grinning: I wanted to make a bulb …

1 Like

I see a relay module connected to another relay with a button or sensor connected to it.
What would you like this setup to do? Is that Finder some come kind of sequence-relay?

I don’t want to integrate another module for lights. So I use the switch as a push button, and the relay. I can use it mechanical … or with the relay. In this mode the relay I use give just an impulse to the finder (step by step relay 27.01.8.230 code). This way nothing is under tension and the lifespan is longer.

But my problem is the esp. I think I can use the ESP8266 … I read that is not having the restart on boot

So is your problem just the boot? Or?
Esp8266 is not resolving anything, opposite!

My problem is … when I write, update or modify the code it gives an impulse to the relay and I will find myself with the light on …

The same problem I have also with a 90 degree servo, that I want to close an 3/4 inch ball valve. General valve of the house.

SCHEMATIC.
Not pictures
Not Fritzing crap

Your description is borderline gibberish. If English is a challenge (it sometimes is for me, too). Just list the steps you want to accomplish one line at a time and indicate where the circuit doesn’t do what you want it to.

You have weird setup on your code. There are two GPIO Switches that switch two GPIO Outputs, which doesn’t make sense. Four gpios all together…

Yes the coding is not my forte point. I’m more a mechanical :disappointed:

For my opinion the circuit it is ok. What is not ok for me, is when I update the code in ESP, it gives an impulse to the relay. What I want, is to change the code to stop the relay for operating when I update/modify the code.

And i’m asking the experienced persons for an advice.

Sorry for my english.

I’m not experienced person and my english is bad as well, but if you only have one relay like on your circuit drawing you only need one gpio switch and nothing else. No gpio output needed.

switch:
  - platform: gpio
    id: id1
    pin: 
      number: 19
      inverted: true
    restore_mode: DISABLED
    name: "Relay 1 Switch"  # Name for the switch controlling relay 1
    on_turn_on:
    - delay: 100ms
    - switch.turn_off: id1

So connect your relay module to gpio19 and the esphome virtual switch gives 100ms pulse every time you press it.

Then if it triggers on boot, it’s easier to work with.

1 Like

Ok. but this is the problem. I do not want to trigger on boot. I want to trigger only when I give the command.

I understand this trigger on boot is a test of the command I write.

Did you try what @Karosm suggested and found it didn’t work?

I tray this and not working

captive_portal:

output:
  - platform: gpio
    id: relay_output1
    pin: 
      number: 17  # GPIO pin connected to relay 1
      inverted: false

switch:
  - platform: gpio
    id: id1
    pin: 
      number: 19
      inverted: true
    restore_mode: DISABLED
    name: "Relay 1 Switch"  # Name for the switch controlling relay 1
    on_turn_on:
    - delay: 100ms
    - switch.turn_off: id1

You don’t need that output component.
Try
restore_mode: ALWAYS_ON

If that gives opposite behavior try ALWAYS_OFF (I don’t remember if restore_mode counts the option inverted or not…)