-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for apparent power calculation with current transformer connected at A0 #7100
Conversation
Implements calculations for CT based current measurement. ADC peak peak range is calculated over 32 samples and this is converted to an RMS current reading using adc_param2 as a scaling factor Power is calculated using current as above and a voltage provided via adc_param3 adc_param1 allows display of current (0), power (1), both (2) or none (> 2).
Updated comments for scaling factors
Nice! Looking forward to seeing this one. |
For my understanding. You measure the voltage once and store it fixed in a adc parameter. Then you measure the current using the ADC input and apply a formule to calculate the apparent power which is equal to true power. It does not expect or calculate reactive or capacitive loads as it cannot measure phase shifts. So only AC resistive loads will provide valid power values. Correct? |
Yes, correct. It's not intended to be a high quality precision measurement. In my case, I have a PZEM connected elsewhere from which I can send the voltage measurement - and in any event, from measurements I have taken over long periods of time, the voltage doesn't vary that much. Using the scaling parameter, you could correct for power factor if the nature of the load is known. The intention here is to provide an estimate of power using a clip on current transformer where precision isn't that important. |
Perfect for those "is the clothes dryer running or not?" I did a build of the CT clamp on ESPHome a while back when they started supported it, always good to have options and do it in Tasmota too. |
Can we decide that this solution will be used as the only power monitoring feature on a device? If yes, then I want it to integrate with the energy monitoring code to leverage the energy code and shrink code size too. |
@arendst Seems fair to me. If one is choosing the "cheap" route for monitoring energy, I would not think they would invest in a separate energy monitor to add to the device. And, if the device is already a power monitoring device, Tasmota already discouraging adding any external peripherals. |
I actually have a PZEM 004T connected to a sonoff communicating over the serial connection that works nicely... and in fact I am sending the voltage from this device over to the device with the CT to use in the power calculation. So it would seem a pity to limit people to this solution, particularly since it is just calculating apparent power and doesn't calculate the power factor. |
What I understood Theo to be suggesting is to "limit" a particular Tasmota device to have connected to it only one energy monitoring peripheral at most. In your case, one Tasmota device has the PZEM attached and reads the voltage and the current. On another Tasmota device you have this A0 current monitor and it receives the voltage measurement from the other device (the one with the PZEM). I think this fits what Theo suggests as each Tasmota device only has one energy monitor attached. |
It also allows for code re-use. The display of values could be done by the energy code already present. No need for another Voltage, Current or Power translation |
Ah, ok, I get you now. I suppose you could conceive a use case where someone has a PZEM connected and also uses a CT connected to A0 on the same device as a second power channel and rides on the back of the PZEM to get power factor and voltage.... but that is quite specific. |
If we went that route - how would the interfacing with adc_params work? |
Don't worry. I'll integrade your PR one of these days. |
- Bump version to 8.1.0.2 - Add support for ``AdcParam`` parameters to control ADC0 Current Transformer Apparent Power formula by Jodi Dillon (#7100)
Thx for your input. I've merged it in the latest dev branch my way. Pls give it a try as I do not have the CT handy ;-) |
u can not send calibration commands like powerset i get unknown command responce. |
Description:
This implements support for a simple AC apparent power monitor using a current transformer connected to the analog input A0. The full circuit details can be found here but in summary, you must have a CT with an applied DC bias connected to A0 so the raw DC reading is near 512 (for zero input) and an appropriate burden resistor such that the peak to peak voltage does not exceed 1V or 3.3V depending on whether or not your board has a voltage divider at A0.
The code measures the peak to peak range of the ADC input signal over 32 samples at 1ms intervals which is plenty to calculate the peak to peak range of a 50Hz or 60Hz signal.
You supply the appropriate scaling factor via adc_param2 to convert the raw adc range (0..1023) to the RMS current. Details of the relevant calculations are here. For a current transformer and burden resistor that reads 1V RMS for 20A RMS input current, the calculations are as follows:
1V RMS = sqrt(2)x1=1.41V peak to peak. Apply DC bias of 3.3/2 = 1.65 => max input voltage of 3.06V for 20A RMS input current. Therefore, the appropriate scaling factor is (20*(3.3/3.06))/1024=0.021063.
The adc_params must be integers, so this is multiplied by 100000 to give 2106 and is supplied via adc_param2.
Using a voltage supplied via adc_param3 in tenths of volts (so 2205 for 220.5 V) this is converted to apparent power.
A running energy total is calculated and displayed. At the moment, this can be reset by sending a value of 1 for adc_param1 which then gets reset back to zero.
The code
Related issue (if applicable): fixes #
Implements feature request: #7092
Checklist: