diy solar

diy solar

DIY Home Energy Monitoring

this thread is making me want to write firmware. it's fun to know what's going on in the box.
A No-Math solution is the advantage of the half or full bridge rectifier circuit in #11. But diodes with low voltage drops cost around a quarter and capacitors around a nickel! Actually, the half-bridge circuit has one less component, so possibly cheaper, but you have to put up with the slow drain (or add a bleeder resistor controlled by a switching transistor?).

to do it pretty accurately in DIY,
Depends on what "pretty" means. For example, if you assume 120V when pulling 10 amps that's 1200 watts. But if you measure it at 122V that's 1220 watts, or an accuracy of 1.7%.

CTs are outputting very small voltage changes for current changes, most have a 1V range. For most commercial applications you'll have to tune your CTs for the entire range (e.g., 0-200 amps, 0-100 amps, or 0-50 amps). That is, 1V covers the entire range, so the larger the range the smaller the voltage change and the lower the accuracy. So a 50 amp CT might not register an LED light coming on, the voltage change of the CT falls into the noise range.

With DIY, you can get far more accurate by tuning to cover the range you're interested in. For example to monitor my air conditioner the clamp meter shows 5.1 amps (1224W) on one circuit and 1.41 amps 340(W) on the other. Nothing else is on the circuit so I don't have to worry about low-watt LED lights or someone plugging in a vacuum (although you do have to worry the inrush amps won't fry your chips).

Let's take a wall outlet that normally has up to 100 watts of power (e.g., your cable modem and stereo), but someone might plug a vacuum cleaner into it for 5 minutes. Let's say that since the vacuum is run for 5 minutes every couple of days, you don't care about the accuracy when it's on. What you really want to measure is 24x7 of the sub-100-watt loads. In this case, you need to use the breaker size plus the suspected in-rush to not fry the chip with high voltages. With an ESP32c readings over 2.5V on the ADC won't be as accurate, but the pin can safely go up to 3.3V. So, you can pick a high-burden resistor giving you a greater voltage range. The readings won't be very accurate while the vacuum is on since the voltage range would be where the ADC isn't as accurate, but the rest of the time you'd be able to pick up what otherwise might be noise. You can also play other games, like using a 5V 32-bit ADC chip that communicates back to the MCU (the saturation on the CTs I experimented with was 4 V, but going over saturation just means a drastic reduction in accuracy which isn't important if that range is the inrush current).

Finally, components have "tolerances", so you very rarely find a 50Ω resistor that actually measures 50Ω. But in a DIY circuit, you can measure and plug in the actual value. Although, it wouldn't be hard for the software of any commercial unit to use calibration to overcome this problem which they could do in the factory.

So, unless the ADC is really bad or something is injecting a lot of noise; DIY should offer more opportunities than commercial systems for accuracy.

one ...needs a CT sensor per branch to detect current and at least one voltage meter for the hot leg voltage?
If you don't care about the power direction (e.g., I don't have to worry about my Air Conditioner suddenly generating power ; -) then you just need one CT to get amps. If you want power (watts) you need the voltage (which you could get from your existing solar API). If you want power direction, then you also need to know the grid phase and calculate the CT phase.

PowerStrip: Another Fun Project?
...needs a CT sensor per branch...
Doesn't have to be a circuit branch. For example, let's go back to the idea of measuring very finely all the devices in an entertainment center rather than one lump sum for them all (that way you can see if one is a hog and needs to go. After all, every 10W is generally > $13/y).

You could build the equivalent of a power strip where each socket reported its current draw.
Add a 5 amp breaker, just in case the kids plug the vacuum cleaner into it. Now you can tune
the circuit for a maximum of 600W, getting a 2.5W sensitivity with an ADC accuracy of 0.01V
(Some of the ADCs supposedly can measure accurately to nV, and quite possibly the ESP's
ADC is better than 10 mV).

Or, go crazy with a 3 amp breaker for a 1.2W accuracy (10 mA).
1678454058955.png
Of course, any of the power meter plugs would probably be cheaper and easier. Some of them even say they're accurate to within 0.01W.
 
Last edited:
Been digging through the junk pile and have plenty of resistors, but the diodes and capacitors found really aren't suitable. Suppose I could just build the design in #9, but I think I want to also build #11 and compare them. Any thoughts about the circuits?
 
Last edited:
Looks like I made a rookie mistake, again...

In #11 I used "ground". I assumed it was a simple way to hide wires, but it's not. Apparently, it's an "ideal" ground. So, quite the surprise when I went to rebuild the circuit putting in all the parts so I could figure out what I needed to order. Instead of a nice flat voltage to read, it was a sine wave again (although at least all positive over the full range).

I should probably check into I2C chips designed for this. Might be cheaper than buying capacitors and diodes since I'm getting low volume.
 

Regression​

TL:DR: More Math, OH NO!

A sine wave can be described by y = a sin (bx + c) + d, were a is the amplitude, b is the frequency, c is the horizontal shift, and d is the vertical shift.

Let's generate some random data using the sin function and adding somewhere between +/- 10 mV using a random function @ 1V:
ms y
0 -0.56
1 -0.81
2 -1.04
3 -1.05
4 -0.92
5 -0.61
6 -0.25
7 0.16
8 0.54
9 0.85
13 0.72
14 0.38

Initial Estimates
Given a number of data points, "a" can be guessed as the maximum y. In our case, we know b is
60 Hz. Let's guess a 1/3 wave for c and d would be the bias voltage in #9 or zero with diodes
(0V for this example). Using the example data above, a = 0.85. So, if we plot the line against
the data (blue) we can plot the data using the formula and guesses to get the line to the right.
We can sum the delta of the Y points and get 11.4, this is the value to minimize in the next attempt.
1678810731571.png

On the second pass, we can guess a new c by looking at the time difference between the two peaks (or interpolating the zero crossings), giving us 10 for c, which gives an error of 1.51. Dropping the voltage to 0.75 increases the error to 2.27, so we know the voltage must go the other way. Subtracting the errors: 2.27-1.51 = 0.76 unit of error for 0.1V change. At 0.85v we were 1.51 units off, so 1.51 x 0.1 / 0.76 = .2V, or a= 1.05V. At which point the error becomes 0.34.

With each change you could also re-guess c using the zero crossings if they changed. So, that technique seems to zoom in pretty quick to fit the curve values.
 
Not sure what your goal for accuracy is but your proposed HW and SW processing for CT readings is unlikely to yield accurate results for real world conditions. I suggest you review the content on https://openenergymonitor.org/ thoroughly.
 
Back
Top