Another kWh newbie question

So I have a CT sensor logging Watt values in influxDb (I believe every 10 seconds).
The CT sensor is on a pool filter pump that runs approximately 8 hs per day consuming about 2.2KW per hour = 2.2kWh
I’m trying to get Grafana to show this when I filter the view by the last 24hs.

I can sum all the values for the particular entity for the last 24hs, but then I need to divide it for the number of hours the pump was actually running and I’m not sure how to do that…

If the pump would be running ALL the time, I would divide the total sum of values by 24 and that would be it. but since it is not running all the time, I’m not sure how to do it…

I’m sure I’m not the first one trying to do this… is there any link or example of somebody that has already done it, that you can share…

I was hoping you guys could help me…
here is the query…
{
“xhrStatus”: “complete”,
“request”: {
“method”: “GET”,
“url”: “api/datasources/proxy/1/query”,
“params”: {
“db”: “homeassistant”,
“q”: “SELECT sum(“value”) / 24 FROM “W” WHERE (“entity_id” = ‘pool_power_monitor_total_watts_filter_pump_ct1andct2’) AND time >= now() - 24h GROUP BY time(15m) fill(null)”,
“epoch”: “ms”
},
“data”: null,
“precision”: “ms”
},
“response”: {
“results”: [
{
“statement_id”: 0,
“series”: [
{
“name”: “W”,
“columns”: [
“time”,
“sum”
],
“values”: [
[
1571944500000,
null
],
[
1571945400000,
8060.474999999999
],
[
1571946300000,
8130.712499999997
],
[
1571947200000,
8333.637499999999
],
[
1571948100000,
8312.941666666664
],
[
1571949000000,
8252.012499999999
],
[
1571949900000,
8321.245833333334
],
[
1571950800000,
3055.454166666666
],
[
1571951700000,
0.11666666666666671
],
[
1571952600000,
0.12916666666666674
],
[
1571953500000,
0.15416666666666676
],
[
1571954400000,
0.18750000000000008
],
[
1571955300000,
0.1625000000000001
],
[
1571956200000,
0.17500000000000007
],
[
1571957100000,
0.17916666666666672
],
[
1571958000000,
0.22500000000000006
],
[
1571958900000,
0.1958333333333334
],
[
1571959800000,
0.25000000000000006
],
[
1571960700000,
0.27083333333333337
],
[
1571961600000,
0.30833333333333335
],
[
1571962500000,
0.2166666666666667
],
[
1571963400000,
0.1166666666666667
],
[
1571964300000,
0.23333333333333336
],
[
1571965200000,
0.22083333333333335
],
[
1571966100000,
0.004166666666666667
],
[
1571967000000,
0.16666666666666674
],
[
1571967900000,
0.22500000000000006
],
[
1571968800000,
0.2625
],
[
1571969700000,
0.27083333333333337
],
[
1571970600000,
0.26666666666666666
],
[
1571971500000,
0.23750000000000004
],
[
1571972400000,
0.25000000000000006
],
[
1571973300000,
0.2166666666666667
],
[
1571974200000,
0.25833333333333336
],
[
1571975100000,
0.23750000000000004
],
[
1571976000000,
0.2291666666666667
],
[
1571976900000,
0.23750000000000004
],
[
1571977800000,
0.3125
],
[
1571978700000,
0.2083333333333334
],
[
1571979600000,
0.21250000000000005
],
[
1571980500000,
0.2166666666666667
],
[
1571981400000,
0.2625
],
[
1571982300000,
0.23750000000000004
],
[
1571983200000,
0.25000000000000006
],
[
1571984100000,
0.28750000000000003
],
[
1571985000000,
0.25833333333333336
],
[
1571985900000,
0.20833333333333337
],
[
1571986800000,
0.28750000000000003
],
[
1571987700000,
0.2833333333333334
],
[
1571988600000,
0.26666666666666666
],
[
1571989500000,
0.2541666666666667
],
[
1571990400000,
0.21250000000000005
],
[
1571991300000,
0.28750000000000003
],
[
1571992200000,
0.25000000000000006
],
[
1571993100000,
0.28750000000000003
],
[
1571994000000,
0.28750000000000003
],
[
1571994900000,
0.2625
],
[
1571995800000,
0.325
],
[
1571996700000,
0.23750000000000004
],
[
1571997600000,
0.3
],
[
1571998500000,
0.25833333333333336
],
[
1571999400000,
0.2625
],
[
1572000300000,
0.3
],
[
1572001200000,
0.23333333333333336
],
[
1572002100000,
0.28750000000000003
],
[
1572003000000,
0.4291666666666663
],
[
1572003900000,
0.3458333333333332
],
[
1572004800000,
0.3666666666666665
],
[
1572005700000,
0.3458333333333332
],
[
1572006600000,
0.3749999999999998
],
[
1572007500000,
0.35416666666666646
],
[
1572008400000,
4767.224999999999
],
[
1572009300000,
8742.758333333328
],
[
1572010200000,
8443.054166666667
],
[
1572011100000,
9575.549999999996
],
[
1572012000000,
9179.833333333332
],
[
1572012900000,
9390.108333333332
],
[
1572013800000,
9786.912499999997
],
[
1572014700000,
10046.383333333339
],
[
1572015600000,
9875.675000000001
],
[
1572016500000,
9397.691666666666
],
[
1572017400000,
9096.866666666667
],
[
1572018300000,
9404.420833333328
],
[
1572019200000,
8239.437500000004
],
[
1572020100000,
9726.141666666672
],
[
1572021000000,
10665.729166666666
],
[
1572021900000,
9171.425
],
[
1572022800000,
8137.112500000002
],
[
1572023700000,
8337.045833333335
],
[
1572024600000,
8137.741666666666
],
[
1572025500000,
8344.079166666665
],
[
1572026400000,
7940.125000000001
],
[
1572027300000,
8341.99166666667
],
[
1572028200000,
8142.137499999998
],
[
1572029100000,
8247.216666666669
],
[
1572030000000,
8061.658333333333
],
[
1572030900000,
8277.829166666666
]
]
}
]
}
]
}
}

Why can’t you use

Select integral(watts,1h) from measure

That would give you the average power consumed by the pump, you can get it as

Select average(watts) where watts>10 and time…

… assuming anything below 10 watts is CT noise.