When we moved into our house a few years ago, a so called “smart meter” had been installed in the utility closet. It tracks electricity and gas usage in realtime and has a serial port that can be used to get readouts from the device. Meaning I have direct access to my own data. Awesome!
Next to the smart meter, I have an Intel NUC running Home Assistant (HA) in my utility closet. With the HassIO version of HA, it is extremely easy to add InfluxDB to store all data, and Grafana to visualise that data. Let’s have a look how to create the dashboard above.
TL;DR Just give me the dashboard
If you are familiar with building dashboards in Grafana and just want the JSON to import this to your setup (and tweak it for your database- and sensor names!), you can find the code at my Gitlab repo.
How it works
Starting with the two gauges in the top left corner. They are pretty straightforward and show current electricity and gas consumption respectively. Both queries select the last known value of their respective sensors. There is a little bit of tweaking required to get the electricity gauge working consistently the way I want it to.
Current power usage (gauge)
HA entity id: sensor.power_consumption
SELECT last(value) * 1000 FROM "Kw"
WHERE ("entity_id" = 'power_consumption')
GROUP BY time($_interval) fill(null)
This query will select the last value from the sensor and multiply the value by 1000 in order to get a reading in Watts. However, the “options” tab for this gauge is where the display settings need a bit of tweaking:
As you can see I have chosen to use a Postfix text (W) to display and select “none” for Unit. I did that because when using Watts as “Unit”, when electricity usage goes above 1000W (1kW), the unit automatically changes from Watt to kW with a decimal point to indicate fractions of kW’s, which is not what I wanted. Finally, tweaking the “Tresholds” value in the “Coloring” column, is what makes the gauge show different colors depending on the value of the query. With the tresholds set to “150,1500”, the gauge will show light yellow if the value < 150W, green when 150< value < 1500, and red value > 1500W.
Current gas consumptoin (gauge)
HA entity id: sensor.hourly_gas_consumption
SELECT last("value") FROM "m3/h"
WHERE ("entity_id" = 'hourly_gas_consumption')
GROUP BY time(1m) fill(null)
This sensor is actually an estimation of hourly rate of gas consumption based on readings and not a real time status of gas currently being used. Tweaking the colors for the display is of course very similar to the electricity gauge above.
The next two graphs are actually the same queries, but with different time ranges, the top right uses “past hour” and the middle row uses “past 24 hours”. Both show power (green) and gas consumption (blue) in the same graph. The X axis shows the time, and the Y axis shows the units for both queries; kW on the left side of the graph, m3/h gas on the right:
This graph uses two queries as its input, both based on the same sensor data as used in the gauges mentioned above:
To make the graph look the way it does, we need to set the left and right Y-axis labels and units. If you want, you can set minimum and maximum values for both Y-axis sides as well as number of decimals:
Finally, the “Past 7 days” graphs at the bottom of the page. Those are a bit more complicated to setup, but not much. We’ll look at the electricity one as that one requires the most work. It shows electricity usage for the past 7 days in stacked bars. My metering plan means that I pay two different prices for electricity, depending on time of day. Between 23:00 (11pm) and 07:00 (7am), prices are slightly lower then during the rest of the day. The graph shows the two different tariffs stacked on top of each other; blue being nights and weekends (hence two blue-only bars, those represent saturday and sunday). First let’s look at the queries:
As you can see, the queries for this graph are not constructed using the default interface. If you click the hamburger icon (3 stacked horizontal lines, next to the eye and the thrash can) on the right of the query editor and click “toggle edit mode”, you can enter a query in plain text. It allows for more complex setups that can otherwise not be created in the default query editor. Let’s have a look at the query:
SELECT last("value") - first("value")
WHERE ("entity_id" = 'power_consumption_low')
GROUP BY time(1d)
The query selects the first and last value of a day for the low-tariff power meter and subtracts the last value from the first, resulting in the delta indicating power consumed in the tariff for a day. Contrary to the ‘power_consumption’ sensor in the previous graphs, this sensor logs its accumulative state over time. So, it’s value is ever growing and indicates the total power used since it was installed. Hence, the need to subtract the last value of the day from the first value of that same day to get the difference; power used. The second query is exactly the same, except it selects values from the normal tariff meter.
Now, setup the display tab so that the results of the two queries are stacked on top of each other in the graph. No magic here, you just need to know where to find the option to display the queries as stacked results:
On the far right in the “Display” tab, is the “stack” tick box. Voila!
Last thing you need to do to limit the display to last 7 days (or however many you like), set the “Override relative time” to “7d” in the “Time Range” tab. And to prevent making changes to that, you can check the “Hide override info”: