Using grafana+influx in a container which collects daily info from my electrical system.
I wish to select just the data between 14:00 and 21:00 for a particular month, so that I can determine the max value (amount of power I am drawing from the grid) during that daily period over the month.
I was just about to learn how to use flux to perform the query, and saw it is going EOL because influxql is the cool way to do things going forward. I hope this means that there is some way to perform this query, such as regular expressions in date/time strings, perhaps?
Hi @permezel and welcome to the Influx Community Forum.
Which version of InfluxDB are you running now, and when you set it up as a data source in Grafana, did you choose InfluxQL, Flux, or SQL?
To the best of my knowledge, InfluxQL cannot select the data only for a range of hours during the day. Flux definitely has that function and SQL probably can do it.
BTW, Flux is not dead.
Hi @grant1 . I am running 1.8. It is part of GitHub - jasonacox/Powerwall-Dashboard: Grafana Monitoring Dashboard for Tesla Solar and Powerwall Systems.
The data source uses InfluxQL. I added another source with Flux (not sure if this is a thing: multiple query languages functioning), and was about to try to figure out how to query it and ran into the statement that Flux was in maintenance mode, so did not want to waste time learning it.
Actually, now that I spend about 3 minutes just now looking again at the flux syntax page, it looks cool, so I will forge on!
Edit: that was easy. Ended up with:
import "date"
from(bucket: "powerwall")
|> range(start: -60d)
|> filter(fn: (r) => r._field == "from_grid")
|> filter(fn: (r) => {
tod = float(v: date.hour(t: r._time)+10) + float(v: date.minute(t: r._time)) / 60.0
return (tod >= 16.0 and tod < 20.5)
})
Nice work @permezel
Just out of curiosity, did you try hourSelection() function | Flux Documentation ?
I did try hourSelection()
, even though it lacked support for fractional hours. It did not seem to work, and when I replaced it with date.hour()
filter, it did work. Banging my head against various things in parallel as I learned how things worked, so perhaps some other failure made me think it was not working, but my memory of events at that time was that as soon as I replaced hourSelection()
with the filter expression, using the same WEB session, editing the query in place, expected results were evident.
Now I need to run through some of the intro tutorials and come up with the final query, which will give me the max over each time period, and a max over a month of such maxima, …
I just want to see how come my energy supplier is billing me for a demand charge, which they calculate as the max instantaneous energy spike over the demand window over the billing period (month, I think) times the demand cost (penalty) in $$. It annoys me to keep getting this charge (although I agree with it in principle) and I want to know when I screwed up so I can avoid it.
A nice Grafana dashboard summarizing this is my eventual goal, but lots more to learn first.