This project is for a whole home energy monitor. I had a lot of trouble finding accurate information about how to properly setup the sensor and get its readings. Most all of the info out there was for setting it up on a Arduino 5v analog input but the ESP8266 only has the one analog input with a max of 1v so I needed to figure out another way to get my readings. I tried using other methods and formulas to get the current but ended up just writing my own in the end.
The project uses the YHDC SCT-013-000 clamp on current sensor to read the current on the mains line. Then it is read by a ADS1115 16bit Analog-to-digital converter. I went with the ADS1115 because it not only provides excellent resolution, the gain is configurable and has a better input range than the ESP8266's max volt of 1 on the analog input. It took some time figuring out how to read the current using the ADS1115 but eventually got it with pretty accurate results.
I was able to get the measurements using a voltage divider that puts 1.65v on one side of the current sensor and the other line going to one of the analog inputs of the ADS1115. Another input measures the difference between the actual reading of the 1.65v and the voltage coming from the sensor which results in +- from 1.65v. The reading is then converted into amps and kWh and displayed by the OLED and uploaded to Cayenne to view on the dashboard or mobile. The OLED only displays when it is booting up and then turns off. To turn it back on there is a momentary button on the front of the case that turns the display on for 20 seconds. There also is a button on the dashboard that triggers it also.
I also use the time library and have the monitor initially connect to a network time server to set the time before it fully boots up. I do this so I can track the kWh and cumulative total. I believe my calculations: