Hi folks,
I am very new to all this, I had some SQL experience years ago so the concepts feel familiar but assuming I know nothing, or worse have made some faulty assumptions, is where my head is right now so please bear that in mind when I ask inevitably stupid stuff !
Specifics… Well as close as I can get right now.
I have an Influx database, and Grafana, running on a Home Assistant RPI
One of my sensors, so data, is kWh, and is attached to multiple entities.
I am not going to pretend that I know the table/s structure but obviously it must contain a timestamp and the data at least.
I built this, using the GUI :-
SELECT max(“value”) FROM “kWh” WHERE (“entity_id”::tag = ‘caravan_and_workshop_4_1d’) AND $timeFilter ORDER BY time DESC
and then modified it to :-
SELECT “value” AS “Caravan” FROM “kWh” WHERE (“entity_id”::tag = ‘caravan_and_workshop_4_1d’) AND $timeFilter GROUP BY interval_day
with an aggregate MAX in the value options of the card.
The latter, sort of works but there is a data anomaly causing a problem.
The data is collected every minute, and being cumulative, is an ascending value.
For any $TimeFilter period, or any other method of getting a dataset, I need to group by a date, not time, and return a Max value.
The issue is that the first record in most ‘days’ is actually the last value of the previous day, typically captured 15-20 seconds after midnight so at 00:10… I have 10 records but only 9 of them are actually the correct day, from a value perspective, with all having a timestamp, and associated date for the group, that is in range.
Timeshift seemed an obvious solution but I cant get it to work, mor likely do not know what I am doing, so I started looking at how to do something like this:-
SELECT “value” AS “Caravan” FROM “kWh”
WHERE (“entity_id”::tag = ‘caravan_and_workshop_4_1d’) AND $timeFilter AND time > 00:01:00.000
GROUP BY interval_day
AND time > 00:01:00.000 just gives me an error and I have tried multiple ways of specifying the time to do this but none so far have helped.
A couple of attempts, looked promising, not that I can remember which, but anything that wasn’t simply wrong syntax complained about not being able to compare time to a literal.
Obviously I am missing something and data anomalies like this are common so this must be possible and should be easy…
Please help if you can… I am feeling more than a little silly here, filter by time or drop the first record of a row set is hardly rocket science.
Cheers,
Al