The days on which the electricity price changes I have entered manually via the line protocol.
is it somehow possible to multiply the daily yield with the last value of the electricity price?
e.g. multiply yesterday’s yield with the value from 1.1. since that was the last change in the electricity price.
This is more of a Flux question than a Grafana question, so can you switch over to Influx Data Explorer and post the two queries and their output? (I presume the electricity price is being stored in a different measurement…I think it should, and should be easy to do if you are sending it into InfluxDB using line protocol)
import "date"
month = date.truncate(t: now(), unit: 1mo)
yield = from(bucket: "inverter")
|> range(start: month)
|> filter(fn: (r) => r["_measurement"] == "dailyenergy")
|> filter(fn: (r) => r["_field"] == "value")
|> aggregateWindow(every: 1d, fn: last, createEmpty: false, timeSrc: "_start")
|> yield(name: "last")
and separately
price = from(bucket: "inverter") // or whatever your bucket name is that stores the price
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "price") // or whatever you call it
|> filter(fn: (r) => r[".. // add your filters here
|> filter(fn: (r) => r["...
|> last()
I think the non-working query just needs to have a yield statement, like this. Can you confirm this works? Then we can proceed to try to do a join or union or something to accomplish what you want to do.
price = from(bucket: "strompreis")
|> range(start: -2y) // I assume the latest update to price would happen in the past 2 years
|> filter(fn: (r) => r["_measurement"] == "verkauf")
|> filter(fn: (r) => r["_field"] == "abnahmetarif")
|> last()
|> yield(name: "price")
If I am understanding this it always tell me the last value of the last 2 years. But how can i now link the values so that the values at the time of day are multiplied by the last price?
e.g. the daily yield of 28th February multiplied by the price of 1st January and the daily yield of 1st March multiplied by the price of 1st March.
I prefer to do as much of the mathematical computations in the query (whether SQL or InfluxDB or whatever), and then have Grafana do the visualization and/or alerting.
I am tied up for a bit, but will try to revisit this later.
Am I correct to assume you are trying to do this? (my syntax is not correct…this is just for you to confirm what you are trying to do). Note that I have added range and sum functions to each query.
It tells me that a yield function is missing and I can not write “yield(cc)” or “yield(name: last)”.
I also don’t understand the calculation “cc = aa + bb” this would be to easy for Flux
Is there a possibility to create a query which takes the last price for every day since there is a new one? Because I already have all values I need in a table in Grafana just the price is missing.
And then I multiplicate the sum with a price I write down manually which could be realistic:
Last step was to get the difference of $I and $J
In the Query Options I also added a relative time to see all days in the current month
Yes I know that it would be better to do all the calculations in Flux but I am not a Flux expert and I find Grafana very beginner friendly and easy to use which is why I do more in Grafana than with the Flux language.
I know it’s a lot but I want to give you an overview of what my goal would be. Maybe you can tell me here what would be the easiest way for a Flux amateur.
The queries and formula (cc = aa - bb) were just to make clear what I thought you were trying to do, but it would not work in Influx (that’s why I said “my syntax is not correct”). Anyway…
Your original question was just about how to combine price (in measurement “verkauf”) with the yield (in measurement “tagesenergie”), and we solved that earlier. The table and formulas (in Grafana) that you showed all seem to work well, so what else remains?
I did want to mention the spread function, which is basically doing last() - first() . Since you have a meter that is always accumulating (right?), and you only care about each day, I believe you could get your daily data for A+B+C as follows:
|> aggregateWindow(every: 1d, fn:spread) // this computes the spread between the first and last value of each phase over each day. If you stopped your function here, you would get 3 values (one for each phase) for each calendar day
|> aggregateWindow(every: 1d, fn:sum) // this would sum the 3 amounts in each calendar day, i.e. it would do what you are doing in expression G
Maybe try out the above in Influx Data Explorer first.
All daily values are multiplied by the last value of the price. I will try to make a script which produces a list for every day and the daily price of the current and then I will easily multiplicate this in Grafana.
The negative thing is that only the electricity price of the previous year is displayed and the column for the current year remains empty. Furthermore, it requires some human effort.
If there isn’t a easier way I would say thanks for your time and have a nice day