Sense up to 24V AC safely

Hey guys,

I’ve got an RasPi 4B running HA for a month now.

I like to integrate my doorbell, to get push notifications when someone is ringing.

The bell is a simple AC to AC step-down transformer with two buttons and two bells.

I like to run a cable to the Pi and sense the voltage from one of the bells, safely.

Whats the cheapest solution to do this?

I saw some I/O boards and some voltage sensors online, but I don’t have enough experice on electronics to understand which one protects the RasPi in case of an overvoltage.

Hope you can share some knowledge with me :slight_smile:

Best regards


The best protection is to not connect it at all.
My advice is get an ESP and use that as your messenger.
If that burns then “no harm” done.

As I see it you could either set up a voltage divider and a diode bridge to convert it to DC.
Or depending on position of the bells and general loudness in your house.
Add a microphone and “listen” for the bell.

Or actually…
A 24 volt ac relay.

This could be safe enough to connect to the pi.
But I wouldn’t.

The cost of a ESP is well worth it if the relay fails and sends 24 volt down the wrong end.

Interesting idea with the relais, but I think the voltage drop might be too high driving a third “magnet” with these hair-thin wires. Have to test that - thanks!

A microphone isn’t a good idea, too much noise in the background to pick the bell out.

My other idea was to use a Zigbee door/window sensor and place it next to the bell. Since it’s using an electro-magnet it might be enough to be picked up :slight_smile:

But I thought there might be a cheaper option.

Or buy a shelly uni ?

fyi, I used a Xiaomi vibration sensor resting on one of the chime tone bars and it works great to alert me when the doorbell rings.

1 Like

No need to overengineer things. Why add another RF pathway when you have a wired connection ? It’s just another component that can fail, another battery you have to replace.

Use an optocoupler, like the PC 817 to get galvanic isolation between your doorbell and the Pi. These things are just a few cents each. It protects the output up to 5 kV, so 24 V should be safe :slightly_smiling_face:

1 Like

I use a relay connected to a ESP to detect doorbell rings. Works great

I’d recommend measuring the AC coming out of the doorbell transformer if you haven’t already, to make sure it works with the relay you choose.

The relay closes when you push the doorbell, opens when released

I’ve ordered one of these, but just for curiosity actually.

I’ll give it a try when it’s here, before buying more stuff.

I though on adding it as “knock” sensor to the door, with a door open switch to avoid activations when just the door has been opened or closed.

But it’s quite rare that someone knocks anyway.

I decided to order a different option as well:

A bistable relay for 6 to 24V which can react to a very short trigger pulse.

This should make it easier to get a reliable reading when the door bell is activated by a very short tap on the button.

And yes I’ll need to add two rectifiers, one to the power supply from the trafo and one from the trigger circuit.

Thanks for the idea @Hellis81 :slight_smile:

Relay fails and sends 24v down the wrong end :joy::joy::joy::joy:
Not possible

So why was the optocoupler invented?
Many things has happened that is “not possible”, I would rather pay the price of a ESP board than relying on something that is “not possible”.

An optocoupler is for when a sensor is connected directly to a PCB. In this case it’s a dry contact on a relay.

Oh sorry, I think I missed to write that bit. I just want to use the bistable release to make the signals easier to read. Instead of small pulses I’ll get flips on each button press. :slight_smile:

Still going the route with an wireless transmission to the RasPi (:

You’re probably right, this looks like it should be mounted on a PCB for sure…


I wasn’t talking to you there.
But sorry if I’m confused… But isn’t a bistable relay one that flips on/off on each “push”?

So first time you press the bell it activates the “smart doorbell” then the second time you press the button it goes off?

Notice the section that product is under?
Solid state relays.
Optocoupler is a type of relay.
It’s pointless arguing with you, after all my 20+ years experience as an electrical engineer means nothing. A traditional magnetic relay cannot leak between the coil pins and the switching pins.

Mostly for scenarios like the OP mentioned. To galvanically isolate signal paths with different voltage or ground potentials to avoid damage, ground loops and similar. And that at very high frequencies. Relays are for low frequency switching higher power loads, not data signals. Using a relay is not a good choice for the OPs situation, but well. It’s inevitably going to fail at one point or another, especially the cheap ones.


Never say impossible. Look at the thing the OP found on AliExpress above. We’re talking about the cheapest of cheap, scrapping the bottom of the barrel of bad quality, $0.01 counterfeit relay here. Everything is possible with crap like that. There is no guarantee for appropriate isolation between coil and actuator/contact side. I’ve seen crap relays like that where the coil heated up so much that the internal isolation melted away. That said, with a good high quality relay, leaking between coil and contacts is very unlikely, unless the relay suffered heavy mechanical damage.

Oh and optocouplers are not a type of relay. They’re not a type of solid state relay either. An optocoupler is a type of galvanically isolated transistor. A solid state relay uses MOSFETs or Triacs. It may use an optocoupler as part of its circuit to provide better isolation, but the relay function itself is performed by the MOSFET/Thyristor/Triac part.

Yeah. My point is, that I put constant power to this relais. And just get one wire from behind the switches which goes to the bells to the trigger.

When someone is pressing very shortly on the button the state change is extremely short and then back to normal.

So any sensor needs to have a high sampling rate to make sure to catch the ‘bell press’.

With a flip-flop relay the state change is permanently, and a much slower sampling rate is enough to catch the state change, even when someone presses the bell twice.

I really don’t care about latency here, since it has to go through Wifi and Bluetooth to my smart watch to notify me - which are both much slower :slight_smile:

Yeah I know what quality to expect. But since I won’t ever come close to switching 10 A or the voltages this thing is supposed to handle I think I’m pretty safe.

I expect it might fail and thus only connecting stuff wirelessly to it.