Esp32 two wire contact (similar as water leak)

Hi!

I searched allover the internet, I didn’t found nothing exactly for what I need to achieve, maybe some of you already know, if yes, please share your information.
I have an ESP32 board and two wires of 3 meters each, connected to a manual wall switch.
How can I do something that ESP32 will know when those two wires are connected or not? I want that the ESP32 board to know when this manual switch it is activated (when two wires are connected). I think that this is something similar with the water leak.
Any idea how to achieve this?
On what pins I should connect those two wires and what is the ESP code for this?

Thank you!

If I understand correctly, you just need something which is essentially the same as an endstop switch, or physical button, and you don’t have any power loads involved with this.

In this case, you would typically use a gpio binary sensor, with one wire connected to ground on the esp and the other connected to a gpio (pick a good one).

I’m not sure how it will go with the length of wires you are using, but you can try…

1 Like

Yes, you are right, no power loads, nothing…
I will try, thank you!

I have done the sensor, it is working.

Another thing now :smiley: … How can I make a led light up from the board (devkitv1), when the state is “on” ?

Thanks

Edit: I done it with

    on_state:
        then:
          - switch.toggle: onboard_led
1 Like

You may want to change to having an on_press trigger with a switch.turn_on and a on_release trigger with a switch.turn_off.

This will guarantee the led stays syncronised with the state of your physical switch (if that’s what you want).

I have tried with the on_press but didn’t work :frowning: Thats why I chosed the on_state.
Now, everytime the sensor have the “on” state, the led is turning on as well… Which is good for me.
I should be worry using on_state ?

If it works, then maybe just leave it. If you find the light is getting out of sync with the state sometimes, then you might need to revisit it.