Newbie Q ... Grafana and InfluxQl


I’ve just put together a raspberry pi to monitor my new solar energy system. So a quick thank you to everyone at Grafana is probably first priority :slight_smile:

Versions … Grafana v 9.3.2 on 64 bit raspi os
Influx is V 1.8.10

I have a bar chart which records energy summaries … the influxql query is

SELECT last(“e_pv_day”) AS “Solar_summary”
, last(“e_dischg_day”) AS “Battery_Summary”
, last(“e_to_grid_day”) AS “Export_Summary”
FROM “inputs” WHERE $timeFilter GROUP BY time(1d) fill(previous)

And this produces a 3 bar bar chart. All good.

I’d like to add another bar, to summarize the power that I’ve saved on each day, but this is not available as a raw measurement. Instead I need to calculate it.

If I wanted a time series graph this is the query I would use to get my ‘Energy Saved’

SELECT ((“e_inv_day” - “e_rec_day”) - “e_to_grid_day”) AS “Energy_Saved” FROM “inputs” WHERE $timeFilter

But I need to be able to select the last entry of this data per day, and then add that to the working bar-chart query

I have tried

SELECT last(“e_inv_day” - “e_rec_day” - “e_to_grid_day”) AS “Energy_Saved” FROM “inputs” WHERE $timeFilter GROUP BY time(1d) fill(previous)

(and other variations of that with different parenthesis …)

Whenever I try this I always get a influxql error and no data returned.

Can someone tell me if this query is possible, and if so enlighten me as to the correct syntax, or am I facing a limitation of influxql ?

– Chris

PS Merry Christmas !!

Did you try this one?

  LAST("e_inv_day") - LAST("e_rec_day") - LAST("e_to_grid_day") AS "Energy_Saved" 
1 Like

Damn !! I didn’t think of that one.

Tried, tested and it works perfectly.

A big thank you for your help, and a double thank you for posting the answer on Christmas Eve ! I hope you had a good Christmas.

– Chris