This gets complicated by the fact the the doorbell button completes the circuit of the power source in series with the doorbell solenoid. ref.
In the USA we have a step down transformer to 24V-AC to drive the doorbell. You probably do, too because it’d be a little risky to run 220V to a place where someone is pushing a crappy button.
Here’s an idea. Power the esp8266 independently. Use a current sense device. This is as simple as wrapping a wire, many times, around one of the wires that is part of the button/solenoid/power-source circuit. The ends of this sense device wire, with a series resistor, go to the input of the opto-isolator. It will take a bit of experimenting to get the number of wraps and value of the series resistor.
The output of the opto-isolator will be a 50 (60?)hz square wave. Software on the esp8266 could figure out “if this square wave exists the door bell button is being pushed” to prevent multiple triggers. and “only notify if a notification has not be sent in the last x seconds”
I use Tasmota and C++ (Arduino IDE) on the esp8266. Tasmota has an easier interface to Home Assistant, but C++ is easier to program.
I know it could be the safest way of operating the doorbell giving the DC side of the switch for someone to press. However, in my part of geographic its 220v AC directly given to a coil that produces electromagnetic induction that pulls a plunger. You can find a video posted by a youtuber here.(I know how he is handling the cables directly with AC voltage and risk associated with that when the other wire is open circuited via the coil). In my case the operating switch is already having 220V AC even today. I have taken caution and put a high quality switch there to avoid any electrocution.
Back to this automation, With the circuit I have shared above, there is a Hi-Link AC to DC converter that will be placed before the D1 mini. The D1 mini and 5v relay module (with optocoupler) will have separate DC power that is connected to my UPS and will not be sharing the power with the Door bell. With the optocoupler already in place, any short circuit in the Hi-Link may not be impacting the D1 side of the circuits. This way the door bell will function without any interference with Automation (as it is today). I may use the automation that I am discussing here to take a snapshot via a camera placed near to my door bell switch using HA automation in future.
This is how I did it from my AC doorbell using optocoupler. AC doorbell to DC to 433mhz device My Doorbell used 18V and I didn’t fancy running a esp off it so I modified a 433 door sensor. It has worked well.
A very simple and safe way to detect electrical AC current in a wire is to use a “Current Switch” like the one linked below. You can then simply enable the internal pullup on the ESP8266 Digital GPIO pin, connect a wire from that pin to the dry contacts of the current switch, and then connect another wire from the ESP8266 GND pin to the other dry contact terminal on the current switch.
I guess when you press a button on a doorbell, you want doorbell to ring. Shelly can do that. + you can easily detect when it happens.
Or you can put shelly in detached mode and do whatever you want to do in HA.
Or am I missing something here?
I saw the drawing. I understand what OP wants to do, I am just saying there are other ways to do it. Perhaps he did not think of other possibilities, that’s all.
You might have seen the you tube video I have linked, my door bell directly operates on 220-230V AC, not having any step-down transformer or DC conversion circuits. So in order to automate I need some kind of DC circuit that’s the reason I have a 5v Power Supply. I have seen other reed switch automation. However there are also cases mentioned those automation that there are false positive alerts. Since my door bell is just above my main door, if my kids shut the main door with a bang the reed switch may get triggered and you get false positive alerts. So I am thinking to keep the automation is triggered when someone is pressing the bell switch.
With respect to AC712, I have bought couple of them thinking similar to what you do have suggested. However if we go with any voltage or current sensor there will be some delay in getting the value sensed by the respective sensor, sending that to d1 mini’s A0 to detect the value is in range and then perform the automation. I am sure it will be in milli seconds and the d1 has to be refreshed accordingly. If you have any working example, could you please share the link so I can refer and proceed accordingly.
For me, the circuit I have proposed is working so the drawing is not wrong logically nor the yaml. Anyway, I have removed the marking as “solution”. I will wait for a better approach to solve this.
Unless I’m missing something, I think @Karosm’s suggestion to use a Shelly 1 is solid.
It’s a single component which can handle 240v and detect the doorbell being pressed.
No need for parallel circuits and requires less rewiring than what you currently have in your diagram. The best thing is, it will not interfere with the original bell functionality except in the case of a hardware failure.
The only place I can get shelly in my country is via amazon. The price is almost double compared to the UK price. I know that link is showing 2 units but the cost is still double for a single unit. I will watch for any good deals on this and will go with your suggestion. Thanks a ton for helping me in this regard.