Wrong values returned by REST API? - explained

This is a query for today, midnight to the present time. Your expression is:

If you add up the total of each of those values, what do you get? Let’s say that the data is this:

Phase1 = 3000Wh
Phase2 = 3200Wh
Phase3 = 3100Wh
Tesla1 = 1000Wh
Tesla2 = 1000Wh
Tesla3 = 1000Wh
Pool = 0Wh
Solar1 = -2800Wh
Solar2 = -3100Wh
AC1 = 0
AC2 = 0
AC3 = 0
HotWater = 1500Wh

Adding those up I get 7,900Wh. 0 is less than 7,900 Wh so the function evaluates to zero.

As long as the solar generation is less than the sum of the other inputs in the formula, for the entire period, the result will always be zero. Very few houses maintain net zero or better. Most all use more power than they generate and so have a net positive value.

Now if you run that query for say begin=s-1h&end=s, &group=all in the middle of a sunny day, you will probably get a negative number.

As you said above:

You get a series of values for each minute of the day. 1,440 of them. If you ad them up, you will get the integration of your function over the day. IoTaWatt does not provide an integrated result when you ask for “all”. It evaluates the expression using the net values of the operands over the requested period (all).

You can get an integration for a day using Graph+. Just plot the function for the day in question and click the statistics tab at the bottom. The integrated Wh will be showh in the rightmost column, integrated to 2 minute resolution.

Mission one for the IoTaWatt is to sample and save the raw measurements. Because of the limitations of the ESP8266 environment, it does not sample while doing a query, so extensive SDcard I/O to read 17,280 datalog records from an SDcard to integrate a day’s worth of detail is not practical. The way data is organized, you can rapidly retrieve many metrics and get total net or average usage for any time period. It just doesn’t integrate to break down a net value into it’s positive and negative components.