core: Currency/cost change isn't reflected in Power Total Cost, stuck at zero

The problem

After changing currency in HA Settings - General to reflect my actual currency (CZK) and adjusting cost of energy to that currency, the Total Cost does not increase anymore. It is stuck at 0.00.

What is version of Home Assistant Core has the issue?

2021.9.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Energy

Link to integration documentation on our website

https://www.home-assistant.io/docs/energy/electricity-grid/

Example YAML snippet

No response

Anything in the logs that might be useful for us?

nothing relevant in logs

Additional information

I tried to remove and re-add my device (it’s a simple zigbee power plug) from energy monitoring, problem didn’t get fixed. Tried modifying the HA database as instructed by a HA developer with

UPDATE statistics_meta SET unit_of_measurement = “CZK” WHERE statistic_id = “sensor.energy_from_grid_cost”; and DELETE FROM statistics WHERE metadata_id = (SELECT id FROM statistics_meta WHERE statistic_id = “sensor.energy_from_grid_cost”);

but to no avail.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 21

Most upvoted comments

I have this same issue : image

edit: fwiw this is fixable as above using the default sqlite database, you don’t need to have mariadb installed.

Sqlite db location is in config, for me it was just a matter of : sqlite3 config/home-assistant_v2.db

from there you can run the commands from the above post so…

  1. Find what you need to update : select * from statistics_meta order by statistic_id;
...
34|sensor.house_total_energy|recorder|kWh|0|1
36|sensor.house_total_energy_2|recorder|kWh|0|1
40|sensor.house_total_energy_2_cost|recorder|EUR|0|1
59|sensor.house_total_energy_cost|recorder|EUR|0|1
123|sensor.incubation_chamber_current|recorder|A|1|0
148|sensor.incubation_chamber_current_2|recorder|A|1|0
...

For me items with id 40 and 59, obviously in the following sql swap out the id(s) for the ones you have.

  1. Set the items to the corrected currency, for me GBP : update statistics_meta set unit_of_measurement="GBP" where id = 40 or id=59;

  2. Verify the update : select * from statistics_meta order by statistic_id;

...
36|sensor.house_total_energy_2|recorder|kWh|0|1
40|sensor.house_total_energy_2_cost|recorder|GBP|0|1
59|sensor.house_total_energy_cost|recorder|GBP|0|1
123|sensor.incubation_chamber_current|recorder|A|1|0
...
  1. And finally run the deletion : delete from statistics WHERE metadata_id = 40 or metadata_id=59;

Restart HA and an hour or so later :

image

I was able to fix this using the instructions in the OP without nuking my recorder db (mysql). Using the homeassistant/home-assistant:2021.9.6 docker image.

Here are the steps. I updated from EUR to USD.

Step 1) sanity check the unit of measurement that’s in the DB already

mysql> SELECT * from statistics_meta WHERE statistic_id = "sensor.home_energy_meter_gen5_electric_consumed_kwh_cost";
+----+----------------------------------------------------------+----------+---------------------+----------+---------+
| id | statistic_id                                             | source   | unit_of_measurement | has_mean | has_sum |
+----+----------------------------------------------------------+----------+---------------------+----------+---------+
| 31 | sensor.home_energy_meter_gen5_electric_consumed_kwh_cost | recorder | EUR                 |        0 |       1 |
+----+----------------------------------------------------------+----------+---------------------+----------+---------+
1 row in set (0.01 sec)

Step 2) update to your desired unit

mysql> UPDATE statistics_meta SET unit_of_measurement = "USD" WHERE statistic_id = "sensor.home_energy_meter_gen5_electric_consumed_kwh_cost";
Query OK, 1 row affected (0.12 sec)
Rows matched: 1  Changed: 1  Warnings: 0

and verify that the unit_of_measurement is what you want it to be:

mysql> SELECT * from statistics_meta WHERE statistic_id = "sensor.home_energy_meter_gen5_electric_consumed_kwh_cost";
+----+----------------------------------------------------------+----------+---------------------+----------+---------+
| id | statistic_id                                             | source   | unit_of_measurement | has_mean | has_sum |
+----+----------------------------------------------------------+----------+---------------------+----------+---------+
| 31 | sensor.home_energy_meter_gen5_electric_consumed_kwh_cost | recorder | USD                 |        0 |       1 |
+----+----------------------------------------------------------+----------+---------------------+----------+---------+
1 row in set (0.01 sec)

Step 3) remove old stats

mysql> DELETE FROM statistics WHERE metadata_id = (SELECT id FROM statistics_meta WHERE statistic_id = "sensor.home_energy_meter_gen5_electric_consumed_kwh_cost");
Query OK, 141 rows affected (0.15 sec)

Step 4) restart homeassistant. This may not be necessary.

Step 5) wait a couple hours. You’ll still have your old long-term energy consumption data, but new data should start populating price

Same here… i’m using a static price with peak and offpeak… it was calculating price fine on September 1st… then from the 2nd i’m not getting any price calculation…

My recorder options havn’t changed…

system_health: recorder: purge_keep_days: 30 exclude: event_types: - themes_updated

image