Emoncms calculation question

I have a question regarding a calculation problem in Emoncms that I cannot explain:

I have an EmonTx running with one voltage sensor and three current probes. Power values for phase 2 and 3 are calculated using a timeshifted voltage reading from a table. This seems to work very well as I am seeing a better than +/- 2% accuracy comparing the data to my Ferraris meter readings over ~3 months.

On phase 1 I have positive and negative mains power values because my PV system is feeding into this phase. So always when the PV power is bigger than the consumption on this phase, I get a negative reading. All this data is logged with Emoncms on a RasPi. Presentation of this data including negative values works perfect.

Now, when I zoom into the data in a region with negative power values, the average is correctly shown as (e.g.) -350W, but the energy sum is always positive like: Average: -350W | 1.6kWh. This is due to Math.abs being used on the result of (only) the energy value calculation (in proc.js). I do not know the reason for this, but ok, maybe nobody thought of negative 'consumption' values when doing this.

To make the calculation work with negative values I removed the Math.abs from the energy calculation. If I now zoom into a region with negative power (excess PV power), I get correct readings of (e.g.) Average -350W | -1.6kWh.

Hmmm, but the problem now is that I also get negative Energy readings when I zoom into a region with only positive power readings, like Average: 170W | -0.17kWh  !?! The calculated value seems to be correct but with wrong sign.

This is not always the case, but only if the integration interval is smaller than ~1 to 1.5 hours (?).

How can this happen? Any ideas?

BR, Jörg.

 

 

 

 

 

 

TrystanLea's picture

Re: Emoncms calculation question

Hello Jorg,

The issue is due to line 384 here: 

https://github.com/emoncms/emoncms/blob/master/Modules/feed/feed_model.php

$sql = "SELECT time, data FROM $feedname".
          " WHERE time BETWEEN $start AND $end ORDER BY time DESC";

Im not sure why I put DESC here, I have a vague recollection there was a reason for it, but cant remember now, so we can probably change it to Asc and remove the Math.abs bit

Trystan

JBecker's picture

Re: Emoncms calculation question

Ah,

Trystan, thanks for the hint! I will try to change it this evening. 

BR, Jörg.

 

JBecker's picture

Re: Emoncms calculation question

Sorry Trystan, doesn't help for me. I get exactly the same result.

Always if the time interval is smaller than 5000 (~1hour 22 minutes), the calculated kwhs have the wrong sign.

Ups, it works!

I have two installations and made the change on the wrong one! Sorry!

BR, Jörg.

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.