I have a PV on my balcony and a smart meter to log my power usage (total power in Watt).
I managed to calculate the Energy (kWh) via integral while power_pv is the power of the PV.
SELECT SUM("integral") AS sum
FROM (
SELECT INTEGRAL("mean")/3600000 AS integral
FROM (
SELECT MEAN("value") AS mean
FROM "power_pv"
WHERE "value" > 0
GROUP BY time(3s) fill(0)
)
)
GROUP BY time(1d)
tz('Europe/Berlin')
Now I want to subtract the Power which is not used by myself, marked with a negative score from my smart meter. The integral of power_pv - p_total (where P_total<0) should be the PV-Energy which is used by myself. To make it short: I want to subtract both queries
SELECT SUM("integral") AS sum
FROM (
SELECT INTEGRAL("mean")/-3600000 AS integral
FROM (
SELECT MEAN("value") AS mean
FROM "P_total"
WHERE "value" < 0
GROUP BY time(3s) fill(0)
)
)
GROUP BY time(1d)
tz('Europe/Berlin')
Any ideas?