Wattage monitoring - I've no flipping idea what I'm doing, help! - Page 1
Forum section: electronics / beginners

author: rthorntn
author_rank: Frequent Contributor
timestamp: February 29, 2024, 01:17:59 am
content: Hi,I have power data (Shelly 3EM with CT clamps), it gives me a power "value" (watts) from the sensor at least once every 15 seconds, it basically sends updates faster if it decides the "value" has changed enough.I can see the same power data from other sensors (power company and inverter) and I can see that my my influxdb derived values are 10-30% off over 24 hours, I think the culprit is adding an hours worth of values together and then dividing it by the number of values ("mean" aggregate data in 1 hour chunks) is the right way for power data?The results are pretty close if I "mean" aggregate data in 15 second chunks.This is what I'm looking for, a time series with data points like this:14:00-15:00 - 6524w15:00-16:00 - 5987w16:00-17:00 - 4876wWith this data set, what is the math to get me to the actual power used in an hour?Thanks.Richard

author: Andy Watson
author_rank: Super Contributor
timestamp: February 29, 2024, 01:55:34 am
content: You only mention watts. Is this the only measurement or are some of your instruments also sensitive to, or registering reactive power ?

author: rthorntn
author_rank: Frequent Contributor
timestamp: February 29, 2024, 02:14:26 am
content: Thanks, apologies, I don't know much about power, especially AC, do you mean the power factor?The Shelly web UI gives me:Voltage - 226.9 VCurrent - 13.678 AActive power - 3.09 kWApparent power - 3102 VAPower factor - 1Frequency - 50 HzEnergy last minuteActive - 51.764 WhActive returned - 0 mWMQTT gives me most of that but not the last minute, it gives me total instead:total_act_energy - 134882.85total_act_ret_ energy - 283273.12I'm storing Active Power in a database and querying it to try to make hourly usage totals.CheersRichard

author: IanB
author_rank: Super Contributor
timestamp: February 29, 2024, 02:45:31 am
content: Quote from: rthorntn on February 29, 2024, 01:17:59 amNot only power, but for any consumption data, really.QuoteLet's suppose you have a data set as a list of pairs: Time stamp, Power recorded at this instantLet the list be like this:T1, P1T2, P2T3, P3T4, P4etc.T is time in hours and fractional hours, P is power in kW at time T.Then what you do is take successive pairs, and accumulate a total pair by pair. For example:Total = 0Total = Total + 0.5 * (P2 + P1) * (T2 - T1)Total = Total + 0.5 * (P3 + P2) * (T3 - T2)Total = Total + 0.5 * (P4 + P3) * (T4 - T3)etc.You can probably set this up in a spreadsheet.What this is doing is taking the average power over each interval and multiplying it by the length of the interval, to give the power consumption in kWh for that interval.If you accumulate this total over the span of an hour, you will have the total consumption over that hour in kWh, which coincidentally will be the average power consumption for that one hour period.Do this computation hour by hour, and you will have the summary you are looking for.

author: rthorntn
author_rank: Frequent Contributor
timestamp: February 29, 2024, 02:56:01 am
content: Thanks, would it be smarter to store:total_act_energy - 134882.85Every minute and then subtract the new value from the previous value?14:00 total_act_energy - 13488214:01 total_act_energy - 134889 (7w)14:02 total_act_energy - 134898 (9w)14:03 total_act_energy - 134905 (7w)14:04 total_act_energy - 134915 (10w)14:05 total_act_energy - 134965 (50w)So the power used in 5 minutes was 83w?

author: donlisms
author_rank: Frequent Contributor
timestamp: February 29, 2024, 03:35:20 am
content: I think it depends on how you're managing the data and how you're producing the results. You talk a little about hourly usage, as well as per-minute usage; I'm guessing you really want minutes. Sometimes. Maybe.From a software perspective, I think I'd just capture the raw data in one form or another, which may very well be just the total, at the chosen resolution (every minute or every hour). Time/total pairs, using IanB's averaging technique. My preference would be to do the average or difference as part of the reporting; let's say I ask for the power overnight 12 hours, pick two data points, subtract the totals, and there you go. Or ask for hour summaries, but then split out an interesting hour into minutes.On the other hand, if there's no chance to do any computing "later", then something similar to what you described could be done "up front" at the chosen interval. You might see how that kinda locks you in to the interval, because you get one chance to do the subtraction, but maybe that's okay, I don't know!

author: Rick Law
author_rank: Super Contributor
timestamp: February 29, 2024, 03:38:44 am
content: After scanning the "User and Safety guide" for the Shelly 3EM, what you may be seeing is (in their words), momentary. Per the user guide,the display of Watt Usage is the Watt being used at that moment. In the app shown in the user guide, they did not sum or average it for you. From what you wrote, I think you already got that. They didn't sum or aggregate data form you. You have to get the data frequently and sum it yourself.If my interpretation of the user guide is right that the data reported is "momentary" data, this is the scenario:Think of it this way, if you have a 100 watt light bulb and that is the only thing being monitored.At the start of 1am, it was off, it turned on at 1:30am. At 2:00 am, the data is read.Soat 2:00am it shows 100W, you don't know thatit was not ON between 1:00am to 1:30am.Since it read 100 Watts and if you assumed 100Watt-Hour used, you would be exactly 100% off. You used only 50 Watt-Hour.If my interpretation is indeed correct, you should probably read the data more frequent and sum it yourself. Say if you read it 1 second interval:1:00:00am = 01:00:01am = 01:00:02am = 0...1:29:59am = 01:30:00am = 100W (this second) = 100/3600 watt hour (3600 seconds/hour)1:30:01am = 100W (this second) = 100/3600 watt hour (3600 seconds/hour)...So at the end, you have 1800 seconds (readings) of 100W/3600 Watt-Hour. Which would give you 50WattHour.You should test my interpretation that the number transmitted is "momentary". User Guides are often difficult to decode. Hook that darn thing up with something that use a constant amount (like a light bulb), keep it on for the whole hour and see what it reads. Then, do 1/2 hour on and 1/2 hour off and see what it reads.Personally, I would prefer to go to 1 second instead of 15 seconds interval -- unless the data collection time is sluggish and need more that 1 second to do. Going 15 seconds would expose you to 15 seconds worth of wattage error if something just turned on immediately after a reading is done. With a longer duration, you may have to worry above averaging last and current reading. A 1 second (or even 0.1 second), that reduces the need to worry about that. Your max error would be "max watt thing you can turn on or off" divide by 3600 for the 1 second read. Your program needs to do more summing, but your program likely wont complain about have to do so much more arithmetic. So, sum it as quickly as the data collection / transmission time permits.If you do want to stick to 15 seconds, each hour has 240 chunks of 15 second (3600/15=240), so read the watt and you have watt/240 WattHour.Reference: The User Guide I found on line:https://kb.shelly.cloud/__attachments/63832224/User%20and%20Safety%20Guide?inst-v=1ab960e4-071b-4043-9129-82bd66a757fc

author: rthorntn
author_rank: Frequent Contributor
timestamp: February 29, 2024, 04:31:12 am
content: Thanks, I'm now capturing:Active PowerTotal Active EnergyTotal Active Return EnergyTotal Active Energy and Total Active Return Energy update every minute and (calculating the difference between the latest reading and the previous one) they seem to give me the intended result.No point reinventing the wheel I guess

author: IanB
author_rank: Super Contributor
timestamp: February 29, 2024, 04:32:31 am
content: Quote from: donlisms on February 29, 2024, 03:35:20 amTo be clear, my post was assuming time/instantaneous value pairs reported by the measuring device, like this:Quote from: Rick Law on February 29, 2024, 03:38:44 amThat's why I described how to do the totalizing afterwards.Considering this point:Quote from: Rick Law on February 29, 2024, 03:38:44 amWe also have this:Quote from: rthorntn on February 29, 2024, 01:17:59 amThis means you should not be exposed to a 15 second error, if the device samples more frequently when the power is changing rapidly.The algorithm I posted does not rely on fixed reporting intervals, so it will remain accurate with uneven spacing.

author: IanB
author_rank: Super Contributor
timestamp: February 29, 2024, 04:33:11 am
content: Quote from: rthorntn on February 29, 2024, 04:31:12 amPerfect.

author: jonpaul
author_rank: Super Contributor
timestamp: February 29, 2024, 01:57:34 pm
content: integrate for KWH.We Use professional instruments and CT like Yokogawa and Hoili, not consumerj