Make friends with ZMPT101B esp8266

Gentlemen, help me figure out how to connect and process the signal from the ZMPT101B correctly. There seem to be examples in C++ for arduino, but they use libraries, but I can’t figure out how to do it correctly with esp8266)) I connected the sensor to the analog port, and it seems that there are readings in the esp home logs, the readings jump very much, although the measured voltage is relatively stable ± 5 v . I also tried using ina226, but it didn’t work.
I believe that this sensor can also show a sine, so for a simple RMS voltage display, you need to describe the reading principle.

esphome:
  name: "esphome-web-2"
  friendly_name: Wemos d2
  on_boot:
    - priority: 600
      then:
        - switch.turn_on: pwm_switch

esp8266:
  board: d1_mini

logger:
  level: DEBUG 

api:

ota:
  - platform: esphome

i2c:
  

wifi:
  networks:
    - ssid: Pro4
      password: Milk33kg

globals:
  - id: pwm_level
    type: float
    restore_value: no
    initial_value: '0.0' 
  - id: pwm_frequency
    type: int
    restore_value: no
    initial_value: '1000'  

sensor:
  - platform: adc
    pin: VCC
    name: "VCC Voltage"
    update_interval: 1s
    accuracy_decimals: 4
[21:00:34][D][sensor:093]: 'VCC Voltage': Sending state 3.22559 V with 4 decimals of accuracy
[21:00:35][D][sensor:093]: 'VCC Voltage': Sending state 3.21387 V with 4 decimals of accuracy
[21:00:36][D][sensor:093]: 'VCC Voltage': Sending state 3.22852 V with 4 decimals of accuracy
[21:00:37][D][sensor:093]: 'VCC Voltage': Sending state 3.22754 V with 4 decimals of accuracy
[21:00:38][D][sensor:093]: 'VCC Voltage': Sending state 3.22754 V with 4 decimals of accuracy
[21:00:39][D][sensor:093]: 'VCC Voltage': Sending state 3.22656 V with 4 decimals of accuracy
[21:00:40][D][sensor:093]: 'VCC Voltage': Sending state 3.22852 V with 4 decimals of accuracy
[21:00:41][D][sensor:093]: 'VCC Voltage': Sending state 3.22852 V with 4 decimals of accuracy
[21:00:42][D][sensor:093]: 'VCC Voltage': Sending state 3.22656 V with 4 decimals of accuracy
[21:00:43][D][sensor:093]: 'VCC Voltage': Sending state 3.22559 V with 4 decimals of accuracy
[21:00:44][D][sensor:093]: 'VCC Voltage': Sending state 3.22656 V with 4 decimals of accuracy
[21:00:45][D][sensor:093]: 'VCC Voltage': Sending state 3.21484 V with 4 decimals of accuracy
[21:00:46][D][sensor:093]: 'VCC Voltage': Sending state 3.17871 V with 4 decimals of accuracy
[21:00:47][D][sensor:093]: 'VCC Voltage': Sending state 3.05273 V with 4 decimals of accuracy
[21:00:48][D][sensor:093]: 'VCC Voltage': Sending state 3.04492 V with 4 decimals of accuracy
[21:00:49][D][sensor:093]: 'VCC Voltage': Sending state 3.17090 V with 4 decimals of accuracy
[21:00:50][D][sensor:093]: 'VCC Voltage': Sending state 3.05664 V with 4 decimals of accuracy
[21:00:51][D][sensor:093]: 'VCC Voltage': Sending state 3.21289 V with 4 decimals of accuracy
[21:00:52][D][sensor:093]: 'VCC Voltage': Sending state 3.16992 V with 4 decimals of accuracy
[21:00:53][D][sensor:093]: 'VCC Voltage': Sending state 3.16895 V with 4 decimals of accuracy
[21:00:54][D][sensor:093]: 'VCC Voltage': Sending state 3.18750 V with 4 decimals of accuracy
[21:00:55][D][sensor:093]: 'VCC Voltage': Sending state 3.04980 V with 4 decimals of accuracy
[21:00:56][D][sensor:093]: 'VCC Voltage': Sending state 3.07617 V with 4 decimals of accuracy
[21:00:57][D][sensor:093]: 'VCC Voltage': Sending state 3.17383 V with 4 decimals of accuracy
[21:00:58][D][sensor:093]: 'VCC Voltage': Sending state 3.16992 V with 4 decimals of accuracy
[21:00:59][D][sensor:093]: 'VCC Voltage': Sending state 3.17090 V with 4 decimals of accuracy
[21:01:00][D][sensor:093]: 'VCC Voltage': Sending state 3.05859 V with 4 decimals of accuracy
[21:01:01][D][sensor:093]: 'VCC Voltage': Sending state 3.05566 V with 4 decimals of accuracy
[21:01:02][D][sensor:093]: 'VCC Voltage': Sending state 3.05664 V with 4 decimals of accuracy
[21:01:03][D][sensor:093]: 'VCC Voltage': Sending state 3.05371 V with 4 decimals of accuracy
[21:01:04][D][sensor:093]: 'VCC Voltage': Sending state 3.07715 V with 4 decimals of accuracy
[21:01:05][D][sensor:093]: 'VCC Voltage': Sending state 3.05273 V with 4 decimals of accuracy
[21:01:06][D][sensor:093]: 'VCC Voltage': Sending state 3.17383 V with 4 decimals of accuracy
[21:01:07][D][sensor:093]: 'VCC Voltage': Sending state 3.05664 V with 4 decimals of accuracy
[21:01:08][D][sensor:093]: 'VCC Voltage': Sending state 3.05664 V with 4 decimals of accuracy
[21:01:09][D][sensor:093]: 'VCC Voltage': Sending state 3.13867 V with 4 decimals of accuracy
[21:01:10][D][sensor:093]: 'VCC Voltage': Sending state 3.12988 V with 4 decimals of accuracy
[21:01:11][D][sensor:093]: 'VCC Voltage': Sending state 3.13477 V with 4 decimals of accuracy
[21:01:12][D][sensor:093]: 'VCC Voltage': Sending state 3.05566 V with 4 decimals of accuracy
[21:01:13][D][sensor:093]: 'VCC Voltage': Sending state 3.10059 V with 4 decimals of accuracy
[21:01:14][D][sensor:093]: 'VCC Voltage': Sending state 3.11035 V with 4 decimals of accuracy
[21:01:15][D][sensor:093]: 'VCC Voltage': Sending state 3.06738 V with 4 decimals of accuracy
[21:01:16][D][sensor:093]: 'VCC Voltage': Sending state 3.08008 V with 4 decimals of accuracy
[21:01:17][D][sensor:093]: 'VCC Voltage': Sending state 3.07812 V with 4 decimals of accuracy
[21:01:18][D][sensor:093]: 'VCC Voltage': Sending state 3.05957 V with 4 decimals of accuracy
[21:01:19][D][sensor:093]: 'VCC Voltage': Sending state 3.05273 V with 4 decimals of accuracy

there is a similar question. But that was a long time ago, and perhaps there are other new ways to connect this sensor.
First ESPHome Custom Sensor ZMPT101B Voltage Sensor

Anyway, the custom components have been removed esphome

from the docs:

The following configuration block adds the sensor reflecting VCC on a supported hardware platform. Please see specific sections below of what voltage is actually measured.

sensor:
  - platform: adc
    pin: VCC
    name: "VCC Voltage"

So, you probably do NOT want to set the pin to VCC, unless you want to know the voltage powering the esp8266.

You do want to set it to 17

And you should read the documentation: Analog To Digital Sensor — ESPHome

But, that still won’t be enough, since you are putting in AC and the ADC is generally expecting DC. You can make it work by computing the RMS value (assuming you have biased the AC voltage so the negative values are still above 0V).

This is a decent explanation of the process (hardware) Measuring AC Voltage with an AC to AC power adapter — OpenEnergyMonitor 0.0.1 documentation

The link you mentioned has a link to a custom component that does RMS calculations that look okay. Custom components have been deprecated, but you can bring them back with an external component:

Thanks for the tips))) I will try to study)) I 've looked at the article I linked to several times , but I still don 't understand where the link to the user component is , or if I 'm looking for the wrong one . And ( external_components: ) generally a dense forest for me , but I think I 'll figure it out now.

external_components:
  - source:
      type: git
      url: https://github.com/robertklep/esphome-custom-component
    components: [ custom, custom_component ]

this is instead of this link https://github.com/robertklep/esphome-custom-component do I need to provide a link that I didn’t find in the article?
I did this as indicated in the link I provided. :

this is what part of the code looks like , and my need to change the link in external_components to the one my need , if I understand correctly , and add sensor description .

esphome:
  name: "esphome-web-2"
  friendly_name: Wemos d2
  includes:
    - zmpt101b_custom_sensor.h
  on_boot:
    - priority: 600
      then:
        - switch.turn_on: pwm_switch

esp8266:
  board: d1_mini

logger:
  level: DEBUG 

api:

ota:
  - platform: esphome

i2c:
  

wifi:
  networks:
    - ssid: Pro4
      password: Milk33kg

globals:
  - id: pwm_level
    type: float
    restore_value: no
    initial_value: '0.0'  # Начальное значение уровня
  - id: pwm_frequency
    type: int
    restore_value: no
    initial_value: '1000'  # Начальная частота в Гц (1 кГц)

external_components:
  - source:
      type: git
      url: https://github.com/robertklep/esphome-custom-component
    components: [ custom, custom_component ]

sensor:
  - platform: adc
    pin: A0

I couldn’t figure out how to correctly configure external_components in my case. I didn’t understand how it works at all.

external_components:
  - source:
      type: git
      url: http://homeassistant/esphome/zmpt101b_custom_sensor.h
    components: [ custom, custom_component ]

how it should look ? ))

what error did you get when you tried it?