Calculation of consumption over a period and then converting it into currency

  • What Grafana version and what operating system are you using?
    Grafana v10.1.1 (0cfa76b22d) on Ubuntu 18.04
    The database I’m using is InfluxDB.
    InfluxDB v1.7.6 (git: 1.7 01c8dd416270f424ab0c40f9291e269ac6921964)
    Chronograf Version: 1.7.11
    Grafana v10.1.1 (0cfa76b22d)
    I plan to upgrade InfluxDB to version 2 or 3, so if it’s necessary to do so, please let me know.

Example of Watt-hour (Wh) data retrieved from InfluxDB.
WattHeure (Wh)

2023-09-11 17:16:00

2023-09-11 17:17:00

2023-09-11 17:18:00

2023-09-11 17:19:00

2023-09-11 17:23:00

2023-09-11 17:24:00

2023-09-11 17:29:00

2023-09-11 17:30:00

I’m trying to retrieve kWh consumption on the left side and convert it into euros on the right side for different periods: current, last 24 hours, last month, and last year (365 days). I believe I can figure out a solution for months and years, but I need assistance in finding the best query for the current period and the last 24 hours.

Currently, the query I’m using to calculate consumed WattHours in the specified time range appears to be correct:
SELECT MAX("Energy [Wh]") - MIN("Energy [Wh]") as "Consommation sélectionnée (kWh)" FROM "watts" WHERE ("host" = 'PZEM-004t-v3-1') AND $timeFilter

However, I’m struggling to convert this value into euros on the left panels, and it seems like the displayed values don’t match my expectations.

Here’s the query I attempted, but I’m not sure of its accuracy for converting to euros:
SELECT ((MAX("Energy [Wh]") - MIN("Energy [Wh]")) / 1000 * 0.145 ) as "Consommation sélectionnée (kWh)" FROM "watts" WHERE ("host" = 'PZEM-004t-v3-1') AND $timeFilter

I’m also trying to determine if it’s feasible to obtain the cost of consumed watts during off-peak (0.1672/KWh) and peak hours (0.2285/KWh) based on the time within the period (e.g., peak hours from 07:30 to 23:30 with a rate of 0.2285/KWh), and the same for off-peak hours (as shown in the screenshot). Then, I would like to use transformation functions to aggregate both and obtain an accurate total.

I hope I’ve provided enough details for you to help me achieve this.

Your Grafana and InfluxDB setup looks good. For your complex kWh to euro conversion and time-based cost calculation, it might require more advanced queries and possibly custom transformations. Consider consulting the Grafana community or documentation for guidance on these specific calculations. Good luck with your energy consumption analysis!

1 Like

Thank you very much for your response @faizan9872

Otherwise, last night, while thinking about it, I wonder if in my Python script that sends data to the Influx database, I could add a tag like “off-peak” or “peak” based on the time at which the script runs. This could be useful in Grafana as a condition, allowing me to calculate kilowatt-hours only when the correct tag variable matches. I’m not sure if others have successfully tested this ?

Does anyone have any ideas for me, please ?
Add post to for complet info