No long term statistics for sensor

On my homewizard P1 meter i have a stat called “P1 meter (3c39e7253554) Piekverbruik huidige maand” (Peak usage for the current month) that doesn’t show any long term data, yet all other entities on the meter do. I would like to be able to keep the values for at least a year. I’ve tried using a utility meter helper, but noticed that the value was not correct. Is there a way to tell home assistant to keer the data for an entity in long term statistics when it wasn’t one I defined myself?

For long term statistics to be generated the sensor must have a correct state_class attribute. Look in Developer Tools → States. The right hand column lists attributes for each entity. What do you see for “P1 meter (3c39e7253554) Piekverbruik huidige maand”?

I have the following attributes:

unit_of_measurement: W
device_class: power
friendly_name: P1 meter (3c39e7253554) Piekverbruik huidige maand

Looks like I`m missing the state_class. How can I assign this class? I tried clicking the entity in the states tab on the developer tools, and then adding “state_class: total_increasing”, and on the lower right it shows it for about a second and then it disappears again.

Yeah that option is only for testing and the changes are not permanent. It’s handy for changing states for testing automation triggers but can not be used for configuring entities.

I assume you are using this integration to add the device HomeWizard Energy - Home Assistant?

The ideal solution would be to open a new issue here: Issues · home-assistant/core · GitHub to have the correct state class added. Note: the correct state class is measurement not total_increasing as it is a peak power measurement, not an energy total.

Until the state class is added to the integration you can use manual customisation to add it, see: Home Assistant Core Integration - Home Assistant

So find the homeassistant: entry in your configuration.yaml file and add this to the existing things under it (if there are any):

homeassistant:
  # may be other stuff listed here
  customize:
    sensor.entity_id_of_your_peak_power_sensor_here: # <- change this
      state_class: measurement 

Then do a configuration check and make sure it passes before restarting.

Customize is considered a bit of a hack by the developers. You should definitely open the issue to get this fixed properly. When it is you can just delete the customisation and restart.

Hi tom_l.

Thank you for the information. I’ve submitted an issue for this as you proposed. However, I have made a PR on a fork on my own repo (sorry if I’m making no sense, I’m not very experienced in this yet.) since I noticed the code change required is only minor. I don’t have any knowledge of how to test this, and since this is a requirement for submitting the PR to the main repo, I don’t really know if I should pursue this further. I don’t want to break anything. :slight_smile:

Looks like this is by design. Homewizard: No support for Long Term Statistics on the Peak Demand entity · Issue #121420 · home-assistant/core · GitHub
I’ll keep the customization up for now and will keep my eyes peeled for a better solution in the future. Thank you for the help!

Hello Tom,

I´m new to HA and want to do the same, some of my entities does not have an state_class.
In my configuraton.yaml File, I dont have some homeassistant: option.
When I try to add it and then check the configuraton, there is an error:

Integration error: homeassitant - Integration 'homeassitant' not found.

Do you know how to solve this?

P.S: Now it works.
I have changed one time from homeassistant: to the name of one integration, in my case wican:
It didn´t work with this, but then i changed back to homeassistant: and then it suddenly worked.