Question about data sampling #38
Replies: 17 comments
-
That's a good question! The ATM90E32AS can write to registers several times a second. But from what I understand this can only happen if the register is read first. I have to double check this for the energy registers. I know this is the case for the cumulative energy registers (which aren't used in ESPHome anyway). Either way, with a 10 second interval it would either be taking the energy reading at that moment or it would be reading the value from 10 seconds prior, then allowing a new value to be written. There is probably a way to configure an average in ESPHome if you wanted to do that, but I haven't looked into this yet. If you want to calculate watt hours, this can be done in ESPHome as well. |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
-
After more research, I came to conclusion that the ESPHome reports instantaneous sensor values via MQTT messages. I see there are registers in esphome/components/atm90e32/atm90e32_reg.h that is forked here: esphome/esphome@dev...CircuitSetup:dev ; but the energy sensors do not seem to be implemented in ESPHome.
@CircuitSetup , how feasible it is to implement the reading from these registers into individual ESPHome sensors we could use in yaml? I recognize the ESP32 might run out of memory, but I wonder if we could sacrifice web server component and only keep |
Beta Was this translation helpful? Give feedback.
-
Wow, you've done a lot of tinkering! I'm glad you're getting to know the IC! The energy registers listed above wouldn't be hard to add to ESPHome, but they would require some additional coding to determine what the number being read means over time. I haven't experimented much with these registers, but from what I gather, as a 16 bit integer, the max they can hold is around 0.2kWh. I do know that they are reset once read though. The Arduino library divides the output of APENERGYT by 100, then by 3200 to get kWh. |
Beta Was this translation helpful? Give feedback.
-
Fascinating! Please don't mind my excitement. I haven't coded in over 10 years, and this whole thing makes me want to come back. I see where that division by 100 (resolution 0.01CF) and then 3200 (MC of 3200imp/kWh) comes from. (from http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-46003-SE-M90E32AS-Datasheet.pdf) It appears as though Arduino library only implemented registers for Total active/reactive/apparent energy values. The per-phase values are commented/not implemented. I am now trying to understand what would it take to add the support for energy sensors in ESPHome. I can't seem to make a logical connection between "sensor" definition in YAML and how/where it gets interpreted and used to pull data from chip via atm90e32.h/atm90e32.cpp. |
Beta Was this translation helpful? Give feedback.
-
this commit is probably all bits of data I need to add support for pulling energy data from chip. what IDE would you recommend using? I would like to contribute, and recognize I need lots of guidance. Thanks for your patience! |
Beta Was this translation helpful? Give feedback.
-
Yes, that commit is exactly what I did to add other registers. For development I would recommend Atom with the platformio plugin installed. You'll want the dev build of ESPHome. Getting it to compile is a bit tricky at first because all of the dependencies have to be loaded. |
Beta Was this translation helpful? Give feedback.
-
Thanks! |
Beta Was this translation helpful? Give feedback.
-
OK, I think I'm more or less done with the implementation. Folks over at ESPHome Discord helped me ascertain where I made mistakes. I don't have a bench or some type of high-precision Wh-meter/Joule meter to estimate a Wh reading error, and therefore can't calibrate; but comparing to Kill-A-Watt (only measures to hundredth's of kWh) the reading is spot on. I tested by boiling a whole electric kettle of water several times. What's next? How can I get this into dev branch? Oh, and one more observation from the way it's implemented - upon reading the register, it is cleared. I might need to figure out a way to re-use or implement some type of sensor that "accumulates" the readings and then reports at less frequent intervals. My use case is to log this data in influxDB, but I recognize to make it usable more broadly, the integrated value over an hour or a day might be needed Code is in "energy-add" branch: https://github.com/elyorkhakimov/esphome/tree/energy-add This is an excerpt from the YAML:
|
Beta Was this translation helpful? Give feedback.
-
Excellent work! From here you can open a pull request with the dev branch of esphome. You'll have to do the same for the documents page, being sure to add examples of the new parameters and how they're used. |
Beta Was this translation helpful? Give feedback.
-
I had a chance to run my setup for few weeks now, and without any calibration of CT sensors (YHDC SCT-013 100A/50mA) spliced/extended with DIY unshielded twisted copper wire extension are giving about 1.51% error. For example, Solar inverter says it generated 22.48kWh, and my setup says 22.14, and from few days ago - 24.37 from sensor vs 24.74 from solar inverter. Both CTs are connected to IC2 (ct5 and ct6). The only global ESPHome adjustment I made was of the The DIY cable extensions are made using 2x 16AWG for first CT, and 2x 18AWG for the second CT, both stranded copper TFFN wires from HomeDepot. I locked two wires of 30ft length in drill chuck and then spun it. Really, eyeballed the number of twists. Then wires untwisted a bit, and I believe the effective extension length is about 28ft. I solder-spliced in this extension cable into existing 24AWG cable that was already attached to CT sensor. |
Beta Was this translation helpful? Give feedback.
-
Glad to hear you're getting fairly accurate results, and that the extensions worked! For the differences in IC1 and IC2, this is likely because of variance in the resistors. They are 1%. If you need to, you can calibrate each voltage input differently. For the CTs you can also adjust the calibration for a more accurate result. It may be easier to do all of the CTs at once, clamped around the same wire, with the same load. |
Beta Was this translation helpful? Give feedback.
-
@elyorkhakimov I assume you're no longer working on this? I'd really like to log "real" energy use instead of instantaneous loads. |
Beta Was this translation helpful? Give feedback.
-
Hi, I read through Microchip ATM90E32AS datasheet and the respective ESPHome page, but can't seem to understand how this energy meter is sampling data. I am currently running 6 channel meter (v1.4 rev1) with only 4 channels in use (waiting for more CT Clamps for the remaining 2 channels).
Question is really about the values that are send via MQTT.
In yaml file update_interval is set to 10 seconds. Does this mean that meter reports instant value of Voltage, Wattage, Current, Power factor, etc, at a given instant "t", and then after 10 seconds reports the instant value at "t+10sec" ? What about Wh readings?
Or, rather, does the meter sample with a specific sampling rate (what is it?) values for each of the sensors and takes an average of all values over the configured 10 seconds?
If there is a better place to ask these questions, please let me know and I will move this discussion there.
Beta Was this translation helpful? Give feedback.
All reactions