Opposite of a relay?

I’m not sure exactly what I need but I’d like to connect something upto the mains that will open or close a circuit that I’d use a GPIO on a ESP8266 to read and monitor. Basically the opposite of a relay I think. I’m not interested in monitoring consumption etc I just want a low cost "is there power in this socket: yes/no)

Could someone point me in the right direction please.

Just write any firmware to the ESP, connect it to your WiFi and plug it into the socket.
If the socket has power, it takes a few seconds to connect and you can use the Ping binary_sensor to show the state in HA.

Exactly. This is probably the easiest way.

Do this with ESPHome.

Thanks but that had already occurred to me. I am already a big ESPHome user. I would rather have a device that I described in my OP.

You can’t tell the difference between ESP died/wifi down/whatever vs power is out. I’d like to read a switch.

Well, then hook up a relay directly into the mains, and the other side that closes/opens you hook up to a GPIO. That way you can see if it has power or not.

But how do the ESP report it if the socket has no power? A battery? And the Wifi also needs power. This doesn’t make a lot of sense.

As Valentino said it’s still a relay - it’s just mains power enegized and switching as an open/close low voltage contact. Your coil side should be rated at your ac mains voltage and the contact ratings won’t really matter at all, except perhaps select as preferred normally open or normally closed (or changeover).

The disadvantage of this approach is the relay may normally be powered for long times drawing a small amount of power, in addition to the esp32 being permanently powered. Hence it can’t run off the plug you are monitoring.

Could you change the socket to one with a built in usb port ? then simply plug your esp8266 into it

You want a power outage monitor.

Though you might want to consider a UPS with monitoring instead.

1 Like

On my built in USB the USB port is permanently powered even if my socket is switched off…
… although I think that is a poor design decision…

True, but he did ask how to tell if there is power in the socket

1 Like

How about getting one of these?

You can then flash it with Tasmota, which will allow HA
to check its availability via MQTT. If it’s unavailable then
the power to your socket is probably out.

You can find an excellent video guide here.

I use ESP8266 with 1-Bit AC 220V Optocoupler Isolation Module. You can find it on AliExpress or so. On one side you can connect 230v AC power. When there is power, the data pin on the other side goes high (or low). It is a 3-5v module. Also available as 4 or 8 way board.

@HansF : Thank you for actually reading my question and providing an answer. That sounds exactly what I’m looking for.

TIL: Optocoupler

@Fuzzysteve - thanks but I’m an IT consultant. I own a proper computer room at work (I own the company). We have several UPSs and a rather large diesel generator that cost £10,000. The UPSs only need to last about 10s before the genny kicks in. The UPSs are all plumbed into a RPi with four instances of APCUPSD running and they are just four of the 2202 services across 497 systems that we monitor.

When I looked at the specs for the electrics board thing that links the genny to the mains, I noticed that it provided a couple of tiny circuits that will open and shut when the mains is on/off and the genny is on/off. I have a single ESP8266 monitoring that.

That is what prompted my OP. I spent about £7 on that device, plus an old phone charger to power it. The phone charger is plugged into a UPS with a good 60 mins runtime on battery.

Now I know about a optocoupler, thanks to @HansF and that sounds like a safe and cheap way of monitoring the mains.

1 Like

@Teleportist: Thanks for the notes. However, monitoring is hard, really hard. I posed my question because I wanted a device that positively identifies the state of something. Note how you said “probably” in your answer. How do you tell the difference between the power actually being out and the device failing, the wifi failing etc? Now I’ll grant you that my desired method is not perfect either but several failure modes are excluded from becoming false positives.

Ahh cool.

A touch beyond what most people here would be looking at I think :wink:

I know UPS add-ons for site UPSs can be, umm, a touch expensive.

@Fuzzysteve To be fair though, that generator is big enough to run most people’s entire house, including a/c. Maybe not FL man’s a/c!