How to measure current with esphome?

@nickrout @andy135 @sparkydave
Hello All, Thank you so much for all your help I can say now that the problem is now solved!.

Although we couldn’t read analog input out of the WCS1700 we manged to find other solutions.

We learned how to use the WCS1700 for over current digital signal and how to adjust it using the potentialometer from here Pixel Electric WCS1700 .

Solution to getting AC current readings without buying unavailable modules online and waiting months:

I have bought a cheap/dumb 1$ current sensor with a display.

I took the external current transformer (circular ring) and hooked it up in a circuit as such:

(I have added a 1000R between 3.3v and red transformer wire to reduce voltage and increase reading range which worked!)

diagram:
WEMOS D1                         AD26B-22VAHM
V3.3 ----------R1000------------- red wire
A0 ---------------------------------- black wire
GND ----------R100-------------- black wire

Now I was able to read voltages 0-1V+ that are proportional to the current passing in the AC wire through the current transformer.

Code to calibrate input:

sensor:
  - platform: adc
    pin: A0
    name: "current"
    id: "current"
    icon: "mdi:flash"
    update_interval: 7ms
    unit_of_measurement: "A"
    raw: True
    filters:
      - max:
          window_size: 1000
          send_every: 1000
          send_first_at: 1000
      - multiply: 3.3
      - calibrate_linear:
          - 1438 -> 9.1
          - 1445 -> 9.2
          - 1491 -> 9.6
          - 1518 -> 9.8
          - 1544 -> 9.9
          - 1567 -> 10.0
          - 1590 -> 10.1
          - 1679 -> 10.2
          - 1686 -> 10.3
          - 1716 -> 10.4
          - 1722 -> 10.5
          - 1735 -> 10.9
          - 1755 -> 11.2
          - 1772 -> 11.4
          - 1791 -> 11.5
          - 1815 -> 11.7
          - 1824 -> 12.0
          - 1861 -> 12.1
          - 1900 -> 12.2
          - 1920 -> 12.5
          - 1940 -> 12.8
          - 1953 -> 13.2
          - 2019 -> 16.4
          - 2088 -> 16.8
          - 2194 -> 17.1
          - 2224 -> 17.7
          - 2244 -> 17.8
          - 2277 -> 18.0
          - 2316 -> 18.2
          - 2385 -> 18.3
          - 2399 -> 18.7
          - 2435 -> 19.9
          - 2418 -> 20.0
          - 2455 -> 20.1
          - 2468 -> 20.6
          - 2484 -> 21.5
          - 2521 -> 24.0
          - 2583 -> 24.4
          - 2666 -> 24.7
          - 2857 -> 26.4
          - 2979 -> 27.0

WCS1700 will give the output of range from 0-5V while the ESP32 only have the capability of 0-3.3V ADC. This might be the reason !

This is not true, WCS1700 works even on 3.3V and datasheet mentioned it clearly even showing graphs, slopes and equations for 5V and 3.3V.

You understand that Output is the complete opposite of input, right? They are talking about what voltage range it outputs and your going on about how it can work(input) at 3.3v.

Maybe you should look again… The max input voltage is 12v and it shows gtaphs for input voltages up tp 12v.

You can measure voltages of 5v, 12v, 24v etc but, only with a voltage divider or similar. Nothing that that was said is Not True. The ADC on esp32 has a max of 3.3v or even lower. That doesnt mean it cant detect higher voltages like 5.0v, it just cant handle a 5.0v ADC voltage direct to the ADC gpio without something like a voltage divider.

Take a moment to actually read something before calling someone else wrong or you risk being wrong too, which you are here.

I have used this sensor with 3.3V with ESP32 and it works as it works with 5V but you need to use another equation as described in the datasheet for 3.3V so you saying that it does not work with 3.3V is definitely wrong so I said what you said was wrong and I stand with my assertion, no need to get hurt. You are confused with input Vdd and output yourself, the equation clearly show that Vdd 5V and 3.3V and the output is y that you’ll connect to ADC. The x is detected Ampere flowing through the wire. Read the datasheet and implement what is described.

no one is or did say it wont work with 3.3v. This is exactly what I was talking about. I don’t even know how you came to that conclusion from what I said because, I said nothing that could even be confused for saying that. You keep going back to “I’ve used it with 3.3v and it works” No one said it wont! Do you understand now? This isn’t difficult stuff to comprehend.

Who even brings to life a dead post from nearly 1 year ago just to add, “No, you’re wrong”? You understand the conversation is dead? The people have forgotten about it and moved on. It’s OK though, I remember when I first got on the internet too. You’ll figure it out

It is your mistake to create an issue where there was none. You said in the comment from 2023, that the output of WCS1700 is 0-5V which is wrong. I said exactly that. The output of WCS1700 depends on the Vdd and Vdd can be 5V and 3.3V (or even higher but we are not discussing that then or now) and the output V is described in the charts you also shared. But you started that maximum input is 12V and bla bla which was not the argument.

The argument is and was for me that the output can’t be 0-5V for 0-3.3V system and you failed to read the datasheet and comprehend the output voltage as per the equations. Please understand what you wrote and wanted to say, do not add irrelevant facts (input can be 12V) when the context of discussion is limited to ESP for which this forum is and discussion is happening for 3.3V and 5V.

if you are wrong, then someone can point it out so you can correct it. When I’m wrong, I do expect the same, there is nothing to be angry or get hurt.

This is going way over your head. It was a very simple statement and thats a common statement. The person was saying it outputs a range of 0-5v. Thats the typical range for people using esp boards and supplying VDD with 3.3v or 5v. Its 0 on the low end and 5v on the high end.

Some devices/sensors can take an input of 5v but will bump it down to 3.3v for the logic output so they are safe to power with 5v and wire S to a gpio as 3.3v is as high as it goes.

The entire point of saying it outputs 0-5v is to make the person aware that if they input 5v they can get 5v back and they need to take necessary steps to deal with that.

You keep going back to “not if VDD is 3.3v”…
No SHI# Sherlock that doesnt even make sense for it to output a higher voltage than your feeding VDD! Thats just common sense, it was common sense to everyone else what they meant by 0-5v but, apparently not to you so here I am again explaining it to you in the simplest words I have. For the last time ill say it, no one is saying the output is 0-5v if VDD is 3.3v. The whole point was to make them aware that it can output up to 5v on the high end and since its common sense to everyone else let me qualify that. Its only 5v if VDD is 5v, duh! No one is or was expecting the output to be higher than the input and everyone and their dogs knew what the 0-5v statement meant except you so, congratulations!

The esp32 can measure up to 3.9V with the internal attenuation set to 12db :raised_hands:

Yep, i know… you want a cookie or something? The reason myself and many others say 3.3v is to keep it simple and not be responsible for people smoking their esp32’s by trying to use the absolute max. The majority of people wont even do a simple Google search before posting a question let alone read specifications or data sheets so, it just seems more responsible to tell them 3.3v.

Also, seeing how most people aren’t using actual esp32 IC’s where that spec comes from and instead theyre using one of the dozens of esp32 dev boards which can have varying specifications between brands or varying max voltage to ADC. Im not so sure 3.9v is the max for every single dev board out there which is another reason to keep it simple and just use 3.3v. Anything else?