I'm adding old data using async_add_external_statistics to Energy, I can't figure out how to show cost

Hi, I’ve made this simple integration GitHub - sathia-musso/enelgrid: This custom integration for Home Assistant retrieves and imports energy consumption data from Enel Italia if you look at sensor.py at one point I use async_add_external_statistics

The data is stored correctly and graphs show just fine, I wanted to also show the consumption cost, but I’ve realized that these statistics don’t have the correct metadata and also, are not really data for sensors.

they don’t look like sensor.daily_consumption but rather sensor:daily_consumption

I’ve been looking but I can’t find a way to make costs show correctly.

I’m having a hard time understanding your question.

Cost is just a separate statistic. You store consuption for each hour in one statistic, and you can store cost for each hour in a different statistic.

that these statistics don’t have the correct metadata

What don’t have the correct metadata?

they don’t look like sensor.daily_consumption but rather sensor:daily_consumption

What are “they”? The colon in the entity id identfies that it is an external statistic, so not something present in the state machine and actively updated, but something for which data is inserted in the past.

If you can explain a bit more I can maybe help.

I forgot to mention this:

when in Energy settings if I try to add a static value to my entity the radio box is not clickable, hence no cost tracking, so I thought that maybe the entity is not setup properly.

If you’re using an external statistic, the option to use a fixed price is not available.

If you use an external statistic for consumption, you must also create an external statistic for cost as well, and select it as “Use an entity tracking the total costs”.

1 Like

ah, that makes sense, I will try to set it up in the python integration. Thank you!

Thank you, it works perfectly now.