Energy Cost with `Use an entity with current price` option is always `$0.00` unless browsing by month

I noticed this issue a few days after the 2021.08 release went out but have been too busy to write it up until now… I was also hoping that this was a known issue / would be fixed in a follow release.

I have my energy dashboard configured with the Use an entity with current price option. However, the total cost per day is always $0.00. This is also true when browsing by week. Only once I go to the monthly view do I get an amount that is not $0.00:

i wish my monthly power bill was only $2.36… it’s actually 20-60x higher depending on the time of year!

Note: I had to use a screenshot from September because the month of October is still at $0.00.

Here is the custom sensor that I have configured for use with the energy dashboard:

At the time the screenshot was taken, my energy company is charging $0.1082 per kWh… so I know the template sensor is returning the correct value for the day/time as 10.82 cents per kWh is 0.1082 USD per kWh.

I do not have any solar or anything else that would ‘back feed’ into the grid… so there is no possible way that I could somehow lower my energy cost.

My next thought was that there is some bug in calculating the daily use and summing that up… but that can’t be the case as the monthly view shows a positive number. So somewhere in the code base, a non 0 cost is being calculated… but the cost is so low that - when rounded to the two decimal places for the UI - still shows 0.00

I am confident that the units on the template sensor are correct: unit_of_measurement: USD/kWh and I am confident that the sensor returns the correct value at all dates/times as shown above in the second screenshot.

My guess is that either the HA code or documentation is wrong; the code wants a sensor in USD/kWh but does it’s math as if the units are tenths of USD/kWh. That is, when my template sensor returns 0.1082 it really should be returning something like10.82` … but this would also mean that the monthly cost ($2.36) would be ~ 10x higher. My power bill for last month was not $236!

Thoughts?


It seems that I’m not the only person with this issue, but this thread is mostly people complaining about the same incorrect cost values but when using a fixed cost per kWh. Ignore the [solved] tag as it seems that was done prematurely:

You can see in my post that you shared, once everything configured correctly all calculations done right.
You should check if your sensor report correct values of kWh and compare to the meter.

Right, but that thread does not really have a conclusive "fix:

I did nothing and it started to work :\


The only real “proposed” fix is to decrease the accuracy by using at most 2 decimal places… except:

  • that is a terrible solution as most utility providers use fractions of a cent. When you specify a fixed cost per kWh, the implementation uses a floating point number… which would allow for arbitrary levels of precision beyond two decimal places. See: core/homeassistant/components/energy/data.py at 5b3711ed198f216f638aee3995eb16ebfc92c676 · home-assistant/core · GitHub

  • Rounding the unit cost metric at 2 digits drops precision and makes the cost tracker portion of the dashboard less accurate which makes it less useful. I am pretty confident that this was not a goal in design and is not a real limitation of the implementation… only an artificial limit imposed by the UI.

You should check if your sensor report correct values of kWh and compare to the meter.

I use Sense energy monitor to keep track of whole-house energy use. The sense app has it’s own UI for entering provider tariffs except the interface for entering the various levels of a rate plan is hot garbage; you can tell that the people that developed it used only very simple data to test it! Never the less, the energy use reported by Sense and my Utility company match up… But, in grabbing screenshots for this post, I noticed that the energy sensor in HA does not match what Sense (the measurement device) reports and what my utility company reports:

Utility company / the source of truth:

Sense Energy Monitor / Home Assistant consumption source:

Home Assistant Energy Dashboard:

So, you can see that Sense and My Utility company agree. Somehow, HA is “missing” about 6.5 kWh from yesterday’s usage and also has an incorrect price for yesterdays electricity use!

Looking at the graph from HA, the last 8 hours are missing! I am located on the west coast of the United States… which is currently at GMT-7 until the end of ‘daylight savings time’ in about a month… then we will be GMT-8. Missing the last 8 hours is a little bit suspicious and smells like a bug; somewhere along the line a timezone offset is being lost.

FWIW, my HA instance is configured with the correct timezone (America/Los_Angeles):


System Health

version core-2021.10.2
installation_type Unknown
dev false
hassio false
docker false
user root
virtualenv false
python_version 3.9.7
os_name Linux
os_version 5.4.0-86-generic
arch x86_64
timezone America/Los_Angeles
Home Assistant Community Store
GitHub API ok
Github API Calls Remaining 5000
Installed Version 1.15.2
Stage running
Available Repositories 893
Installed Repositories 21
Lovelace
dashboards 4
resources 14
views 11
mode storage
1 Like

I’ve been running into the same issue, and this is the top search result on Google for it.

I think I know what happened, though. I’m American, and I never set the currency flag on my Home Assistant instance since I didn’t know it existed. If you’re using a yaml file for configuration and you don’t manually specify USD, it defaults to Euros.

When you go and assign a price for your energy, it creates a new sensor that keeps track of the price… using whatever your default currency is as the type. When I set mine up, I created a bunch of sensors keeping track of the price in Euros. Even after I switched currency in the yaml, those sensors kept using Euros. There’s no error shown that it’s trying to render the wrong currency; it just gives a value of 0.

I only noticed because I went into the developer options → statistics and saw that Home Assistant was complaining that it’s mixing units in there. I fixed the sensors to use dollars instead of Euros, and I think it fixed it? The history still displays EUR when I click on it, but the prices seem to be tracked properly.

1 Like

Glad i’m not the only one!

What integration are you using for the energy consumption? If multiple people have this issue but they all use the same source integration for the consumption data then we have a better signal about where the issue might be.

If you’re using a yaml file for configuration and you don’t manually specify USD, it defaults to Euros.

Yep. I use USD and this is explicitly set in the config.yaml; when i go to the server settings page:

 Editor disabled because config stored in configuration.yaml. 

I only noticed because I went into the developer options → statistics

Ohhh, this is nice to see! Glad this debugging tool exists!

I use the Sense energy monitor and the sensor of interest is sensor.daily_usage. When i look up sensor.daily_usage on the dev options / stats page, no error is reported:

In my case, I’m using the powercalc custom component to track the consumption of my Hue lights, plus I’m using it for estimating the draw of my other devices (smart switches and such).

When you click on sensor.daily_usage_cost in the developer tools the graph displays in USD, yes? Even after I “fixed” mine it was displaying in EUR there for some reason; I had to go into the database and drop the history for that one sensor before it would display the history in USD. After that, it started appearing as normal:

(The litterbox is a smart litterbox that’s classified as a vacuum; since it’s my only vacuum in HASS it gets its own category.)

If you don’t have access to SQL commands, try renaming your database temporarily and see if that fixes it.

…If not, well, I’m out of ideas. :man_shrugging:

Funny enough, my postgres pod had some index corruption and I wasn’t able to repair the damage… so i dropped my entire history too and now the daily energy usage dashboard works!

This is what I saw a month ago. Note the $0.00

And this is what I see today (after DROP TABLE on the recorder database). Note the $1.11:

I don’t know why but it looks like the both of us have more or less the same symptoms, but through different integrations and some brain surgery on the recorder component was sufficient get things working again…