Yes. I’m using one and it works very well.
I have the ZMPT101b voltage sensor and a 50A SCT-013-050 current sensor hooked up to nodeMCU 8266 running ESPHome. The sensors connect through an ADS1115 A/D converter.
The node measures the line voltage and house current and calculates the power consumption. I also have a SMA solar inverter giving me the solar power generation and HA calculates the mains power from the two.
The voltage I measure with the node tracks the voltage reported by the SMA inventer pretty well. The only reason I measure it with the node is that the inverter goes to sleep in the dark and then stops reporting the line voltage.
Concerning the voltage measurement;
The ZMPT outputs the attenuated sine wave with a 1/2Vcc offset. The attenuation can be adjusted and you must make sure the voltage does not clip. A scope comes in handy here. Also note that using the NodeMCU ESP8266 ADC is not great solution the range is 0 - 3.3V, with an offset of 2.5V there is not much room for the signal.
From the sine wave you must calculate the RMS value. Here it gets interesting. The ADS1115 is not fast enough to take enough samples over one wave at 50 Hz (20 ms). So I sample the wave over a much longer time to calculate the RMS value. I make sure NOT to sample at a multiple of 20 ms. I ended up sampling 1250 times at 24 ms, i.e. 30 seconds. And report every 5 seconds.
For the RMS calculation I substract the voltage offset, square the result, calculate the rolling average over 1250 samples, report every 208 samples, take the square root and multiply to calibrate.
I increased the i2c bus speed to 400 kHz and reduced the sample interval 24ms, that way I got the expected 42 samples per second in the log (but I do not know if the ADS or the logging is the constraint …).
It is possible to use the ct_clamp platform for the voltage sensor. It just calculates the RMS voltage from the ADC. But I found it to be very nerveus, so I stick with my solution.
# i2C bus
i2c:
- sda: D2
scl: D1
scan: no
frequency: 400kHz
id: bus_a
ads1115:
- address: 0x48
# continuous_mode: on
sensor:
- platform: ads1115
name: "Mains voltage"
unit_of_measurement: "V"
icon: "mdi:flash"
accuracy_decimals: 0
update_interval: 24ms
multiplexer: 'A0_GND'
gain: 6.144
filters:
- offset: -2.5485 # compensate the offset (calbration)
- lambda: return x * x;
- sliding_window_moving_average:
window_size: 1250 # average over 30 seconds
send_every: 208 # report every 05 seconds
- lambda: return sqrt(x);
- multiply: 338 # calculate mains voltage (calibration)
id: mains_voltage
Concerning the current measurement;
I was using the ‘ct_clamp’ platform from ESPHome. That seems to work, but I have no idea what it does and that is frustrating. The ESPHome page on this does not explain much. Also, for the ct_clamp platform I’m supposed to enable the continuous mode, but when I do that I only get ‘reading ADS1115 timed out’ messages in the log.
So I ended up using exactly the same logic as for the voltage sensor with different filter settings (same 24 ms sample rate, average over 12 seconds, report every 2 seconds).
Note that the current clamp will give a zero crossing wave output. To measure the positive and the negative part you must connect as a differential to the ADS1115. The average is zero and there is no need for an offset correction.
- platform: ads1115
name: "Mains current"
unit_of_measurement: "A"
accuracy_decimals: 1
icon: "mdi:gauge"
multiplexer: 'A2_A3'
gain: 1.024
update_interval: 24ms
filters:
- offset: 0 # compenstate the offset (value measured at 0A)
- lambda: return x * x;
- sliding_window_moving_average:
window_size: 500 # average over 12 seconds
send_every: 83 # report every 02 seconds
- lambda: return sqrt(x);
- multiply: 52.743 # calculate mains current (0.5 V = 25 A)
id: mains_current
I hope this helps some people with their ZMPT101B and SCT-013-050 integrations.