Graphing energy usage in Grafana

Thanks for your answer, I will study it.

My goal is (relatively) simple:

for the main (I have a Efergy Hub) I want to have the instant power (this I have from the component) and the energy consumed in last hour, last day, last week, last month … eventually rolling (rolling day, rolling week, rolling month) and/or from beginning of a period (last hour, from midnight to now, from first of week to now, from first of month to now) and keeping the data stored/visible in some way that it is easy to check.

The same I would like to do for some appliances (I do have Sonoff POW, Neo coolcam zwave, Broadlink SP3, xiaomi zigbee switch) which all give instant power but is very confusing how they calculate the energy, I am sure you know what I mean

Yes this is exactly what I want for the energy today

you use hassio?

How/where you do those queries, or its done inside grafana (newb here)

I do not understand very well. I got this, is it the same?

AH now I see query inspector, I get this

xhrStatus:“complete”
request:Object
method:“GET”
url:“api/datasources/proxy/1/query”
params:Object
db:“home_assistant”
q:“SELECT cumulative_sum(mean(“value”)) FROM “W” WHERE (“entity_id” = ‘efergy_802171’) AND time >= now() - 6h GROUP BY time(20s) fill(null);SELECT mean(“value”) FROM “W” WHERE (“entity_id” = ‘neo_coolcam_power_plug_12a_power’) AND time >= now() - 6h GROUP BY time(20s) fill(null);SELECT mean(“value”) FROM “W” WHERE (“entity_id” = ‘neo_coolcam_power_plug_12a_power_2’) AND time >= now() - 6h GROUP BY time(20s) fill(null)”
epoch:“ms”
data:null
precision:“ms”
response:Object
results:Array[3]
0:Object
1:Object
2:Object

Hi @anon35356645,
no I don’t use Hassio, I use the HA Docker container on a Ubuntu host. It works pretty well so far.

My Continuous Queries are done in Influxdb, you can read them above. I then use Grafana to graph the results.

It looks like in your Grafana query you sum the mean values from your Efergy monitor, which I guess must be instant power readings. I don’t think that will work, as you need to calculate energy use (in wh or Kwh) from the instant power readings (in w or Kw).

My flow is somewhat complicated, as I read the power into an Influxdb database, calculate energy with the integral function, graph in Grafana and use the Influxdb sensor in HA to read for example ‘Energy consumed yesterday’.
I can go through it step by step if you’re really interested.

For things like lights that have fixed power, I think it can be done directly in HA, though I haven’t tried, but this looks good: Calculate power usage

1 Like

Could you go through this step by step Manu? Want to achieve exactly the same thing as you, but have been unsuccessful untill now…

1 Like

How do you guys do “Monthly” graphing… ie calculate your monthly values. Influxdb doesn’t have “GROUP BY MONTH”

I’m also very interested in this! The “difference” selector helped me get the good values when I want “day to day-bars” but when I try this per week instead it gives me totally wrong values… before I knew how to make grafana queries I used to reset zwave-nodes every new week and just fetch the last value in grafana, that gave me the right numbers, but I also skrew up the counter making grafana less effective… I felt that it was the wrong way to use it.

Now I use difference with a counter that doens get reset, it constantly grows and when I try the query below I get a value like 30kHw but I know that it actually should be like 68kHw… why does it not show the exact numbers?

SELECT difference(mean(“value”)) FROM “kWh” WHERE (“entity_id” = ‘pump_energy_kwh’) AND $timeFilter GROUP BY time(1w) fill(null)

For those wanting a simpler solution: in 0.87 you can use the utility sensor to achieve daily and hourly kWh readings and feed those into influxdb

2 Likes

Yep, and I did a little write-up for those using the DSMR component (or any other way that results in separate sensors for each power tariff) and will add that to the component’s docs as well tomorrow…

oh and I forgot about this thread, but for those interested, I have figured out a basic dashboard in grafana which is discussed in this thread. I have included a link to a blogpost on it and the json to import the dashboard into your own grafana instance.

Hope it helps someone :slight_smile:

1 Like

It sure does! Thanks!

And the docs for the utility meter component have just been updated to reflect DSMR specific setup: https://www.home-assistant.io/components/utility_meter/

Totally forgot this thread, I solved my issues using the “last” instead of “mean” value in the grafana query. Now I have exact values in my graphs for everyday/week or whatever consumption

Also I have singlestat meters that reset for every day using “difference” and “last” also

Mabye it helps someone :slight_smile:

Although the utility-meter seems nice I prefer to have it in a grafana-dashboard

8 Likes

Looks awesome! Could you share your dashboard’s JSON?

Sorry for the late reply, is this what you wanted?

json model.yaml (159.3 KB)

2 Likes

Hi, I’m a new influxdb/grafana user. I setup daily bar graph for energy consumption and i noticed that bars are resetting at utc time an not at local 00:00. How did you manage this issue (if you did it)?

Hi,

This seems to be a common problem. Even called a bug by a few. I managed to solve it way back. I cant remember the exact thread but this one is pretty close, take a look: https://community.grafana.com/t/wrong-value-in-graph-with-bars/1306/36

Hope it helps :slight_smile:

Ok, i solved daily bar charts adding GROUP BY “time(24h,22h)”, but i have no idea how to have a monthly bar chart… I think that a GROUP BY “time(30d)” doesn’t do the job…
Do you use monthly bars? How?