Long Term Statistics not showing for utility_meter

Hi,

I have a “utility_meter” setup from my configuration.yaml.
I want to be able to look back a few months at historical values.
The utility_meter has a monthly cycle… so although it’s constatly increasing, it’s mainly the value just before it cycles I’m looking for.

The sensor look like this in my configuration.yaml:

utility_meter:
  house_solar_saving_montly:
    source: sensor.house_solar_saving_last_hour
    cycle: monthly
    delta_values: true
    offset: '00:00:20'
    unique_id: "house_solar_saving_monthly"
    name: House Solar Saving Monthly
    #unit_of_measurement: SEK

And the sensor looks like this:

From a bit of reading I now undestand that it’s normal that I can’t see historical values long ago in the history viewer:

Trying to look at last month, I have nothing in my history.

But, I also read that there is something called LTS (Long Term Statistics) and that I should be able to see this data for my sensor as it has a native “state_class: total_increasing”.
The data should become visible when adding it to a statistics card.
But when I do so… I still only see the sensor data that gets purged.

Please help, what am I doing wrong here?

  1. You’d have to wait for it to populate that data. The system does not create things in the past. When you add an entity to the system, your LTS and Regular history start the moment you add the entity.

  2. You’ll need a unit of measurement for it to be numerical.

  3. You may need device_class: monetary for it to work.

Sorry I forgot to mention that I created the sensor roughly a year ago, so there should be plenty of LTS data.

Ok, I’ll look to implement your other two advice.
Any risk I mess up any potential LTS data I have by making changes like this to the sensor?

Thank you for taking your time to look at this! :heart:

For your statement 2, do I solve this by removing the # in front of my “unit of measure” in the configuration.yaml file?
Seems I was playing around with this at the time I created this sensor, but I’ve not sure why I left it out by adding the #

That would be a start

So… I’ve now looked into all the bullets above.

1) I created the sensor ~a year ago, so this should not be the issue

2) I tried adding a unit if measurement to my utility_meter as we (although it already has a unit_of_measurement based on the source sensor it’s tracking (sensor.house_solar_saving_last_hour):

utility_meter:
  house_solar_saving_montly:
    source: sensor.house_solar_saving_last_hour
    cycle: monthly
    delta_values: true
    offset: '00:00:20'
    unique_id: "house_solar_saving_monthly"
    name: House Solar Saving Monthly
    unit_of_measurement: "SEK"

HA doesn’t like this added “unit_of_measurement”:

Perhaps it’s because it would be a double statement from the sensor values fed to it?

3) I tried adding “device_class”…

utility_meter:
  house_solar_saving_montly:
    source: sensor.house_solar_saving_last_hour
    cycle: monthly
    delta_values: true
    offset: '00:00:20'
    unique_id: "house_solar_saving_monthly"
    name: House Solar Saving Monthly
    device_class: monetary

But HA doesn’t seem to like this either:

I have exactly the same problem. My utility meter sensors are not show in the long term statistic. Adding unit_of_measurement or device_class are leading to errors in the config as shown above.

I also cannot add an utility meter sensor to a “Statistics graph Card”.

Does anyone have a solution how to bring utility meter sensors to the long term statistic? @Piffis maybe?

They need to be added via

homeassistant:
  customize:
    <entity_id>:
      device_class: ...
      state_class: ...
      unit_of_measurement: ...
1 Like

To add to this. A good place to start is in Developer Tools and States. This will show you how the sensor/entity is defined in HA. If it does not have state_class it will not save to LTS.

2 Likes

Sorry for answering so late. Unfortunately customize seems not to work as solution for me. I have added state class and unit of my Utility Meter sensor like this:

homeassistant:
  customize:
    sensor.<anonymized>wr_bezug_daily:
      unit_of_measurement: "kWh"
      state_class: "measurement"

It is even correctly showing up in the states of the developer tools:

Nevertheless no values older than 10 days are shown (but the sensor can be found in developer tools / statistic).

EDIT:
I just realize in this that it is device_class energy. So I will change state_class to “total_increasing”. Maybe that helps.

Setting state_class to “total_increasing” is also not working too.

As I had the problem of missing long term statistics also for other sensors which are originally missing state_class I opened a more general thread. Now I learned that customize cannot be used to enable long term statistics (at least for non-legacy sensors):

So there seems to be no way to enable the long term statistic for my Utility Meter sensor. :neutral_face:

If nobody else has any other idea, I will de-install Utility Meter and use my own logic with template triggered sensors again. Not as elegant but working but I can use LTS if I want to.

I finally figured out the problem:

The root cause have been, that the source sensor has set unit_of_measurement to “kWh” but state_class to “measurement” which does not really fit together. The Utility Meter uses state_class “total_increasing” for kWh. After changing the source sensor to “total_increasing” (and waiting 10 days) everything works fine now. The long term statistic works as expected. :slight_smile: