Detecting mains voltage in an ATS

I have a Kohler ATS that I desoldered the uCs off of and replaced them with an ESP32-S. I know there are about a 1000 tangents we can go regarding safety, but let’s just suspend all that and work under the assumption that I am doing this safely.
The transfer switch uC had 3 functions: RS485, a single output to transfer to the backup generator, and 3 inputs to detect voltage on the 3 sides of the transfer switch. The software side of the detection circuit is the nature of my question.
Line voltage enters the board through an 8 pin plug and each leg connects to a long chain of resistors that feed into what I imagine is a quad op amp. The outputs of which feed into the uC. Floating, we get about 1.5v, and when connected we get fluctuating voltage going from a little under half a volt to almost 3 volts. It looks like it is representing the waveform of the AC as a swing in DC with 1.5 being neutral.
It would be cool to be able to read out voltage and frequency, but at the very least I just need to detect if there is power on the line. My initial thought was something like a counter that gets reset whenever voltage is far enough from 1.5 to show power, but that might not be the most efficient way to do it. Any suggestions for the way to handle this in ESPHome? Thanks!

Yes, well that gave me a giggle. An ATS with desoldered uC’s must be one of the more unique ESPHome projects. Let’s assume it’s a large relay. :slight_smile: Maybe what I’m suggesting isn’t going to fly as you’re looking for AC waveform analysis and I think that might need to be programmed directly on the ESP rather than using ESPHome’s YAML, but here are my thoughts.

The obvious answer here is to feed the representative AC into an ADC and perform some type of analysis on this - I’m not sure about the feasibility of this though, but I found some info which suggests that it can work on the basis of using a ZMPT101B module (which you don’t need as you have the AC signal already).

ESPHome also has the facility to measure zero crossing in the AC Dimmer module. I got the RobotDyn dimmer module, but I haven’t played with it yet. Looking briefly at the PCB I can make out that the AC coming into two or three resistors and then routes off to a bridge-rectifier and then into an optoisolator. It appears to match this circuit in some ways:

There is also a circuit here which shows an oscilloscope trace which looks to be functional.

So if “zero_cross_pin” can be used as a pulse reference, then there should be no problem applying a frequency counter to it.
Anyway, some food for thought.

Actually, two other options for frequency: pulse_counter and pulse_meter:

Thank you, That is helpful, and I should be able to implement that. Honestly a frequency counter might be the ticket here. One of the reasons I chose this ATS was that it is mechanically impossible for me to screw up (There is a coil on either side of the physical switch that does the transfer) Also, I discovered there is just a single line to pull high that switches from line power to backup. Here is the monstrosity in it’s current state: