Energy dashboard stopped working after upgrade to core-2022.2.0

As @ClassicGOD suggested try to follow the instructions on Sensor Entity | Home Assistant Developer Docs which indicate the correct use of state_class and last_reset, but as I mentioned earlier in doing this you will only get the bars showing in the Energy dashboard while the values will remain wrong (almost everything zero). At least that is what happended to me

Stats are updated every hour (12mins past every hour AFAIK), it can take up to 2 hours for them to show up. Have you waited at least this long?
I applied the changes yesterday and today my readouts on energy panel match my sensors exactly. (they also matched yesterday but due to late time I applied the change I was unable to verify the correct readouts for PV production)

what did you set for state_class? I used just “total” with no last reset attribute and yes I modified the settings yesterday and the figures were still wrong today

I have it set to total_increasing but i think I should probably be using total for some of my sensors.
Since Energy dashboard is not mission critical for me I will switch to total and test if it reports correctly.

I changed the state_class to total_increasing more than 12 hours ago and I cannot change last_reset as it is not supported by the MQTT sensor. After a few restarts the dashboard is still empty for values since the date and time of the upgrade. I’m pretty sure that 2022.2 introduced a bug on the energy dashboard. By the way, even if the cost are not in the charts, they are still calculated correctly on a daily basis.

The bug is definitely a possibility. There is an open GitHub issue about this here: https://github.com/home-assistant/core/issues/65773#issuecomment-1030917033 there are people suggesting other solutions in there so I recommend taking a look.

When it comes to setting last_reset - I had it in my config but I removed it now as it probably is no longer required (like setting state_class: measurement it was a fix for early long time statistics implementation) but if you want to set it for sensor that does not directly support it in the configuration you can set it via customize.yaml like this:

sensor.your_sensor:
  last_reset: ‘1970-01-01T00:00:00+00:00’

you have to have customize.yaml enabled in ‘configuration.yaml’:

homeassistant:
  customize: !include customize.yaml

of course you can set it directly under customize: in the main config but splitting configuration is good for you :slight_smile:

Hello @ClassicGOD, I realized that I had some custom entries already. I have removed the device_class and state_class (as they are now in the main config) and I left the last_seen that was already there. I’ve restarted and the dashboard is still empty: I will wait for the canonical 2 hours to see if the problem was fixed. Thanks

How can I convert the following “integration” sensor to a total_increasing?

- platform: integration
    source: sensor.power_grid_consumption
    name: energy_grid_consumption
    method: left
    unit_time: h
    unit_prefix: k
    round: 2

These are the current attributes:

state_class: measurement
source: sensor.power_grid_consumption
unit_of_measurement: kWh
device_class: energy
icon: mdi:chart-histogram
friendly_name: energy_grid_consumption
last_reset: '1970-01-01T00:00:00+00:00'

Should I change the platform and use something else? The HA documentation suggests to use the Riemann sum integral, which is what I’ve done. Am I missing something?
Thanks!

1 Like

So 1 hour after changing the state_class to total_increasing in the main config, and keeping only the last_reset in the custom attributes, I have back my dashboard, but the first days of the month have been messed up with huge negative kwh consumption the day of the upgrade, the consumption of today is ok and I think that the problem is fixed. I’m not sure if the situation of the upgrade day can be restored to normal, but it is not that bad (and costs are still ok). Thanks @ClassicGOD

You can use customize.yaml to set it to total_increasing in the same way I outlined in one of my posts above.

@adizanni Happy I could help :slight_smile:

@backtrack I changed my sensors to total as promised. They still seem to operate and show in Energy panel as expected.

1 Like

Hi guys,

unfortunately the consumption display did not work for me anymore.
I currently use the following code:

  •   - name: "Energy Total"
        unique_id: energy_total
        state: >-
          {{ states('sensor.phase_1_energy')|float(0) + 
             states('sensor.phase_2_energy')|float(0) + 
             states('sensor.phase_3_energy')|float(0) }}`
        `unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        attributes:
          last_reset: "1970-01-01T00:00:00+00:00"
        availability: >
            {{ not 'unavailable' in 
               [ states('sensor.phase_1_energy'), 
                 states('sensor.phase_2_energy'),
                 states('sensor.phase_3_energy') ] }}`
      - name: "Power Total"
        unique_id: power_total
        state: >-
          {{ (states('sensor.phase_1_power')|float(0) + 
              states('sensor.phase_2_power')|float(0) + 
              states('sensor.phase_3_power')|float(0)) }}
        unit_of_measurement: W
        device_class: power
        state_class: total_increasing
        availability: >
            {{ not 'unavailable' in 
               [ states('sensor.phase_1_power'), 
                 states('sensor.phase_2_power'),
                 states('sensor.phase_3_power') ] }}
    
    

I had changed this accordingly the state_class as total_increasing, which now (almost) works again as before. The solar module is connected to L2 in the apartment. In case of excess power the Shelly 3M measures negative and I get the following log:

Logger: homeassistant.components.sensor.recorder
Source: components/sensor/recorder.py:331
Integration: Sensor (documentation, issues)
First occurred: 13:20:10 (1 occurrences)
Last logged: 13:20:10

Entity sensor.power_total from integration template has state class total_increasing, but its state is negative. Triggered by state -15.8 with last_updated set to 2022-02-07T12:19:09.517860+00:00. Please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A"integration%3A+template"

and

Logger: homeassistant.components.sensor.recorder
Source: components/sensor/recorder.py:311
Integration: Sensor (documentation, issues)
First occurred: 13:05:10 (1 occurrences)
Last logged: 13:05:10

Entity sensor.power_total from integration template has state class total_increasing, but its state is not strictly increasing. Triggered by state 131.0 (134.5) with last_updated set to 2022-02-07T12:00:17.129803+00:00. Please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A"integration%3A+template"

Possibly someone knows a solution?

Thanks in advance.

Power is a momentary reading so definitely shouldn’t be set to total_increasing. That is why you are getting those errors. Sensors representing momentary readings should be set to measurement

Also if you have 3 sensors representing energy you don’t have to create a sensor that adds them for the Energy integration. You can just add all 3 sensors to the integration and it will not only take care of adding them for you it will also give you more detailed bar graphs.

Thanks so far for your answer.
I set it back to measurement: Now I am waiting for enough sun to get into “negative measurement” :slight_smile: Germany isn´t the sunniest place actually.

I know, that I can use all three sensors for the energy integration, but the Solar Panel is connected to L2. Therefore that code above summarizes all 3 main cables in the appartement together - including the solar production. (I hope, I explained this correctly.)

I have the same setup (funny enough my inverter is also connected to phase 2) the graphs look like this when you go into negative:

Did you use the L2 return function from the Shelly 3M or do you use another one?
Honestly I just use a 390W Panel with a Hoymiles 350 Inverter on the Balkony. In my case it looks as follows (The current solar power is around 40Watts :smiley: )

I use Aeotec Home Energy Meter Gen5 (zwave device). It does not have dedicated “return” function if that is what you are asking.

My inverter is connected behind the meter so when the PV production is high my entire usage on 2nd phase goes into negative. That is why I don’t have anything configured as return to grid.

If I configure my Inverter as return to grid my calculation in the energy panel is incorrect. (the PV production is counted twice, once as return to grid and once again because it lowers my real usage).
Technically my setup is not optimal and I should change it but I have to run new cable for the inverter from my fuse box so it is connected between meter and the incoming city supply.

1 Like

I had the same problem. After changing my “Solar generation” to total_increasing it worked again, but showed huge negative numbers for today.
For now I restored the Backup I made this morning and continue to live with 2021.12 until theres a good solution.

I don’t think there will be a better solution. Using state_class: measurement was deprecated for a long time and will never be supported for accumulation sensors again.

That negative value is just for that day, when you upgraded that.
I wouldn´t worry about that. :wink:

In my case, the Shelly 3M device has a return function for every clamp. That means if a value gets negative, then this is going to be measured as return.
Anyway… The energy from the panel gets measure with a Shelly Plug S.
Until now…your solution works. Thanks so far for your help.