Hello, I am new to this topic but have a question.
I use InfluxDB2.6.1 and feed the database with electricity data from my house and my solar system.
My smart meter measures data and so does my solar system.
The whole thing should be visualised in grafana.
I am familiar with simple queries, but when it comes to calculation, I am out. I have tried a lot using chat GPT, but it didn’t work the way I wanted or at all.
I want to calculate the amount of electricity that is directly consumed by my house when the solar system is providing electricity and the amount that is fed into the grid from surplus.
The daily yield of the solar system is measured at the inverter and recalculated daily. So in the evening I can see how much the solar system has generated today.
My smart electricity meter counts the amount of electricity consumed from the grid and the amount I feed into the grid.
Both are absolute values that are counted up.
To calculate the direct consumption of the inverter, I have to calculate as follows:
Direct consumption = Today’s production solar - (current feed-in number - feed-in number the day before at 23:59).
A query of today’s production is simple, it is straightforward.
A query of the current count is also simple.
A query for the value that was at 23:59 the previous day is not so simple. Every time I tried using Chat GPT, I got errors because you can’t subtract or add time intervals. Or a value came out that was not correct.
So my question is, what is the best way to carry out such a calculation?
Or should I rather do the whole thing in Grafana and if so, how?
Thanks a lot
To do a query for the value that was at 23:59 the previous day, would something like this work? I am not sure how often you are collecting the data, so if the last data point collected yesterday was at 23:45, then this query would close, but not perfect.
The last datapoint on the counter for electricity in the grid is at this time when the solar plant is not producing so when the sunset occurrs.
Round about 22 or in summer at least 23 I think. So every value between 23:00 the day befor or 2 o´clock in the morning will be the same count.
Now it comes to calculations: Should I calculate in influxDB or should I do that with expressions in Grafana?
I mean the possibility of grafana to use “total” or “difference” in the value options are only reagarding one graf, like to calculate the difference of start and stop. That is working when I want to know how much consumption from the grid I have or how much I put in the grid.
But it is not works when it comes to calculation with miltiple grafs (in worst case out of different buckets).
Both queries work on its own when I miss the t1= and t2= in Influx and in Grafana and return two seperate values.
When I use the t1=… this error occurs
“invalid: error in query specification while starting program: this Flux script returns no streaming data. Consider adding a “yield” or invoking streaming functions directly, without performing an assignment”
The result function does not work, because of not using t1 and t2.
In Grafana it is possible to use expressions to “tag” every query and do some math with these expressions, but I don´t get hit how to use it.
Here are screenshots of the expression what I have done so far:
Thanks for the querry:
No error occurs. Result see in the screenshot.
129.4 was the value from yesteday.
The value from today is 129.5 (cloudy and rainy day today), the value is not shown.
And the result is also not shown should be 0.1 for yesterday and today.