ESP32 and Relay act as push button

Not an expert on this and the docs are less than easy to understand but you really should look at switch, binary_sensor, and output. Switch has multiple meanings in English, but it is not the right component to use for the noun. It does the verb meaning of switch, it is an output (from what I understand).

I believe your push button should be using the binary_sensor component

Your relay which controls the remote should be a switch

Output is probably best left for something else.

Where exactly to put the logic for the pulse you need might not matter, but I would put it like @Karosm showed.

You need one GPIO for the push button and one other one for the relay. Make sure you are clear which is which and that you use ones that won’t cause an issue on startup (ones that are not output during startup and also have the right default state).

If I understood OP, he wanted the push button to be wired directly to Finder.

The picture does indicate that, but the code does not.
@NituN you really need to try again and describe what you are really trying to do and how you have things wired up.

It seems like you might be making things more complicated than they need to be.

1 Like

Ok. How I want it to work.

  1. When I use the contact the finder relay will turn the light.
  2. When I use the home esp32 and relay the finder relay will turn the light ok.

So I can use the contact or the switch the light work.

The initial code that works is:

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

switch:
  - platform: gpio
    id: id1
    pin: 
      number: 16
      inverted: true
    restore_mode: ALWAYS_OFF
    name: "relay 1"  # Name for the switch controlling relay 1
    on_turn_on:
      - output.turn_on: relay1  # Turn on relay 1 when switch is activated
    on_turn_off:
      - output.turn_off: relay1  # Turn off relay 1 when switch is deactivated

  - platform: gpio
    id: id2
    pin: 
      number: 19  # Replace this with the GPIO pin for the second switch
      inverted: true
    restore_mode: ALWAYS_OFF
    name: "relay 2"  # Name for the switch controlling relay 2
    on_turn_on:
      - output.turn_on: relay2  # Turn on relay 2 when switch is activated
    on_turn_off:
      - output.turn_off: relay2  # Turn off relay 2 when switch is deactivated

But when I press, the relay stays on. Not with a delay. An at boot I do not have a test of the code. Hope to be understood.

I’m repeating myself here, but you don’t need output components. This is Enough.

switch:
  - platform: gpio
    id: id1
    pin: 
      number: 19
      inverted: true # or false for high side trigger
    restore_mode: ALLWAYS_ON # Or ALLWAYS_OFF
    name: "Relay 1 Switch"  # Name for the switch controlling relay 1
    on_turn_on:
    - delay: 100ms
    - switch.turn_off: id1

If that code doesn’t trigger the relay correctly, there are two options:
-your relay module has high side trigger and you need to set inverted: false
-your relay module is wired incorrectly and it never turns off because it can’t.

Feel free to post a good photo presenting how relay module is wired to Esp.

See those yello jumpers on your relay? One side sais “H” and the other sais “L” ?? Thats for High and Low and its referencing the relay trigger and you can set it so either a Low signal or a High signal are what triggers the relay.

Right now you have both set on High(H) and your also using gpio as inverted…

You need to turn the inverted Off

- platform: gpio
    id: id1
    pin: 
      number: 19
      inverted: false