Energy Management in Home Assistant

Same here. After update…

+1 with the energy dashboard broken after update

did you see the notification that said the database was being upgraded and not to reboot?
Mine looks fine

No, I did not see that notification.

I rolling back to previous version (from backup), then all working again. There is problem in new HA version.

Is it possible that it now only works with
state_class total increasing
And no longer with
state_class measurement

Update:
OK. That’s it. My energy card works again

2 Likes

Yes - that’s exactly what seems to have happened.

This is the solution. Works for me after the changes now again. Thank you

Need some help here, what should I exactly change (and where) to get the energy dashboard working again?

Check in development tools the states of the entity. It should look like the picture of mine above. If not, you can customise it in customize.yaml. There howto’s in net.

It look like
customize.yaml

sensor.tasmota_sml_strom_in:
  state_class: total_increasing
  last_reset: '1970-01-01T00:00:00+00:00'
  unit_of_measurement: 'kWh'
  device_class: energy

This is my solution.
But there are other ways to do that.

1 Like

found it. It was in my configuration.Yaml

homeassistant:
customize_glob:
sensor.*_energy:
last_reset: ‘1970-01-01T00:00:00+00:00’
device_class: energy
state_class: measurement total_increasing

Seems to work now. Thx for the info.

I also used to have in my config

state_class: measurement

for the configuration of the energy consumption/injection from the main grid (MQTT input).

After the update the energy dashboard stopped showing values as mentioned in this post. However, after updating the state_class to total_increasing I got invalid entries that are way too big and also negative compared to the usual graphs in the overview as shown in the figure below.

Is there a way to remove these single invalid values from the database so that the totals reported for month/year are in line with the actual consumption?

Thanks,
Lieven.

1 Like

i change from measurement in configuration.yaml to state_class: total_increasing but still not working.also, input from solar production does not work in the energy management chart. bad

all after 2022.2 update

look like now start working

Yes, my device_class:measurement sensors also started reporting 0 in energy management until I changed them to total_increasing in my configuration.yaml file

  customize_glob:
    sensor.*_importenergy:
      last_reset: '1970-01-01T00:00:00+00:00'
      device_class: energy
      state_class: total_increasing
    sensor.*_exportgrid:
      last_reset: '1970-01-01T00:00:00+00:00'
      device_class: energy
      state_class: total_increasing ```

same thing. after 2022.2 update no longer works !!!
first


after

Follow-up: apparently this issue is present when you have a sensor with state_class: measurement in your config, you update home-assistant to the latest version 2022.2.1 and you only notice after a while that the energy dashboard is no longer updating.

This is as far as I understand caused by a different way of storing the data in the home-assistant_v2.db file under the topic statistics in this version of HA:

Sensor with state_class measurement under the previous version of Home Assistant is stored as follows:

20433|2022-02-04 09:00:10.042489|5|2022-02-04 08:00:00.000000||||1970-01-01 00:00:00.000000|5740.244|354.485

After updating to the latest version of HA this becomes:

20451|2022-02-04 10:00:10.036745|5|2022-02-04 09:00:00.000000|5741.98231123358|5741.428|5742.471|||

And then after changing the configuration of the sensor state class to be total_increasing we get:

20541|2022-02-04 15:00:10.032608|5|2022-02-04 14:00:00.000000|5767.73258326141|5765.18|5769.98||5770.368|0.388000000000829

The jump in the graph for this sensor is as expected ±354 kWh in negative.

Is there any way to fix this? I tried removing the invalid readings that were added after the update, but as expected this does not make a difference because the sensor started counting from ‘0’ again after changing the state class to ensure the graphs started updating again.

Is there something we can do with the last_reset value in the database to ensure home assistant does understand the sensor sum was reset? I am willing to experiment furhter with this, but some insights on which changes to make would help me tremendously.

Kind regards,
Lieven.

A bit of off-topic (but this software seems to provide what you/we need when editing more than just a few things where few SQL statements would be fine):

1. Can we use DBeaver with our home-assistant_v2.db (default SQLite db of HA)?
2. Anything to consider (e. g. will DBeaver lock the DB during commits which could be a problem for HA)?

Update:
Terrible idea. :exclamation::exclamation::exclamation: Don’t do it! :exclamation::exclamation::exclamation:

  • Thought about even deleting this comment but decided to keep it so others have been warned.
  • ANY SQLite database access next to HA when running is very likely to corrupt the database.
  • In this case HA will automatically create a new (empty) one.
    Offline editing should be safe of course, e. g. by shutting down HA or using a copy.

DBeaver should in general be safe to use with every non-file based database which can be used for HA (like MySQL/MariaDB).

Gosh I really hope the migration from SQLite to MySQL will work some day… less trouble, more flexibility. Migrating home assistant database from sqlite to mariadb.. ONLY if you are VERY familiar with Database administration

Yes. It seems I was too late responding…don’t mess with the SQL lite version of the DB…it’s not a smart idea. The other DBs, particularly MariaDB, this is not a problem…

As it stands I do not understand why people do not move to a MariaDB straightaway if they have to CPU/RAM/Disk to accommodate it…migrating is very easy…and, if you control your history settings in the configuration.yaml file you can mimimise the storage overhead. I have mine to record only the last 48 hours because just how far back do you ever want to go for the status of a light switch? The long term statisitics however keep running on forever…nad for me at least MariaDB has been stable and easy to use!

CP

How did you set this up? Can it be done with an automation? Call service?

Recorder:Purge