Looking for a switch/relay that detects 12v => to a sensor

@sparkydave

my esp2866 arrived :slight_smile:
can you share that little code , to configure an esp2866 gpio as INPUT to read 3,3v to and to trigger a sensor?
also question, i was looking at resistor, why did you configure as output 3V and not 3,3V ? i changed that second resistor to 3,8 ?

anyway, if i have my breadbord ready, gonna make a picture :slight_smile:

btw, is it also possible to simulate that button press? can i take whatever 3.3v output pin, and connect it to an configured input pin (for 2 sec), to simulate? i see 3 x gpio output pins that are 3.3v , not sure if those need to be enabled first though, does it mather witch gpio pin i choose, i see several gnd 3.3v output pins

thnx

after reading some more, i think i need to configure just this, seems only a0 pin can read a voltage?

probably i need to setup update interval to 1 sec, since i only have like 3,3 v for 2 seconds when doorbell is pressed?
but seems it can only read voltages from 0,0 to 1,0 ? do i need to change the resistors?

sensor:
  - platform: adc
    pin: A0
    name: "doorbell"
    update_interval: 1s

EDIT EDIT , disregard this text above , i think i amtotally wrong, i just need to enable another pin like D2 , D5, D6 (green ones according to this image) to INPUT mode , thats it i think ?

binary_sensor:
  - platform: gpio
    pin:
      number: D2
      mode: INPUT_PULLUP
    name: ...

not sure what mode i need to use, input, input_pullup , input_pulldown

You just need to know if the button was pressed
So a digital yes/no on/off is perfect
People above have given you several methods to achieve this
Why are you now looking at analogue circuitry ?

yeah, i was wrong, i edited my last reply, thats makes sense right?

i just need this config? thats all ? not sure about what input mode i need to choose?
actually i just need to read that 3,3 voltage, thats happening for 2 sec when my doorbell is pressed

binary_sensor:
  - platform: gpio
    pin:
      number: D2
      mode: INPUT_PULLUP
    name: doorbell_pressed

I made it 3v because there is a chance that the 12v from the doorbell will fluctuate a little and you don’t want it going over 3.3 at all as it will damage the ESP. the input will work fine at 3v.

Code coming soon

Here is an example code snippet from one of my ESP projects

esphome:
  name: ha_retic_controller_1
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: 192.168.0.61
    gateway: 192.168.0.1
    subnet: 255.255.255.0

api:

logger:

web_server:
  port: 80

ota:
  password: !secret ota_password


binary_sensor:
  - platform: gpio
    name: "Retic Bore Running"
    pin: 
      number: D8
      inverted: false
      mode: INPUT_PULLUP

  - platform: status
    name: "Retic Controller Status"

There is more code to it but nothing you need for your project.

Seems indeed simple :wink:
But I think D8 is wrong, in that pin image a few post back, d8 is output only? Think d7 is better?

ok, hooked up, confgured like below
no wires, transistors yet on the breadbord, just want to test it

so i can wire from a 3v3 pin to d7 , that should trigger my binary sensor right? but i also need to connect the gnd pins? how can i quickly test from the board ,
so 3v3 pin to D7 , and the gnd ?

EDIT: nm, hooked up a battery, works :slight_smile:

binary_sensor:
  - platform: gpio
    name: "Doorbell"
    pin: 
      number: D7
      inverted: false
      mode: INPUT_PULLUP

Guys, got it all working now, thnx for all the feedback , really appreciated!!
at the end it was all quite simple :stuck_out_tongue:

Yeah, I think the first 3 responders thought it was gonna be easy too. :crazy_face:
Who did you mark as the solution?

Marked the image as a solution :wink:

@sparkydave @Mutt @francisp

thnx a lot for your help, my smart doorbell is up and running stable for 20 days, with that esp 8266 chip!!
now i have a rasperry for testing purposes, cause i was also cable to capture the camera feed with the USB from raspberry, so basicly i want to ditch the esp8266 for now

so with code below and the remote gpio i also created a binary sensor, its also default pull up
when i ring the door, the sensors goes from on to off , working the same as the esp8266
BUT
seems its not always triggering … first 5 times it works, then it stops it seems , so for now i am using the esp 8266 …

is it maybe because only 3.0 V ? because you choose the resistors 10 kohm and 3.3 kohm to convert 12.0 V to 3.0 v ?
then i replace the 3.3 resistor with a 3.8 resistor?

binary_sensor:
  - platform: remote_rpi_gpio
    host: !secret raspberry
    ports:
      18: doorbell

Fabio, please be careful tagging people like that, some consider it spamming. Taras (for example) has blacklisted them for it.
Regarding using gpio on an HA pi machine please read the following thread including both links from Tom_l : -

There is a known problem.

Edit: but I now see you are part of another thread discussing this very issue. If you manage to get a solution, @Misiu for one, would appreciate it. :smile:

yeah, i saw that thread also , but thats another component , they are using a PI with HA on , so local
also that threat is for a quick change, my change is like 1-2 sec, thats more then a quick change i thin, they are talking about less then 1 sec …, mine is more :slight_smile:
i am using the remote gpio … stange thing is that it works a few times , when i test, but after a while , like 15 min, if i do the test again, i dont see the binary sensor changing anymore , so disabled it then, no further testing done at that point

am i correct about the 3.0 vs 3.3 v ?

sorry for tagging!

Fabio, I don’t mind the tagging some others do, dunno why
According to the pi docs anything above 2.7v as an input is a sure lock.
So 3.0 should be more than adequate.
You did connect the grounds together didn’t you?
Not sure why it would ‘sometimes’ and sometimes not.
Remind me do you still need the 12v ie does it also ring the bell ?
I bet your wife is happy that it sometimes doesn’t work if not (:rage:)
If no bell, you could ditch the 12v, use a defence resistor (I’m paranoid) set the gpio to pull itself up and use the bell button just to short it to earth. Though SOMEBODY must have tried that before.
It’s a puzzle, good luck solving it

what do you mean by : connect the grounds together?
if you look in image below, indeed the the cable below from resitor r2 goes to a groudpin on the RPI
the bell still rings inside, thats normal , that still works offcourse, but on my intercom indoor, with the digitall bell, on that intercom is an option to configure an EXTRA doorbell, that i dont have/need, so its my inside intercom, that gives 1-2 sec 12 v on an output GPIO pin, those outputs are then routed to my gpio pins (with resistor schema) to my gpio of the rpi …

the first photo below, where you see the sw+, sw-,extring, gnd, video, those are also gpio pins,i am using those with an UTP cable back to the place where i have my raspberry

with that video cable i am also able to capture the video feed , also connected to my raspberry


I simply mean that if you look at your voltage divider circuit, you have a source voltage and the output voltage from the divider. In the picture it shows that they are both referenced from a common ground, implicit in that is that the grounds are connected together.
It’s kinda obvious, but I’m checking because you once said that when the bell button was not pressed the voltage went to (I think) -2.7v (or abouts)
Just checking is all :slight_smile:

yes, indeed with a multimeter directly on the output pins from my intercom, is was like -2.7v, really strange
but on esphome it works … gonna try again with rpi

guide from @frenck is great :smiley:
If I have a 12V power source and 12V as the signal I want to read, can I use the ESP-01S itself by connecting the power and signal through a voltage devider?

forgive me, but my painting skills are negligible :wink:
something like this:

image