Monitoring mains voltages

Hi All -

Sometimes I’d like to detect the presence or absence of mains voltages (240v AC here). Examples include knowing when my traditional hot-water system is opening or closing a heating valve, or when my outdoor motion sensor is switching on or off the outside light. (It’s a mains-powered unit giving a switched live output.)

I understand the underlying electronics and could build a board myself, but that’s probably too much effort, especially considering the safety requirements.

Anyone know of an easy reasonably-prepackaged solution that could become a binary sensor in HA? I’m guessing a Sonoff Pow would work, but it might be overkill - I don’t need to switch the current or measure anything other than presence or absence of a signal.

Thanks in advance,

I am looking for almost the same.

I have some outdoor motion triggered lights, and I have connected them to a Sonoff Pow. When the power is above a threshold value, I assume the light must be turned on.

I have an outdoor motion sensor connected to a Shelly 1, but it isn’t working good. I needed to insert a relay between the two to get it working. (Shelly 1: 25VAC on input - Motion Sensor attached gives 100 VAC)
But I think attaching it to your hot-water system should work. (

And it should be possible to just use a esp8266 with an optocoupler to detect mains voltage. (,searchweb201602_2_10065_10068_319_317_10696_10084_453_10083_454_10618_10304_10307_10820_10821_10301_537_536_10902_10843_10059_10884_10887_321_322_10103,searchweb201603_51,ppcSwitch_0&algo_expid=698b1ac0-6421-4ab4-a717-c21eef65504c-3&algo_pvid=698b1ac0-6421-4ab4-a717-c21eef65504c&transAbTest=ae803_3)

using an ESP8266 with the above mentioned optocoupler would be the cheapest and very easy to implement using the ESPhomeYAML API in HA

I know, but you still need to get from 220V AC to 5V DC to power the ESP. Do you know of any easy and reliable way to do this?

The shelly can also be flashed with ESPHome, and might even be easier/cheaper.

I use a Quibino Relay module and connect the voltage to be sensed to the I2 switch input, this shows up as a binary sensor in HA

I suppose any Zwave relay with mains rated switch inputs would work, there are some that don’t have mains rated inputs (Everspring) thats why i chose the Qubino

Just use a power supply which is looked in before the device doing the switching. IE: before the thermostat or motion sensor. You can buy very cheap 240vac to 5vdc power supply modules from AliExpress. I have a few on their way now, only about AUD$1 each from memory

Thanks all - some useful suggestions…

I like the look of that optocoupler - it could work nicely in situations where I’m already using a Sonoff switch (which could provide the Vcc) and want to connect one of its GPIO inputs to an existing 220v source. That would work well for my outdoor-light-with-motion-sensor example.

I will be using a micro usb cable splitter to power a 5v relay and a power passthrough power bank which in turn powers the raspberry pi where hass runs. The powerbank acts as a ups for the pi. The relay is connected to hass as a pir sensor through a suitable pin.
The relay and splitter y cable costs 1.5$ total from aliexpress.

Combining a Sonoff switch and the optocoupler is a good idea. I think I am gonna try that too.

If you have a UPS , there is a component to monitor it which will give you a binary sensor

The UPS that already runs the PI is what I used, but use NUT instead.