Following from my energy tariff automatically updating (I use the Hildebrand Glow MQTT integration to get energy usage and tariff data from my SMETS2 meter) my historical energy costs in the Energy dashboard are screwed up. Cost data following the tariff update are correct however historical cost data shows as £0 as per the screen shot. Any ideas what is causing this and how to fix?
Your cost entity needs to be stored in the database, it cannot be excluded. Every energy value in the database needs an associated cost at the time the energy value was taken. If that doesn’t exist, the result will be zero.
So, start tracking your cost in the database. After some time, you’ll get values that make sense. You cannot retroactively add cost to the database, so you won’t have summed cost values prior to adding the cost entity to the database.
The cost has been tracking correctly for the last year it is only since today when the energy tariff data updated automatically from my smart meter that the historical data is now showing zeros. I also save the track the data within Grafana so it has been tracking correctly previously
Well, verify the cost entity you are using is the one being tracked in the database. If you changed to a new cost… then you have to wait for the new cost to populate values in the database. The system won’t split it between 2 entities.
Sorry I’m confused the new costs are showing correctly for todays usage its historical views which appear broken so I would assume that given I can see both the new and old values for the unit rate that historical energy dashboard would pull back the previous rate data and generate the appropriate costs?
Can you post the attributes of that sensor? Developer tools → states page.
That entity is missing a state_class, so it will not be tracked in long term statistics. So it won’t be used for monetary calculations.
I’m not sure how that entity ever worked for you if it didn’t have that attribute.
EDIT: You can customize that entity in yaml and add
state_class: measurement to get it to add to the long term statistics database for use. But keep in mind, it won’t be retroactive, meaning it’ll only calculate from this point forward.
Thanks for the insight that is being set via the Hildebrand glow integration just for further clarity why is it not simply using the current updated tariff for cost calculations?
because, the calculation is a summation of the energy * the cost. If you have variable cost, you need to know the cost when the energy was taken.
The math is
total_cost = (energy_reading * energy_cost) + (energy_reading * energy_cost) + (energy_reading * energy_cost)...
total_cost = (energy_reading + energy_reading + energy_reading ... ) * energy_cost
This allows for situations where your cost changes throughout the day.
Because of that, you need to have the value tracked in the long term statistics database. Which is why state_class is required.
Many thanks for your help. I’ve updated the Hildebrand component to add the correct state class so moving forward hopefully I’m covered. Will just have to rely on my historical Grafana data